|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object es.ucm.fdi.hysteria.console.command.Command
public abstract class Command
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.
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 |
---|
protected Game _game
protected boolean _successful
protected boolean _parsed
protected boolean _executed
protected java.lang.String _result
protected GameConfig _config
Constructor Detail |
---|
public Command(Game theGame) throws java.lang.IllegalArgumentException
theGame
- Reference to main Game
java.lang.IllegalArgumentException
public Command(Game theGame, java.util.Properties config) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
Method Detail |
---|
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean execute() throws UnparsedCommandException
UnparsedCommandException
public abstract java.lang.String getHelp()
public java.lang.String getResult()
public boolean hasResult() throws UnparsedCommandException, UnexecutedCommandException, NoCommandResultException
UnparsedCommandException
UnexecutedCommandException
NoCommandResultException
public abstract boolean parse(java.lang.String line)
line
- Order to parse
public void setConfig(java.util.Properties config) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public void setGame(Game theGame) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public abstract java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |