-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.java
More file actions
75 lines (66 loc) · 1.77 KB
/
Command.java
File metadata and controls
75 lines (66 loc) · 1.77 KB
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
69
70
71
72
73
74
75
/**
* Class Command - Represents a command issued by the player in the game.
*
* A Command object stores a primary command word and, optionally, a second word
* that provides additional details.
*
*
* @author Florian NELCHA
*/
public class Command
{
// ### Attributes ###
private String aCommandWord;
private String aSecondWord;
// ### Constructor ###
/**
* Constructor that creates a Command object with a command word and an optional
* second word.
*
* @param pW1 The main command word.
* @param pW2 An optional second word (e.g., direction or item).
*/
public Command(final String pW1,final String pW2)
{
this.aCommandWord = pW1;
this.aSecondWord = pW2;
} // Command()
// ### Getters ###
/**
* Gets the main command word.
*
* @return The main command word.
*/
public String getCommandWord()
{
return this.aCommandWord;
} // getCommandWord()
/**
* Gets the secondary word if available.
*
* @return The secondary word, or null if it does not exist.
*/
public String getSecondWord()
{
return this.aSecondWord;
} // getSecondWord()
// ### Other methods ###
/**
* Checks if the command includes a secondary word.
*
* @return true if there is a secondary word, false otherwise.
*/
public boolean hasSecondWord()
{
return this.aSecondWord != null;
} // hasSecondWord()
/**
* Checks if the command is unknown (if it has no main command word).
*
* @return true if the command word is null, false otherwise.
*/
public boolean isUnknown()
{
return this.aCommandWord == null;
} // isUnknown()
} // Command