student.adventure
Class Command

java.lang.Object
  extended by student.adventure.Command
Direct Known Subclasses:
GoCommand, HelpCommand, QuitCommand

public abstract class Command
extends java.lang.Object

This class is an abstract superclass for all command classes in the game. Each user command is implemented by a specific command subclass. Objects of class Command can store an optional argument word (a second word entered on the command line). If the command had only one word, then the second word is .

Version:
2.0 (December 2002)
Author:
Michael Kolling and David J. Barnes

Constructor Summary
Command()
          Create a command object.
 
Method Summary
abstract  boolean execute(Player player)
          Execute this command.
 java.lang.String getSecondWord()
          Return the second word of this command.
 boolean hasSecondWord()
          Check whether a second word was entered for this command.
 void setSecondWord(java.lang.String secondWord)
          Define the second word of this command (the word entered after the command word).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

public Command()
Create a command object. First and second word must be supplied, but either one (or both) can be null. The command word should be null to indicate that this was a command that is not recognised by this game.

Method Detail

getSecondWord

public java.lang.String getSecondWord()
Return the second word of this command. If no second word was entered, the result is null.

Returns:
This command's second word, if any

hasSecondWord

public boolean hasSecondWord()
Check whether a second word was entered for this command.

Returns:
true if there is a non-null second word

setSecondWord

public void setSecondWord(java.lang.String secondWord)
Define the second word of this command (the word entered after the command word). Null indicates that there was no second word.

Parameters:
secondWord - The value to use for the second word

execute

public abstract boolean execute(Player player)
Execute this command. A flag is returned indicating whether the game is over as a result of this command.

Parameters:
player - The player executing the command
Returns:
True, if game should exit; false otherwise.