aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/esieequest/controller/Interpreter.java3
-rw-r--r--src/esieequest/controller/Performer.java18
-rw-r--r--src/esieequest/model/Game.java7
-rw-r--r--src/esieequest/model/commands/CommandWord.java2
-rw-r--r--src/esieequest/model/map/Door.java12
-rw-r--r--src/esieequest/model/map/Room.java7
-rw-r--r--src/esieequest/model/map/TransporterDoor.java3
-rw-r--r--test/random.txt17
8 files changed, 67 insertions, 2 deletions
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
index e09ad91..5f9dafa 100644
--- a/src/esieequest/controller/Interpreter.java
+++ b/src/esieequest/controller/Interpreter.java
@@ -79,6 +79,9 @@ class Interpreter {
79 case LOOK: 79 case LOOK:
80 this.performer.look(); 80 this.performer.look();
81 return; 81 return;
82 case ALEA:
83 this.performer.forceAlea(command.getOption());
84 return;
82 85
83 // items related: 86 // items related:
84 case INVENTORY: 87 case INVENTORY:
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
index 59a3973..17d2cd8 100644
--- a/src/esieequest/controller/Performer.java
+++ b/src/esieequest/controller/Performer.java
@@ -11,6 +11,7 @@ import esieequest.model.items.Item;
11import esieequest.model.map.Door; 11import esieequest.model.map.Door;
12import esieequest.model.map.LockedDoor; 12import esieequest.model.map.LockedDoor;
13import esieequest.model.map.Room; 13import esieequest.model.map.Room;
14import esieequest.model.map.TransporterDoor;
14import esieequest.model.map.TrapDoor; 15import esieequest.model.map.TrapDoor;
15import esieequest.view.View; 16import esieequest.view.View;
16 17
@@ -249,4 +250,21 @@ class Performer {
249 } 250 }
250 } 251 }
251 252
253 public void forceAlea(final String forcedRoomName) {
254 Room destinationRoom = null;
255 if (forcedRoomName != null) {
256 destinationRoom = this.game.getRooms().get(forcedRoomName);
257 if (destinationRoom == null) {
258 this.echo("No such room.");
259 return;
260 }
261 }
262 for (final Room room : this.game.getRooms().values()) {
263 for (final Door exit : room.getExits().values()) {
264 if (exit.getClass() == TransporterDoor.class) {
265 ((TransporterDoor) exit).setDestination(destinationRoom);
266 }
267 }
268 }
269 }
252} 270}
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index e5e3b56..17fad02 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -268,4 +268,11 @@ public class Game {
268 return "Available commands:"; 268 return "Available commands:";
269 } 269 }
270 270
271 /**
272 * @return the rooms
273 */
274 public HashMap<String, Room> getRooms() {
275 return this.rooms;
276 }
277
271} 278}
diff --git a/src/esieequest/model/commands/CommandWord.java b/src/esieequest/model/commands/CommandWord.java
index 555fe15..7162b7a 100644
--- a/src/esieequest/model/commands/CommandWord.java
+++ b/src/esieequest/model/commands/CommandWord.java
@@ -7,6 +7,6 @@ package esieequest.model.commands;
7 */ 7 */
8public enum CommandWord { 8public enum CommandWord {
9 9
10 NEW, LOAD, SAVE, SOUND, HELP, QUIT, LOOK, FORWARD, BACK, GO, TURN, DO, TAKE, DROP, TALK, INVENTORY, USE, UNKNOWN; 10 NEW, LOAD, SAVE, SOUND, HELP, QUIT, LOOK, FORWARD, BACK, GO, TURN, DO, TAKE, DROP, TALK, INVENTORY, USE, ALEA, UNKNOWN;
11 11
12} 12}
diff --git a/src/esieequest/model/map/Door.java b/src/esieequest/model/map/Door.java
index 122b529..dfa0551 100644
--- a/src/esieequest/model/map/Door.java
+++ b/src/esieequest/model/map/Door.java
@@ -7,7 +7,7 @@ package esieequest.model.map;
7 */ 7 */
8public class Door { 8public class Door {
9 9
10 private final Room destination; 10 private Room destination;
11 11
12 /** 12 /**
13 * Creates a new Door. 13 * Creates a new Door.
@@ -28,4 +28,14 @@ public class Door {
28 return this.destination; 28 return this.destination;
29 } 29 }
30 30
31 /**
32 * Sets the destination room.
33 *
34 * @param destination
35 * the destination room
36 */
37 public void setDestination(final Room destination) {
38 this.destination = destination;
39 }
40
31} 41}
diff --git a/src/esieequest/model/map/Room.java b/src/esieequest/model/map/Room.java
index 421e781..3e606d7 100644
--- a/src/esieequest/model/map/Room.java
+++ b/src/esieequest/model/map/Room.java
@@ -115,4 +115,11 @@ public class Room {
115 return this.items; 115 return this.items;
116 } 116 }
117 117
118 /**
119 * @return the exits
120 */
121 public HashMap<String, Door> getExits() {
122 return this.exits;
123 }
124
118} 125}
diff --git a/src/esieequest/model/map/TransporterDoor.java b/src/esieequest/model/map/TransporterDoor.java
index 8c5fc6e..47fb6c2 100644
--- a/src/esieequest/model/map/TransporterDoor.java
+++ b/src/esieequest/model/map/TransporterDoor.java
@@ -19,6 +19,9 @@ public class TransporterDoor extends Door {
19 19
20 @Override 20 @Override
21 public Room getDestination() { 21 public Room getDestination() {
22 if (super.getDestination() != null) {
23 return super.getDestination();
24 }
22 return this.findRandomRoom(); 25 return this.findRandomRoom();
23 } 26 }
24 27
diff --git a/test/random.txt b/test/random.txt
new file mode 100644
index 0000000..19c71f9
--- /dev/null
+++ b/test/random.txt
@@ -0,0 +1,17 @@
1go north
2go west
3go north
4go east
5go east
6go east
7go north
8go east
9go east
10alea Storage room
11go east
12back
13alea
14go east
15back
16alea poire
17go east \ No newline at end of file