-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommand.java
68 lines (60 loc) · 1.71 KB
/
Command.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* This class is part of the "NolsPotLex" application. "NolsPotLex" is a
* very simple, text based adventure game.
*
* This class holds information about a command that was issued by the user. A
* command currently consists of two parts: a CommandWord and a string (for
* example, if the command was "take map", then the two parts are TAKE and
* "map").
*
* The way this is used is: Commands are already checked for being valid command
* words. If the user entered an invalid command (a word that is not known) then
* the CommandWord is UNKNOWN.
*
* If the command had only one word, then the second word is <null>.
*
* @author Michael Kolling and David J. Barnes and Alexandre Boursier and Nolan Potier
* @version 2011.10.28
*/
public abstract class Command {
private String secondWord;
/**
* Create a command object.
*
* The command word should be null to tell the command is UNKNOWN
*/
public Command()
{
secondWord = null;
}
/**
* Return the second word of this command. If no
* second word was entered, the result is null.
*/
public String getSecondWord()
{
return secondWord;
}
/**
* Check whether a second word was entered for this
* command.
*/
public boolean hasSecondWord()
{
return secondWord != null;
}
/**
* Define the second word of thie command
*/
public void setSecondWord(String secondWord)
{
this.secondWord = secondWord;
}
/**
* Execute the current command.
* A flag is returned indicating :
*
* @return True, if game should exit; false otherwise.
*/
public abstract boolean execute(Player player);
}