diff options
-rw-r--r-- | report/progression.tex | 7 | ||||
-rw-r--r-- | src/esieequest/controller/Interpreter.java | 24 | ||||
-rw-r--r-- | src/esieequest/controller/Parser.java | 24 | ||||
-rw-r--r-- | src/esieequest/controller/Performer.java | 12 | ||||
-rw-r--r-- | src/esieequest/model/commands/Command.java | 6 | ||||
-rw-r--r-- | src/esieequest/model/commands/CommandWord.java | 63 | ||||
-rw-r--r-- | src/esieequest/view/app/UserInterface.java | 23 | ||||
-rw-r--r-- | src/esieequest/view/web/WebInterface.java | 17 |
8 files changed, 63 insertions, 113 deletions
diff --git a/report/progression.tex b/report/progression.tex index 94cc5b5..ccfff83 100644 --- a/report/progression.tex +++ b/report/progression.tex | |||
@@ -313,10 +313,15 @@ The commands test file was updated in the commit number 7b610fc05. | |||
313 | 313 | ||
314 | \subsection{switch} | 314 | \subsection{switch} |
315 | 315 | ||
316 | \subsection{look with enum} | 316 | The String switch statement was replaced by an enum switch with the |
317 | commit number d24dd6cc9. Instead of using an HashMap to match entered Strings to | ||
318 | the corresponding enum value, the valueOf() method was used. | ||
317 | 319 | ||
318 | \subsection{help with enum} | 320 | \subsection{help with enum} |
319 | 321 | ||
322 | The help command now generates the list of the available commands from the enum | ||
323 | with the commit number 159b168b2. | ||
324 | |||
320 | 325 | ||
321 | \section{Zuul extended} | 326 | \section{Zuul extended} |
322 | 327 | ||
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index 5c60f6d..32adeda 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java | |||
@@ -48,40 +48,40 @@ class Interpreter { | |||
48 | public void dispatch(final Command command) { | 48 | public void dispatch(final Command command) { |
49 | if (command.getAction() != null) { | 49 | if (command.getAction() != null) { |
50 | switch (command.getAction()) { | 50 | switch (command.getAction()) { |
51 | case "new": | 51 | case NEW: |
52 | this.performer.newGame(); | 52 | this.performer.newGame(); |
53 | return; | 53 | return; |
54 | case "load": | 54 | case LOAD: |
55 | this.performer.loadGame(); | 55 | this.performer.loadGame(); |
56 | return; | 56 | return; |
57 | case "save": | 57 | case SAVE: |
58 | this.performer.saveGame(); | 58 | this.performer.saveGame(); |
59 | return; | 59 | return; |
60 | case "sound": | 60 | case SOUND: |
61 | this.performer.toggleSound(); | 61 | this.performer.toggleSound(); |
62 | return; | 62 | return; |
63 | case "go": | 63 | case GO: |
64 | this.performer.goTo(command.getOption()); | 64 | this.performer.goTo(command.getOption()); |
65 | return; | 65 | return; |
66 | case "back": | 66 | case BACK: |
67 | this.performer.goBack(); | 67 | this.performer.goBack(); |
68 | return; | 68 | return; |
69 | case "look": | 69 | case LOOK: |
70 | this.performer.look(); | 70 | this.performer.look(); |
71 | return; | 71 | return; |
72 | case "inventory": | 72 | case INVENTORY: |
73 | this.performer.listItems(); | 73 | this.performer.listItems(); |
74 | return; | 74 | return; |
75 | case "take": | 75 | case TAKE: |
76 | this.performer.take(command.getOption()); | 76 | this.performer.take(command.getOption()); |
77 | return; | 77 | return; |
78 | case "drop": | 78 | case DROP: |
79 | this.performer.drop(command.getOption()); | 79 | this.performer.drop(command.getOption()); |
80 | return; | 80 | return; |
81 | case "help": | 81 | case HELP: |
82 | this.performer.showHelp(); | 82 | this.performer.showHelp(); |
83 | return; | 83 | return; |
84 | case "quit": | 84 | case QUIT: |
85 | this.performer.quitGame(); | 85 | this.performer.quitGame(); |
86 | return; | 86 | return; |
87 | } | 87 | } |
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java index 452c27c..7b07efb 100644 --- a/src/esieequest/controller/Parser.java +++ b/src/esieequest/controller/Parser.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import esieequest.model.commands.Command; | 3 | import esieequest.model.commands.Command; |
4 | import esieequest.model.commands.CommandWord; | ||
4 | 5 | ||
5 | /** | 6 | /** |
6 | * The command parser. | 7 | * The command parser. |
@@ -26,25 +27,20 @@ class Parser { | |||
26 | public Command getCommand(final String commandString) { | 27 | public Command getCommand(final String commandString) { |
27 | final String[] elements = commandString.split(" "); | 28 | final String[] elements = commandString.split(" "); |
28 | 29 | ||
29 | String action = null; | 30 | CommandWord action = null; |
30 | String option = null; | 31 | String option = null; |
31 | 32 | ||
32 | if (elements.length > 0) { | 33 | try { |
33 | action = elements[0]; | 34 | action = CommandWord.valueOf(elements[0].toUpperCase()); |
34 | } | 35 | } catch (final Exception e) { |
35 | if (elements.length > 1) { | 36 | action = CommandWord.UNKNOWN; |
36 | option = elements[1]; | 37 | } finally { |
38 | if (elements.length > 1) { | ||
39 | option = elements[1]; | ||
40 | } | ||
37 | } | 41 | } |
38 | 42 | ||
39 | return new Command(action, option); | 43 | return new Command(action, option); |
40 | } | 44 | } |
41 | 45 | ||
42 | /** | ||
43 | * Checks whether the command contains a valid action with a valid option. | ||
44 | */ | ||
45 | private boolean validateCommand() { | ||
46 | // TODO | ||
47 | return true; | ||
48 | } | ||
49 | |||
50 | } | 46 | } |
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 8f8afeb..7ba8c94 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java | |||
@@ -1,6 +1,10 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import java.util.HashSet; | ||
4 | import java.util.Set; | ||
5 | |||
3 | import esieequest.model.Game; | 6 | import esieequest.model.Game; |
7 | import esieequest.model.commands.CommandWord; | ||
4 | import esieequest.model.items.Inventory; | 8 | import esieequest.model.items.Inventory; |
5 | import esieequest.model.map.Room; | 9 | import esieequest.model.map.Room; |
6 | import esieequest.view.View; | 10 | import esieequest.view.View; |
@@ -88,9 +92,11 @@ class Performer { | |||
88 | * Displays the help message and the available commands. | 92 | * Displays the help message and the available commands. |
89 | */ | 93 | */ |
90 | public void showHelp() { | 94 | public void showHelp() { |
91 | this.notImplemented(); | 95 | final Set<String> commands = new HashSet<String>(); |
92 | // this.echo(this.game.getHelpMessage()); | 96 | for (final CommandWord command : CommandWord.values()) { |
93 | // TODO: list commands | 97 | commands.add(command.name().toLowerCase()); |
98 | } | ||
99 | this.echo(Utils.list(commands, "Commands:", "No commands.")); | ||
94 | } | 100 | } |
95 | 101 | ||
96 | /** | 102 | /** |
diff --git a/src/esieequest/model/commands/Command.java b/src/esieequest/model/commands/Command.java index ea33c35..15b4322 100644 --- a/src/esieequest/model/commands/Command.java +++ b/src/esieequest/model/commands/Command.java | |||
@@ -7,7 +7,7 @@ package esieequest.model.commands; | |||
7 | */ | 7 | */ |
8 | public class Command { | 8 | public class Command { |
9 | 9 | ||
10 | private final String action; | 10 | private final CommandWord action; |
11 | private final String option; | 11 | private final String option; |
12 | 12 | ||
13 | /** | 13 | /** |
@@ -18,7 +18,7 @@ public class Command { | |||
18 | * @param option | 18 | * @param option |
19 | * the option | 19 | * the option |
20 | */ | 20 | */ |
21 | public Command(final String action, final String option) { | 21 | public Command(final CommandWord action, final String option) { |
22 | this.action = action; | 22 | this.action = action; |
23 | this.option = option; | 23 | this.option = option; |
24 | } | 24 | } |
@@ -28,7 +28,7 @@ public class Command { | |||
28 | * | 28 | * |
29 | * @return the action | 29 | * @return the action |
30 | */ | 30 | */ |
31 | public String getAction() { | 31 | public CommandWord getAction() { |
32 | return this.action; | 32 | return this.action; |
33 | } | 33 | } |
34 | 34 | ||
diff --git a/src/esieequest/model/commands/CommandWord.java b/src/esieequest/model/commands/CommandWord.java index 2afa372..555fe15 100644 --- a/src/esieequest/model/commands/CommandWord.java +++ b/src/esieequest/model/commands/CommandWord.java | |||
@@ -1,71 +1,12 @@ | |||
1 | package esieequest.model.commands; | 1 | package esieequest.model.commands; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * Contains the commands that the user can enter |