Module gameobject :: Class GameObject
[hide private]
[frames] | no frames]

Class GameObject

source code


This is the base class for all artifacts, actors, and contexts. The abilities of this base class are:

Instance Methods [hide private]
 
__init__(self, name='actor', descr=None)
create a new GameObject
source code
 
__str__(self)
return the given name of this object
source code
 
get_objects(self, hidden=False)
return a list of GameObjects contained in/owned by this GameObject
source code
 
get_object(self, name)
return a named object from my inventory
source code
 
add_object(self, item)
add another object to my objects list (if not already there)
source code
 
accept_action(self, action, actor, context)
called by GameAction.act() to receive GameAction, determine effects
source code
 
possible_actions(self, actor, context)
return list of GameActions this object enables
source code
 
load(self, filename)
read object definitions from a file
source code

Inherited from base.Base: get, set

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Instance Variables [hide private]
  objects
list of owned/contained GameObjects
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name='actor', descr=None)
(Constructor)

source code 

create a new GameObject

Parameters:
  • name - display name of this object
  • descr - for players description of this object
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

return the given name of this object

Overrides: object.__str__

get_objects(self, hidden=False)

source code 

return a list of GameObjects contained in/owned by this GameObject

if an object is hidden (has a positive RESISTANCE.SEARCH) it may not be visible unless

  • it has been successfully found (SEARCH > 0)
  • caller specifies that hidden objects should be returned
Parameters:
  • hidden - return only hidden objects
Returns:
list of discoverd GameOjects

get_object(self, name)

source code 

return a named object from my inventory

Parameters:
  • name - (string) of the desired object
Returns:
first matching object (or None)

accept_action(self, action, actor, context)

source code 

called by GameAction.act() to receive GameAction, determine effects

NOTE: this base class cannot process ATTACK actions. Those are processed by the GameActor sub-class. This base class can only process actions which (if successful), increment the property who's name matches the action verb.

Parameters:
  • action - GameAction being performed
  • actor - GameActor initiating the action
  • context - GameContext in which action is occuring

    NOTE: this base class makes no use of the actor or context parameters, but they might be useful to a subc-class that could process actions before passing them down to us.

Returns:
<(boolean) success, (string) description of the effect>

possible_actions(self, actor, context)

source code 

return list of GameActions this object enables

verbs come from our (comma-separated-verbs) ACTIONS attribute for each GameAction, ACCURACY, DAMAGE, POWER, STACKS are the sum of

  • our base ACCURACY, DAMAGE, POWER, STACKS
  • our ACCURACY.verb, DAMAGE.verb, POWER.verb, STACKS.verb,
Parameters:
  • actor - GameActor initiating the action
  • context - GameContext in which the action is taken

    NOTE: this base class makes no use of the actor and context parameters, but a sub-class might want to determine whether or not this actor could perform this action in this context.

Returns:
list of possible GameActions

load(self, filename)

source code 

read object definitions from a file

  • blank lines and lines beginning w/# are ignored
  • NAME string ... is the name of an object
  • DESCRIPTION string ... is the description of that object
  • ACTIONS string ... is the list of supported verbs
  • OBJECT ... introduces definition of an object in our inventory
  • anything else is an atribute and value (strings should be quoted)

NOTE: The object being defined can contain other objects. (e.g. guard has a sword, box contains a scroll) But contained objects cannot, themselves, contain other objects.

Parameters:
  • filename - name of file to be read

Instance Variable Details [hide private]

objects

list of owned/contained GameObjects

objects can be hidden in which case they might not be returned