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

Class Adventure

source code

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.
source code
 
get_name(self)
Returns the name (or title) of the adventure game.
source code
 
get_player(self)
Returns an object representing the player character that the user controls.
source code
 
get_turn_count(self)
Returns the number of turns the adventure has lasted so far.
source code
 
play_turn(self, command)
Plays one turn of the adventure game.
source code
 
is_complete(self)
Determines if the adventure is complete, i.e., if the player has won.
source code
 
is_over(self)
Determines if the adventure is over.
source code
 
get_welcome(self)
Returns the text to be displayed to the user at the beginning of the game.
source code
 
get_goodbye(self)
Returns the text to be displayed to the user at the end of 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)
(Constructor)

source code 

Sets up a new "Forest adventure" game.

Overrides: object.__init__

get_name(self)

source code 

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

Returns:
the name of the game

get_player(self)

source code 

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

Returns:
player

get_turn_count(self)

source code 

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

Returns:
turn count

play_turn(self, command)

source code 

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 - the command given by the user to make the player character act
Returns:
a "turn report" of what occurred this turn

is_complete(self)

source code 

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

Returns:
a boolean value indicating if the adventure is complete

is_over(self)

source code 

Determines if the adventure is over.

Returns:
a boolean value indicating if the game has come to an end

get_welcome(self)

source code 

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

Returns:
welcome text

get_goodbye(self)

source code 

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:
goodbye text

See Also: #is_over()