aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/esieequest/controller/commands/AleaCommand.java2
-rw-r--r--src/esieequest/controller/commands/BackCommand.java6
-rw-r--r--src/esieequest/controller/commands/Command.java4
-rw-r--r--src/esieequest/controller/commands/DoCommand.java5
-rw-r--r--src/esieequest/controller/commands/DropCommand.java2
-rw-r--r--src/esieequest/controller/commands/Executable.java2
-rw-r--r--src/esieequest/controller/commands/ForwardCommand.java24
-rw-r--r--src/esieequest/controller/commands/GoCommand.java26
-rw-r--r--src/esieequest/controller/commands/HelpCommand.java6
-rw-r--r--src/esieequest/controller/commands/InventoryCommand.java6
-rw-r--r--src/esieequest/controller/commands/LoadCommand.java5
-rw-r--r--src/esieequest/controller/commands/LookCommand.java5
-rw-r--r--src/esieequest/controller/commands/NewCommand.java6
-rw-r--r--src/esieequest/controller/commands/QuitCommand.java5
-rw-r--r--src/esieequest/controller/commands/SaveCommand.java10
-rw-r--r--src/esieequest/controller/commands/TakeCommand.java11
-rw-r--r--src/esieequest/controller/commands/TalkCommand.java28
-rw-r--r--src/esieequest/controller/commands/ToggleSoundCommand.java6
-rw-r--r--src/esieequest/controller/commands/TurnCommand.java11
-rw-r--r--src/esieequest/controller/commands/UseCommand.java2
-rw-r--r--src/esieequest/model/Text.java7
-rw-r--r--src/esieequest/model/map/Room.java36
-rw-r--r--src/esieequest/view/app/UserInterface.java2
-rw-r--r--src/esieequest/view/web/WebInterface.java2
24 files changed, 155 insertions, 64 deletions
diff --git a/src/esieequest/controller/commands/AleaCommand.java b/src/esieequest/controller/commands/AleaCommand.java
index ff73537..093f088 100644
--- a/src/esieequest/controller/commands/AleaCommand.java
+++ b/src/esieequest/controller/commands/AleaCommand.java
@@ -20,7 +20,7 @@ public class AleaCommand implements Executable {
20 final String forcedRoomName = argument; 20 final String forcedRoomName = argument;
21 Room destinationRoom = null; 21 Room destinationRoom = null;
22 22
23 if (forcedRoomName != null) { 23 if (!forcedRoomName.isEmpty()) {
24 try { 24 try {
25 destinationRoom = Room.valueOf(forcedRoomName.toUpperCase()); 25 destinationRoom = Room.valueOf(forcedRoomName.toUpperCase());
26 } catch (final Exception exception) { 26 } catch (final Exception exception) {
diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java
index d7ed8a3..b2322ed 100644
--- a/src/esieequest/controller/commands/BackCommand.java
+++ b/src/esieequest/controller/commands/BackCommand.java
@@ -1,6 +1,7 @@
1package esieequest.controller.commands; 1package esieequest.controller.commands;
2 2
3import esieequest.model.Game; 3import esieequest.model.Game;
4import esieequest.model.Text;
4import esieequest.view.Viewable; 5import esieequest.view.Viewable;
5 6
6/** 7/**
@@ -13,6 +14,11 @@ public class BackCommand implements Executable {
13 @Override 14 @Override
14 public void execute(final String argument, final Game game, final Viewable view) { 15 public void execute(final String argument, final Game game, final Viewable view) {
15 16
17 if (!argument.isEmpty()) {
18 view.echo(Text.TOO_MANY_ARGUMENTS.toString());
19 return;
20 }
21
16 game.getPlayer().goToPreviousRoom(); 22 game.getPlayer().goToPreviousRoom();
17 23
18 view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() 24 view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer()
diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java
index 829ebf8..651d3da 100644
--- a/src/esieequest/controller/commands/Command.java
+++ b/src/esieequest/controller/commands/Command.java
@@ -28,7 +28,6 @@ public enum Command {
28 28
29 // map related 29 // map related
30 GO(new GoCommand()), 30 GO(new GoCommand()),
31 FORWARD(new ForwardCommand()),
32 BACK(new BackCommand()), 31 BACK(new BackCommand()),
33 TURN(new TurnCommand()), 32 TURN(new TurnCommand()),
34 LOOK(new LookCommand()), 33 LOOK(new LookCommand()),
@@ -70,7 +69,8 @@ public enum Command {
70 * the View 69 * the View
71 */ 70 */
72 public void execute(final String argument, final Game game, final Viewable view) { 71 public void execute(final String argument, final Game game, final Viewable view) {
73 this.command.execute(argument, game, view); 72 final String arg = argument == null ? "" : argument;
73 this.command.execute(arg, game, view);
74 } 74 }
75 75
76 /** 76 /**
diff --git a/src/esieequest/controller/commands/DoCommand.java b/src/esieequest/controller/commands/DoCommand.java
index 646ac2a..cb596e8 100644
--- a/src/esieequest/controller/commands/DoCommand.java
+++ b/src/esieequest/controller/commands/DoCommand.java
@@ -16,6 +16,11 @@ public class DoCommand implements Executable {
16 @Override 16 @Override
17 public void execute(final String argument, final Game game, final Viewable view) { 17 public void execute(final String argument, final Game game, final Viewable view) {
18 18
19 if (!argument.isEmpty()) {
20 view.echo(Text.TOO_MANY_ARGUMENTS.toString());
21 return;
22 }
23
19 final Side currentSide = game.getPlayer().getCurrentSide(); 24 final Side currentSide = game.getPlayer().getCurrentSide();
20 25
21 if (currentSide.hasCharacter()) { 26 if (currentSide.hasCharacter()) {
diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java
index dbdf03c..6ed2b81 100644
--- a/src/esieequest/controller/commands/DropCommand.java
+++ b/src/esieequest/controller/commands/DropCommand.java
@@ -18,7 +18,7 @@ public class DropCommand implements Executable {
18 18
19 final String itemName = argument; 19 final String itemName = argument;
20 20
21 if (itemName == null) { 21 if (itemName.isEmpty()) {
22 view.echo(Text.NO_ITEM_SPECIFIED.toString()); 22 view.echo(Text.NO_ITEM_SPECIFIED.toString());
23 return; 23 return;
24 } 24 }
diff --git a/src/esieequest/controller/commands/Executable.java b/src/esieequest/controller/commands/Executable.java
index 156fc1c..ab84b78 100644
--- a/src/esieequest/controller/commands/Executable.java
+++ b/src/esieequest/controller/commands/Executable.java
@@ -14,7 +14,7 @@ public interface Executable {
14 * Performs the task corresponding to the Command. 14 * Performs the task corresponding to the Command.
15 * 15 *
16 * @param argument 16 * @param argument
17 * the argument to pass to the Command 17 * the argument to pass to the Command (null if empty String)
18 * @param game 18 * @param game
19 * the Game model 19 * the Game model
20 * @param view 20 * @param view
diff --git a/src/esieequest/controller/commands/ForwardCommand.java b/src/esieequest/controller/commands/ForwardCommand.java
deleted file mode 100644
index 9134fdc..0000000
--- a/src/esieequest/controller/commands/ForwardCommand.java
+++ /dev/null
@@ -1,24 +0,0 @@
1package esieequest.controller.commands;
2
3import esieequest.model.Game;
4import esieequest.model.map.Direction;
5import esieequest.view.Viewable;
6
7/**
8 * Allows the user to move forward in the Map (in the Room at the Direction he
9 * is facing).
10 *
11 * @author Pacien TRAN-GIRARD
12 */
13public class ForwardCommand implements Executable {
14
15 @Override
16 public void execute(final String argument, final Game game, final Viewable view) {
17
18 final Direction direction = game.getPlayer().getCurrentDirection();
19
20 Command.GO.execute(direction.name(), game, view);
21
22 }
23
24}
diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java
index a68f5ad..4bcd0e1 100644
--- a/src/esieequest/controller/commands/GoCommand.java
+++ b/src/esieequest/controller/commands/GoCommand.java
@@ -17,22 +17,30 @@ public class GoCommand implements Executable {
17 @Override 17 @Override
18 public void execute(final String argument, final Game game, final Viewable view) { 18 public void execute(final String argument, final Game game, final Viewable view) {
19 19
20 final Direction direction; 20 Direction direction;
21 21
22 try { 22 if (!argument.isEmpty()) {
23 direction = Direction.valueOf(argument.toUpperCase());
24 } catch (final Exception exception) {
25 view.echo(Text.NO_SUCH_DIRECTION.toString());
26 return;
27 }
28 23
29 final Door door = game.getPlayer().getCurrentRoom().getSide(direction).getDoor(); 24 try {
25 direction = Direction.valueOf(argument.toUpperCase());
26 } catch (final IllegalArgumentException e) {
27 view.echo(Text.NO_SUCH_DIRECTION.toString());
28 return;
29 }
30
31 } else {
32
33 direction = game.getPlayer().getCurrentDirection();
30 34
31 if (door == null) { 35 }
36
37 if (!game.getPlayer().getCurrentRoom().getSide(direction).hasDoor()) {
32 view.echo(Text.NO_DOOR.toString()); 38 view.echo(Text.NO_DOOR.toString());
33 return; 39 return;
34 } 40 }
35 41
42 final Door door = game.getPlayer().getCurrentRoom().getSide(direction).getDoor();
43
36 final boolean crossed = door.cross(game, view); 44 final boolean crossed = door.cross(game, view);
37