|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstudent.adventure.Game
public abstract class Game
This class is the main class for a simple text adventure
game application.
Users
can walk around some scenery. That's all. It should really be extended
to make it more interesting!
To play this game, create your own subclass of Game, and define
your own createCommands()
, createRooms()
,
and welcomeMessage()
methods. Then create an instance
of your subclass and call the play()
method.
This main class creates and initializes all the others: it creates all
rooms, creates the parser and starts the game.
Constructor Summary | |
---|---|
Game()
Create the game and initialize its internal map. |
|
Game(Player player,
Parser parser)
Create the game and initialize its internal map. |
Method Summary | |
---|---|
abstract void |
createCommands()
Create all the commands this game knows about. |
abstract void |
createRooms()
Create all the rooms and link their exits together. |
Parser |
parser()
Access this game's parser. |
void |
play()
Main play routine. |
Player |
player()
Access this game's player. |
void |
printWelcome()
Print out the opening message for the player. |
abstract java.lang.String |
welcomeMessage()
Returns the welcome message printed when the game starts. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Game()
Player
to represent the player,
and a Parser
to parse player commands.
The internal map is determined by the createRooms()
method, and the list of supported commands is determined
by the createCommands()
method.
public Game(Player player, Parser parser)
Player
object is used to represent the
player, and the provided Parser
object is used to
parse player commands. This allows custom subclasses of
Player or Parser to be used if desired.
The internal map is determined by the createRooms()
method, and the list of supported commands is determined
by the createCommands()
method.
player
- The player object to useparser
- The parser to useMethod Detail |
---|
public final Player player()
public final Parser parser()
public abstract void createCommands()
parser().commandWords.addCommand( "go", new GoCommand() );
public abstract void createRooms()
public void play()
public void printWelcome()
public abstract java.lang.String welcomeMessage()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |