Package adventure :: Module area :: Class Area
[hide private]
[frames] | no frames]

Class Area

object --+
         |
        Area

The class Area represents locations in a text adventure game world. A game world consists of areas. In general, an area can be pretty much anything: a room, a building, an acre of forest, or something completely different. What areas have in common is that players and items can be located in them and that they have exits leading to other, neighboring areas. An area also has a name and a description.

Instance Methods [hide private]
 
__init__(self, name, description)
Creates a new area with the given name and description.
string
get_name(self)
Returns the name of the area.
string
get_full_description(self)
Returns a full description of the area as a player sees it.
 
add_exit(self, direction, target_area)
Adds an exit from this area to another given area (or event the same area, if there is an exit leading back to where one started).
area object
get_neighbor(self, direction)
Returns the area where one ends up if moving in the given direction from this area.
 
add_item(self, item)
Adds an item to the area.
boolean
contains(self, item_name)
Determines if the area contains an item of the given name.
item object
remove_item(self, item_name)
Removes the item of the given name from the area, assuming it was there to begin with.

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, description)
(Constructor)

 

Creates a new area with the given name and description. The created area has no contents and no exits (yet).

Parameters:
  • name (string) - area name
  • description (string) - a basic (non-changing) description of the area, not including information about items
Overrides: object.__init__

get_name(self)

 

Returns the name of the area.

Returns: string
area name

get_full_description(self)

 

Returns a full description of the area as a player sees it. The description includes the static, non-changing description of the area as set by the constructor, plus a listing of the items currently located in the area and an enumeration of the available exits.

Returns: string
a description of the area

add_exit(self, direction, target_area)

 

Adds an exit from this area to another given area (or event the same area, if there is an exit leading back to where one started).

Parameters:
  • direction (string) - the direction where one has to move to get from this area to the other area (nort/east/south/west)
  • target_area (area object) - another area

get_neighbor(self, direction)

 

Returns the area where one ends up if moving in the given direction from this area.

Parameters:
  • direction (string) - a direction (north/east/south/west - may be nonexistent)
Returns: area object
neighboring area, or None if there is no exit in the given direction

add_item(self, item)

 

Adds an item to the area.

Parameters:
  • item (item object) - the item to be placed

contains(self, item_name)

 

Determines if the area contains an item of the given name.

Parameters:
  • item_name (string) - the name of an item in the game (may be nonexistent item)
Returns: boolean
True/False indicating if such an item is located here

remove_item(self, item_name)

 

Removes the item of the given name from the area, assuming it was there to begin with.

Parameters:
  • item_name (string) - the name of an item in the game (may be nonexistent item)
Returns: item object
the removed item, or None if no such item was found