Package adventure :: Module player :: Class Player
[hide private]
[frames] | no frames]

Class Player

object --+
         |
        Player

A Player object represents a player character controlled by the real-life program user in a text adventure game. A player object knows the player's location and possessions.

Instance Methods [hide private]
 
__init__(self, starting_area)
Creates a new player who is located in the given area and has no possessions.
boolean
has_quit(self)
Determines if the player has indicated a desire to quit game.
area object
get_location(self)
Returns the current location of the player.
string
go(self, direction)
Attempts to move the player in the given direction.
string
get(self, item_name)
Tries to pick up the given item.
boolean
has(self, item_name)
Determines if the player is carrying the given item.
string
drop(self, item_name)
Tries to drop the given item.
string
examine(self, item_name)
Causes the player to examine the given item.
string
make_inventory(self)
Causes the player to list what they are carrying.
string
rest(self)
Causes the player to rest for a short while (this has no real effect in game terms).
 
quit(self)
Signals that the player wants to quit the game.

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, starting_area)
(Constructor)

 

Creates a new player who is located in the given area and has no possessions.

Parameters:
  • starting_area (area object) - the initial location of the player
Overrides: object.__init__

has_quit(self)

 

Determines if the player has indicated a desire to quit game.

Returns: boolean
True/False indicating if the player wants to quit the game

get_location(self)

 

Returns the current location of the player.

Returns: area object
player location

go(self, direction)

 

Attempts to move the player in the given direction. This is successful if there is an exit from the player's current location to the given direction.

Parameters:
  • direction (string) - a direction name (may be nonexistent direction)
Returns: string
a description of the results of the action

get(self, item_name)

 

Tries to pick up the given item. This is successful if the item is located in the player's current location.

Parameters:
  • item_name (string) - an item name (may be nonexistent item)
Returns: string
a description of the results of the action

has(self, item_name)

 

Determines if the player is carrying the given item.

Parameters:
  • item_name (string) - the name of an item in the game
Returns: boolean
True/False indicating if the player is in possession of the given item

drop(self, item_name)

 

Tries to drop the given item. This is successful if the item is currently in the player's possession.

Parameters:
  • item_name (string) - an item name (may be nonexistent item)
Returns: string
a description of the results of the action

examine(self, item_name)

 

Causes the player to examine the given item. This is successful if the item is currently in the player's possession.

Parameters:
  • item_name (string) - an item name (may be nonexistent item)
Returns: string
a description of the results of the action

make_inventory(self)

 

Causes the player to list what they are carrying.

Returns: string
a listing of the player's possessions or a statement indicating that the player is carrying nothing

rest(self)

 

Causes the player to rest for a short while (this has no real effect in game terms).

Returns: string
a description of the action