es.ucm.fdi.hysteria.console.command
Class Command

java.lang.Object
  extended by es.ucm.fdi.hysteria.console.command.Command
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
CloseCommand, ConnectCommand, DisconnectCommand, DropCommand, ExamineCommand, GoCommand, HelpCommand, ListCommand, LoadCommand, LookCommand, OpenCommand, PresentCommand, QuitCommand, RedoCommand, SaveCommand, TakeCommand, TalkCommand, UndoCommand, UseCommand

public abstract class Command
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Command defines the interface that every command in the game has. Every command knows how to parse a string in order to create a correct command, so it is also responsible to print its own help. This abstract class follows the Command pattern. It includes methods for executing a command and undoing it. Additionally, this class implements the Prototype pattern. The commands are employed by the Parser class as prototypes of the commands that the user can employ during the game. The clone method needed to implement the prototype is implemented using the Cloneable interface.

Author:
MiniSandor
See Also:
Serialized Form

Field Summary
protected  GameConfig _config
           
protected  boolean _executed
          Was the command executed?
protected  Game _game
          A reference to a game object.
protected  boolean _parsed
          Was the command parsed?
protected  java.lang.String _result
          What was the result?
protected  boolean _successful
          Was the command successful?
 
Constructor Summary
Command(Game theGame)
          A constructor that initializes the reference to the game.
Command(Game theGame, java.util.Properties config)
           
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this command.
 boolean execute()
          Executes the command.
abstract  java.lang.String getHelp()
          Creates a string with the information about the command.
 java.lang.String getResult()
           
 boolean hasResult()
           
abstract  boolean parse(java.lang.String line)
          Tries to configure the command with the information contained in a string.
 void setConfig(java.util.Properties config)
          Implements the toString method (it would be useful to show information about the command)
 void setGame(Game theGame)
           
abstract  java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_game

protected Game _game
A reference to a game object.


_successful

protected boolean _successful
Was the command successful?


_parsed

protected boolean _parsed
Was the command parsed?


_executed

protected boolean _executed
Was the command executed?


_result

protected java.lang.String _result
What was the result?


_config

protected GameConfig _config
Constructor Detail

Command

public Command(Game theGame)
        throws java.lang.IllegalArgumentException
A constructor that initializes the reference to the game.

Parameters:
theGame - Reference to main Game
Throws:
java.lang.IllegalArgumentException

Command

public Command(Game theGame,
               java.util.Properties config)
        throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException
Method Detail

clone

public java.lang.Object clone()
Returns a clone of this command.

Overrides:
clone in class java.lang.Object

execute

public boolean execute()
                throws UnparsedCommandException
Executes the command.

Throws:
UnparsedCommandException

getHelp

public abstract java.lang.String getHelp()
Creates a string with the information about the command.

Returns:
How to write this command

getResult

public java.lang.String getResult()

hasResult

public boolean hasResult()
                  throws UnparsedCommandException,
                         UnexecutedCommandException,
                         NoCommandResultException
Throws:
UnparsedCommandException
UnexecutedCommandException
NoCommandResultException

parse

public abstract boolean parse(java.lang.String line)
Tries to configure the command with the information contained in a string.

Parameters:
line - Order to parse
Returns:
Successfulness of the parse

setConfig

public void setConfig(java.util.Properties config)
               throws java.lang.IllegalArgumentException
Implements the toString method (it would be useful to show information about the command)

Throws:
java.lang.IllegalArgumentException

setGame

public void setGame(Game theGame)
             throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object