public abstract class Game
extends java.lang.Object
createCommands()
, createRooms()
, and
welcomeMessage()
methods. Then create an instance of your subclass
and call the play()
method.
This main class creates and initialises all the others: it creates all rooms,
creates the parser and starts the game.Constructor and Description |
---|
Game()
Create the game and initialise its internal map.
|
Game(Player player,
Parser parser)
Create the game and initialise its internal map.
|
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.String |
printWelcome()
Print out the opening message for the player.
|
abstract java.lang.String |
welcomeMessage()
Returns the welcome message printed when the game starts.
|
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 usepublic 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 java.lang.String printWelcome()
public abstract java.lang.String welcomeMessage()