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

Class Player

source code

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.
source code
 
has_quit(self)
Determines if the player has indicated a desire to quit game.
source code
 
get_location(self)
Returns the current location of the player.
source code
 
go(self, direction)
Attempts to move the player in the given direction.
source code
 
get(self, item_name)
Tries to pick up the given item.
source code
 
has(self, item_name)
Determines if the player is carrying the given item.
source code
 
drop(self, item_name)
Tries to drop the given item.
source code
 
examine(self, item_name)
Causes the player to examine the given item.
source code
 
make_inventory(self)
Causes the player to list what they are carrying.
source code
 
rest(self)
Causes the player to rest for a short while (this has no real effect in game terms).
source code
 
quit(self)
Signals that the player wants to quit the game.
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, starting_area)
(Constructor)

source code 

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

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

has_quit(self)

source code 

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

Returns:
a boolean value indicating if the player wants to quit the game

get_location(self)

source code 

Returns the current location of the player.

Returns:
player location (type: Area)

go(self, direction)

source code 

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 - a direction name (may be nonexistent direction)
Returns:
a description of the results of the action

get(self, item_name)

source code 

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

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

has(self, item_name)

source code 

Determines if the player is carrying the given item.

Parameters:
  • item_name - the name of an item in the game
Returns:
a boolean value indicating if the player is in possession of the given item

drop(self, item_name)

source code 

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

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

examine(self, item_name)

source code 

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

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

make_inventory(self)

source code 

Causes the player to list what they are carrying.

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

rest(self)

source code 

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

Returns:
a description of the action