Class Command

java.lang.Object
  extended by 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:
2011.07.31
Author:
Michael Kolling and David J. Barnes

Field Summary
private  java.lang.String secondWord
           
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

secondWord

private java.lang.String secondWord
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.


hasSecondWord

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


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.


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.

Returns:
True, if game should exit; false otherwise.