Changeset 180


Ignore:
Timestamp:
07/02/09 01:18:58 (10 years ago)
Author:
maximinus_parpg
Message:

Cleaned up some typo's.
Tidied up some text.
Let's keep it clean folks!

Location:
trunk/PARPG/scripts
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/scripts/agents/hero.py

    r153 r180  
    123123        l.setLayerCoordinates(fife.ModelCoordinate(*doorLocation)) 
    124124        self.agent.move('approachDoor', l, self.speed) 
     125 
  • trunk/PARPG/scripts/gamestate.py

    r177 r180  
    1919 
    2020class GameState(object): 
    21     """This class hold the current state of the game.""" 
     21    """This class holds the current state of the game.""" 
    2222    def __init__(self): 
    2323        """initialize attributes""" 
  • trunk/PARPG/scripts/objects/base.py

    r178 r180  
    1717 
    1818"""Containes classes defining the base properties of all interactable in-game  
    19 objects (such as Carryable, Openable, etc. These are generally independent  
    20 classes, which can be combined in almost any way and order.  
    21  
    22 Some rules that should be followed when CREATING base property classes: 
    23 1. If you want to support some custom initialization arguments, always define  
    24 them as keyword ones. Only GameObject would use positional arguments. 
    25 2. In __init__() **ALWAYS** call the parent's __init__(**kwargs), preferably *at the 
    26 end* of your __init__() (makes is easier to follow) 
    27 3. There should always be an is_x class member set to True on __init__ (where X is  
    28 the name of the class) 
    29  
    30 EXAMPLE: 
    31 class Openable(object): 
    32     def __init__ (self, is_open = True, **kwargs): 
    33         self.is_openable = True 
    34         self.is_open = is_open 
    35         super(Openable,self).__init__ (**kwargs) 
    36          
    37 ==== 
    38  
    39 Some rules are to be followed when USING the base classes to make composed ones: 
    40 1. The first parent (left to right) should always be the base GameObject class 
    41 2. Base classes other than GameObject can be inherited in any order 
    42 3. The __init__ functoin of the composed class should always invoke the parent's 
    43 __init__() *before* it starts customizing any variables. 
    44  
    45 EXAMPLE: 
    46 class TinCan (GameObject, Container, Scriptable, Destructable, Carryable): 
    47     def __init__ (self, *args, **kwargs): 
    48         super(TinCan,self).__init__ (*args, **kwargs) 
    49         self.name = 'Tin Can' 
    50 """ 
     19   objects (such as Carryable, Openable, etc. These are generally independent  
     20   classes, which can be combined in almost any way and order.  
     21 
     22   Some rules that should be followed when CREATING base property classes: 
     23    
     24   1. If you want to support some custom initialization arguments, always define  
     25      them as keyword ones. Only GameObject would use positional arguments. 
     26   2. In __init__() **ALWAYS** call the parent's __init__(**kwargs), preferably  
     27      *at the end* of your __init__() (makes it easier to follow) 
     28   3. There should always be an is_x class member set to True on __init__  
     29      (where X is the name of the class) 
     30 
     31   EXAMPLE: 
     32 
     33   class Openable(object): 
     34       def __init__ (self, is_open = True, **kwargs): 
     35           self.is_openable = True 
     36           self.is_open = is_open 
     37           super(Openable,self).__init__ (**kwargs) 
     38         
     39 
     40   Some rules are to be followed when USING the base classes to make composed ones: 
     41 
     42   1. The first parent should always be the base GameObject class 
     43   2. Base classes other than GameObject can be inherited in any order 
     44   3. The __init__ functoin of the composed class should always invoke the 
     45      parent's __init__() *before* it starts customizing any variables. 
     46 
     47   EXAMPLE: 
     48 
     49   class TinCan (GameObject, Container, Scriptable, Destructable, Carryable): 
     50       def __init__ (self, *args, **kwargs): 
     51           super(TinCan,self).__init__ (*args, **kwargs) 
     52           self.name = 'Tin Can'""" 
    5153 
    5254class GameObject (object): 
    53     """A base class that should be inherited by all interactable game objects. 
    54     This must be the first class (left to right) inherited by any game object. 
    55     """ 
     55    """A base class to be inherited by all game objects. This must be the 
     56       first class (left to right) inherited by any game object.""" 
    5657    def __init__ (self, ID, gfx = {}, xpos = 0.0, ypos = 0.0, map_id = None,  
    5758                  blocking=True, name="Generic object", text="Item description", 
    5859                  **kwargs): 
    5960        """Set the basic values that are shared by all game objects. 
    60         @type ID: String 
    61         @param ID: Unique object identifier. Must be present. 
    62         @type gfx: Dictionary 
    63         @param gfx: Dictionary with graphics for the different contexts        
    64         @type coords 2-item tuple 
    65         @param coords: Initial coordinates of the object. 
    66         @type map_id: ??? 
    67         @param map_id: Identifier of the map where the object is located 
    68         @type blocking: Boolean 
    69         @param blocking: Whether the object blocks character movement 
    70         @type name: String 
    71         @param name: The display name of this object (e.g. 'Dirty crate') 
    72         @type text: String 
    73         @param text: A longer description of the item 
    74         """ 
     61           @type ID: String 
     62           @param ID: Unique object identifier. Must be present. 
     63           @type gfx: Dictionary 
     64           @param gfx: Dictionary with graphics for the different contexts        
     65           @type coords 2-item tuple 
     66           @param coords: Initial coordinates of the object. 
     67           @type map_id: ??? 
     68           @param map_id: Identifier of the map where the object is located 
     69           @type blocking: Boolean 
     70           @param blocking: Whether the object blocks character movement 
     71           @type name: String 
     72           @param name: The display name of this object (e.g. 'Dirty crate') 
     73           @type text: String 
     74           @param text: A longer description of the item""" 
    7575        self.ID = ID 
    7676        self.gfx = gfx 
     
    8383        super(GameObject,self).__init__ (**kwargs) 
    8484         
    85     def trueAttr (self, attr): 
     85    def trueAttr(self, attr): 
    8686        """Shortcut function to check if the current object has a member named 
    87         is_%attr and if that attribute evaluates to True""" 
     87           is_%attr and if that attribute evaluates to True""" 
    8888        return hasattr(self,'is_%s' % attr) and getattr(self, 'is_%s' % attr) 
    8989 
     
    9292        return (self.X, self.Y) 
    9393     
    94     def _setCoords (self, coords): 
     94    def _setCoords(self, coords): 
    9595        """Set-er property function""" 
    9696        self.X, self.Y = float(coords[0]), float (coords[1]) 
     
    9999        doc = "Property allowing you to get and set the obejct's coordinates via tuples") 
    100100     
    101     def __repr__ (self): 
     101    def __repr__(self): 
    102102        """A debugging string representation of the object""" 
    103103        return "<%s:%s>" % (self.name, self.ID) 
     
    106106    """Adds open() and .close() capabilities to game objects 
    107107    The current state is tracked by the .is_open variable""" 
    108     def __init__ (self, is_open = True, **kwargs): 
     108    def __init__(self, is_open = True, **kwargs): 
    109109        """Init operation for openable objects 
    110110        @type is_open: Boolean 
    111         @param is_open: Keyword boolen argument to set the initial open state. 
    112         """ 
     111        @param is_open: Keyword boolean argument sets the initial state.""" 
    113112        self.is_openable = True 
    114113        self.is_open = is_open 
     
    149148    def open (self, *args, **kwargs): 
    150149        """Adds a check to see if the object is unlocked before running the 
    151         .open() function of the parent class""" 
     150           .open() function of the parent class""" 
    152151        if self.locked: 
    153152            raise ValueError ("Open failed: object locked") 
     
    171170    def placeItem (self, item): 
    172171        """Adds the provided carriable item to the inventory.  
    173         Runs an 'onStoreItem' script, if present"""     
     172           Runs an 'onStoreItem' script, if present"""     
    174173        if not item.trueAttr ('carryable'): 
    175174            raise ValueError ('% is not carriable!' % item) 
     
    182181    def takeItem (self, item): 
    183182        """Takes the listed item out of the inventory.  
    184         Runs an 'ontakeItem' script"""         
     183           Runs an 'ontakeItem' script"""         
    185184        if not item in self.items: 
    186185            raise ValueError ('I do not contain this item: %s' % item) 
     
    208207    def __init__ (self, scripts = {}, **kwargs): 
    209208        """Init operation for scriptable objects 
    210         @type scripts: Dictionary 
    211         @param scripts: Dictionary where the event strings are keys. The values  
    212         are 3-item tuples (function, positional_args, keyword_args) 
    213         """  
     209           @type scripts: Dictionary 
     210           @param scripts: Dictionary where the event strings are keys. The  
     211           values are 3-item tuples (function, positional_args, keyword_args)""" 
    214212        self.is_scriptable = True 
    215213        self.scripts = scripts  
     
    239237     
    240238class Usable (object): 
    241     """Allows the object to be used in some way (e.g. a Zippo lighter to make a  
    242     fire) 
    243     """ 
     239    """Allows the object to be used in some way (e.g. a Zippo lighter  
     240       to make a fire)""" 
    244241    def __init__ (self, **kwargs): 
    245242        self.is_usable = True 
     
    266263if __name__=="__main__": 
    267264    """This will be turned into a test suite""" 
    268      
    269     class Wildcard (GameObject, Lockable, Container, Living, Scriptable, CharStats, Wearable, 
    270                     Usable, Weapon, Destructable, Trappable, Carryable, ): 
     265    class Wildcard (GameObject, Lockable, Container, Living, Scriptable,  
     266                    CharStats, Wearable, Usable, Weapon, Destructable, 
     267                    Trappable, Carryable, ): 
    271268        def __init__ (self, ID, *args, **kwargs): 
    272269            super(Wildcard,self).__init__ (ID, *args, **kwargs) 
     
    286283    print wc 
    287284    print wc.is_carryable 
    288              
     285 
  • trunk/PARPG/scripts/objects/composed.py

    r166 r180  
    2020from base import * 
    2121 
    22 class ImmovableContainer (GameObject, Container, Lockable, Scriptable, Trappable, Destructable): 
     22class ImmovableContainer(GameObject, Container, Lockable, Scriptable,  
     23                         Trappable, Destructable): 
    2324    """Composite class that can be used for crates, chests, etc.""" 
    2425    def __init__ (self, *args, **kwargs): 
    2526        super(ImmovableContainer,self).__init__ (*args, **kwargs) 
    2627        self.blocking = True 
     28 
  • trunk/PARPG/scripts/objects/containers.py

    r178 r180  
    2525class WoodenCrate (composed.ImmovableContainer): 
    2626    def __init__ (self, ID, name = 'Wooden Crate', \ 
    27             text = 'A battered down crate', gfx = {'map': 'crate'}, **kwargs): 
     27            text = 'A battered crate', gfx = {'map': 'crate'}, **kwargs): 
    2828        super(WoodenCrate,self).__init__ (ID, name = name, gfx = gfx, \ 
    2929                text = text, **kwargs) 
Note: See TracChangeset for help on using the changeset viewer.