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

Class Adventure

object --+
         |
        Adventure

The class Adventure represents text adventure games. An adventure consists of a player and a number of areas that make up the game world. It provides methods for playing the game one turn at a time and for checking the state of the game.


Note: This version of the class has a lot of "hard-coded" data which represents a very specific adventure game involving a small trip through a twisted forest and some other game-specific features such as a time limit and a specific goal location for the player. All newly created instances of class Adventure are identical to each other. To create other kinds of adventure games, you will need to modify or replace the source code of this class.

Instance Methods [hide private]
 
__init__(self)
Sets up a new "Forest adventure" game.
string
get_name(self)
Returns the name (or title) of the adventure game.
player object
get_player(self)
Returns an object representing the player character that the user controls.
int
get_turn_count(self)
Returns the number of turns the adventure has lasted so far.
string
play_turn(self, command)
Plays one turn of the adventure game.
boolean
is_complete(self)
Determines if the adventure is complete, i.e., if the player has won.
boolean
is_over(self)
Determines if the adventure is over.
string
get_welcome(self)
Returns the text to be displayed to the user at the beginning of the game.
string
get_goodbye(self)
Returns the text to be displayed to the user at the end of 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)
(Constructor)

 

Sets up a new "Forest adventure" game.

Overrides: object.__init__

get_name(self)

 

Returns the name (or title) of the adventure game.

Returns: string
the name of the game

get_player(self)

 

Returns an object representing the player character that the user controls.

Returns: player object
player

get_turn_count(self)

 

Returns the number of turns the adventure has lasted so far.

Returns: int
turn count

play_turn(self, command)

 

Plays one turn of the adventure game. This involves the player character executing the given command - indeed, that is the only thing that happens during a turn of the basic forest adventure game. Some more elaborate adventure games could have other creatures move or act after the player, or could feature other world events independent of the player's actions.

Playing a turn advances the turn count of the adventure by one (though giving a command that the game does not understand does not count as a turn).

Parameters:
  • command (string) - the command given by the user to make the player character act
Returns: string
a "turn report" of what occurred this turn

is_complete(self)

 

Determines if the adventure is complete, i.e., if the player has won.

Returns: boolean
True/False indicating if the adventure is complete

is_over(self)

 

Determines if the adventure is over.

Returns: boolean
True/False indicating if the game has come to an end

get_welcome(self)

 

Returns the text to be displayed to the user at the beginning of the game.

Returns: string
welcome text

get_goodbye(self)

 

Returns the text to be displayed to the user at the end of the game. The text will vary depending on whether or not the player has completed the quest.

Returns: string
goodbye text

See Also: #is_over()