aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-04-06 21:30:51 +0000
committerPacien TRAN-GIRARD2014-04-06 21:30:51 +0000
commit8df91ed3259cecf8f640747de90200deed3a6e06 (patch)
tree5a922bd7fc5df41bd6d26fedac7d6447c933d211
parent7cec06bea8172ceb7d819f4d2d4474585200c74d (diff)
parent3a34f0e78c1843335e6e92879285b5bda39cd869 (diff)
downloadesieequest-8df91ed3259cecf8f640747de90200deed3a6e06.tar.gz
Merge branch 'zuul-with-enums' into 'master'
Zuul With Enums
-rw-r--r--report/progression.tex7
-rw-r--r--src/esieequest/controller/Interpreter.java24
-rw-r--r--src/esieequest/controller/Parser.java24
-rw-r--r--src/esieequest/controller/Performer.java12
-rw-r--r--src/esieequest/model/commands/Command.java6
-rw-r--r--src/esieequest/model/commands/CommandWord.java63
-rw-r--r--src/esieequest/view/app/UserInterface.java23
-rw-r--r--src/esieequest/view/web/WebInterface.java17
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} 316The String switch statement was replaced by an enum switch with the
317commit number d24dd6cc9. Instead of using an HashMap to match entered Strings to
318the corresponding enum value, the valueOf() method was used.
317 319
318\subsection{help with enum} 320\subsection{help with enum}
319 321
322The help command now generates the list of the available commands from the enum
323with 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 @@
1package esieequest.controller; 1package esieequest.controller;
2 2
3import esieequest.model.commands.Command; 3import esieequest.model.commands.Command;
4import 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 @@
1package esieequest.controller; 1package esieequest.controller;
2 2
3import java.util.HashSet;
4import java.util.Set;
5
3import esieequest.model.Game; 6import esieequest.model.Game;
7import esieequest.model.commands.CommandWord;
4import esieequest.model.items.Inventory; 8import esieequest.model.items.Inventory;
5import esieequest.model.map.Room; 9import esieequest.model.map.Room;
6import esieequest.view.View; 10import 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 */
8public class Command { 8public 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 @@
1package esieequest.model.commands; 1package esieequest.model.commands;