student.adventure
Class Game

java.lang.Object
  extended by student.adventure.Game

public abstract class Game
extends java.lang.Object

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.

Version:
2003.11.10
Author:
Stephen Edwards (based on original by Michael Kolling and David J. Barnes)

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

Game

public Game()
Create the game and initialize its internal map. This also creates a 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.


Game

public Game(Player player,
            Parser parser)
Create the game and initialize its internal map. The provided 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.

Parameters:
player - The player object to use
parser - The parser to use
Method Detail

player

public final Player player()
Access this game's player.

Returns:
The player

parser

public final Parser parser()
Access this game's parser.

Returns:
The parser

createCommands

public abstract void createCommands()
Create all the commands this game knows about. A subclass must define this method to provide its own set of commands and associated words. A new command is typically added like this:
     parser().commandWords.addCommand( "go", new GoCommand() );
 


createRooms

public abstract void createRooms()
Create all the rooms and link their exits together. A subclass must define this method to provide its own map of rooms.


play

public void play()
Main play routine. Loops until end of play.


printWelcome

public void printWelcome()
Print out the opening message for the player.


welcomeMessage

public abstract java.lang.String welcomeMessage()
Returns the welcome message printed when the game starts. A subclass must define this method to provide the content of the welcome message.

Returns:
The welcome message