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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
package esieequest.engine.commands;
import java.util.ArrayList;
import java.util.List;
import esieequest.engine.utils.ListUtils;
import esieequest.game.Game;
import esieequest.game.Text;
import esieequest.ui.View;
/**
* The Command-s the user can use.
*
* @author Pacien TRAN-GIRARD
*/
public enum Command {
// @formatter:off
// game related
NEW(new NewCommand()),
LOAD(new LoadCommand()),
SAVE(new SaveCommand()),
QUIT(new QuitCommand()),
HELP(new HelpCommand()),
ALEA(new AleaCommand()),
SOUND(new ToggleSoundCommand()),
// map related
GO(new GoCommand()),
BACK(new BackCommand()),
TURN(new TurnCommand()),
LOOK(new LookCommand()),
// items related
DROP(new DropCommand()),
INVENTORY(new InventoryCommand()),
TAKE(new TakeCommand()),
USE(new UseCommand()),
// characters related
TALK(new TalkCommand()),
// shortcuts
DO(new DoCommand()),
;
// @formatter:on
private Executable command;
/**
* Links an enum constant to a CommandInterface.
*
* @param command
* the CommandInterface
*/
Command(final Executable command) {
this.command = command;
}
/**
* Executes the CommandInterface's execute() method.
*
* @param argument
* the argument String to pass
* @param game
* the Game model
* @param view
* the View
*/
public void execute(final String argument, final Game game, final View view) {
final String arg = argument == null ? "" : argument;
this.command.execute(arg, game, view);
}
/**
* Lists all the Command-s names
*
* @return the list of all the names of the Command-s
*/
public static List<String> listCommandsNames() {
final ArrayList<String> commandsList = new ArrayList<String>();
for (final Command command : Command.values()) {
commandsList.add(command.name().toLowerCase());
}
return commandsList;
}
/**
* Lists all the Command-s names in a String
*
* @return a String listing all the names of the Command-s
*/
public static String listCommandsNamesString() {
return ListUtils.listToString(Command.listCommandsNames(), Text.HELP_PREFIX.toString(),
null, Text.HELP_SUFFIX.toString());
}
}
|