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

Class Area

source code

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.
source code
 
get_name(self)
Returns the name of the area.
source code
 
get_full_description(self)
Returns a full description of the area as a player sees it.
source code
 
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).
source code
 
get_neighbor(self, direction)
Returns the area where one ends up if moving in the given direction from this area.
source code
 
add_item(self, item)
Adds an item to the area.
source code
 
contains(self, item_name)
Determines if the area contains an item of the given name.
source code
 
remove_item(self, item_name)
Removes the item of the given name from the area, assuming it was there to begin with.
source code

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)

source code 

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

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

get_name(self)

source code 

Returns the name of the area.

Returns:
area name

get_full_description(self)

source code 

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:
a description of the area

add_exit(self, direction, target_area)

source code 

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 - the direction where one has to move to get from this area to the other area
  • target_area - another area

get_neighbor(self, direction)

source code 

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

Parameters:
  • direction - a direction (may be nonexistent)
Returns:
neighboring area, or None if there is no exit in the given direction

add_item(self, item)

source code 

Adds an item to the area.

Parameters:
  • item - the item to be placed

contains(self, item_name)

source code 

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

Parameters:
  • item_name - the name of an item in the game (may be nonexistent item)
Returns:
a boolean value indicating of such an item is located here

remove_item(self, item_name)

source code 

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

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