Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – making the tanks move


To start out, we will define attributes and methods that allow the tank instances to move. Execute this enhanced version of the previous example:

class Cannon():

    """Model of a large cannon."""
    
    def __init__(self, damage):
        """Create a Cannon instance
            Arguments:
                damage      Integer that represents
                    the damage inflicted by the cannon
        """
        # _damage   amount of damage inflicted by cannon (integer)
        # _operational  True if operational, False if disabled
        self._damage = damage
        self._operational = True
    
    def __str__(self):
        return 'Damage value:' + str(self._damage)
    
    
class Track():
    
    """Model of a continuous track."""
    
    def __init__(self):
        # _operational  True if operational, False if disabled
        self._operational = True
    
    
class Turret():
    
    """Model of a tank turret."""
    
    def __init__...