Module gamecontext :: Class GameContext
[hide private]
[frames] | no frames]

Class GameContext

source code


A GameContext corresponds to a geographic location and is a collection of GameObjects, GameActors and state attributes. They exist in higherarchical relationships (e.g. kingdom, village, buiding, room).

Instance Methods [hide private]
 
__init__(self, name='context', descr=None, parent=None)
create a new GameObject
source code
 
get(self, attribute)
return the value of an attribute
source code
 
possible_actions(self, actor, context)
return a list of possible actions in this context
source code
 
accept_action(self, action, actor, context)
receive and process the effects of an action
source code
 
get_party(self)
Returns: list of player GameActors in this context
source code
 
add_member(self, member)
Add an player character to this context
source code
 
remove_member(self, member)
Remove a player character from this context
source code
 
get_npcs(self)
return a list of the NPCs GameActors in this context
source code
 
add_npc(self, npc)
Add an NPC to this context
source code
 
remove_npc(self, npc)
Remove a non-player character from this context
source code

Inherited from gameobject.GameObject: __str__, add_object, get_object, get_objects, load

Inherited from base.Base: set

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

Instance Variables [hide private]

Inherited from gameobject.GameObject: objects

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name='context', descr=None, parent=None)
(Constructor)

source code 

create a new GameObject

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

get(self, attribute)

source code 

return the value of an attribute

Differs from base class because calls flow up the chain of parents if this instance does not have the requested attribute.

Parameters:
  • attribute - name of attribute to be fetched
Returns:
(string) value (or None)
Overrides: base.Base.get

possible_actions(self, actor, context)

source code 

return a list of possible actions in this context

This base class merely passes that list up to our parent.

Parameters:
  • actor - GameActor initiating the action
  • context - GameContext for this action (should be "self")
Returns:
list of possible GameActions
Overrides: gameobject.GameObject.possible_actions

accept_action(self, action, actor, context)

source code 

receive and process the effects of an action

The only verb supported by this base class is SEARCH, which it passes on to any hidden (RESISTANCE.SEARCH > 0) object in this context.

Parameters:
  • action - GameAction being performed
  • actor - GameActor initiating the action
  • context - GameContext in which the action is happening
Returns:
(boolean success, string description of the effect)
Overrides: gameobject.GameObject.accept_action

get_party(self)

source code 
Returns:
list of player GameActors in this context

add_member(self, member)

source code 

Add an player character to this context

Parameters:
  • member - (GameActor) player to be added

remove_member(self, member)

source code 

Remove a player character from this context

Parameters:
  • member - (GameActor) player to be removed

add_npc(self, npc)

source code 

Add an NPC to this context

Parameters:
  • npc - (GameActor) the NPC to be added

remove_npc(self, npc)

source code 

Remove a non-player character from this context

Parameters:
  • npc - (GameActor) NPC to be removed