aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/esieequest/controller/Interpreter.java3
-rw-r--r--src/esieequest/controller/Performer.java8
-rw-r--r--src/esieequest/model/Game.java21
3 files changed, 27 insertions, 5 deletions
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
index 5c60c0b..586b329 100644
--- a/src/esieequest/controller/Interpreter.java
+++ b/src/esieequest/controller/Interpreter.java
@@ -63,6 +63,9 @@ class Interpreter {
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":
67 this.performer.goBack();
68 return;
66 case "look": 69 case "look":
67 this.performer.look(); 70 this.performer.look();
68 return; 71 return;
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
index 6da3901..0ac194f 100644
--- a/src/esieequest/controller/Performer.java
+++ b/src/esieequest/controller/Performer.java
@@ -109,6 +109,14 @@ class Performer {
109 } 109 }
110 110
111 /** 111 /**
112 * Changes the current room to the previous one.
113 */
114 public void goBack() {
115 this.game.goToPreviousRoom();
116 this.echo(this.game.getLocationInfo());
117 }
118
119 /**
112 * Displays informations about the current place. 120 * Displays informations about the current place.
113 */ 121 */
114 public void look() { 122 public void look() {
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 99afa7c..5f2049c 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -1,6 +1,7 @@
1package esieequest.model; 1package esieequest.model;
2 2
3import java.util.HashMap; 3import java.util.HashMap;
4import java.util.Stack;
4 5
5/** 6/**
6 * Represents the game. 7 * Represents the game.
@@ -12,6 +13,7 @@ public class Game {
12 13
13 private final HashMap<String, Room> rooms; 14 private final HashMap<String, Room> rooms;
14 private Room currentRoom; 15 private Room currentRoom;
16 private Stack<Room> previousRooms;
15 17
16 /** 18 /**
17 * The default constructor. 19 * The default constructor.
@@ -19,6 +21,7 @@ public class Game {
19 public Game() { 21 public Game() {
20 this.rooms = new HashMap<String, Room>(); 22 this.rooms = new HashMap<String, Room>();
21 this.currentRoom = null; 23 this.currentRoom = null;
24 this.previousRooms = new Stack<Room>();
22 25
23 this.createRooms(); 26 this.createRooms();
24 this.linkRooms(); 27 this.linkRooms();
@@ -48,8 +51,7 @@ public class Game {
48 * @param exitRoomName 51 * @param exitRoomName
49 * the name of the exit room 52 * the name of the exit room
50 */ 53 */
51 private void setRoomExit(final String roomName, final String direction, 54 private void setRoomExit(final String roomName, final String direction, final String exitRoomName) {
52 final String exitRoomName) {
53 this.rooms.get(roomName).addExit(direction, this.rooms.get(exitRoomName)); 55 this.rooms.get(roomName).addExit(direction, this.rooms.get(exitRoomName));
54 } 56 }
55 57
@@ -98,8 +100,7 @@ public class Game {
98 this.createRoom("OffscriptLock", "somewhere implementing a doorlock"); 100 this.createRoom("OffscriptLock", "somewhere implementing a doorlock");
99 this.createRoom("OffscriptLockLockedroom", "in a locked room that is not anymore"); 101 this.createRoom("OffscriptLockLockedroom", "in a locked room that is not anymore");
100 this.createRoom("OffscriptAlea", "somewhere implementing alea"); 102 this.createRoom("OffscriptAlea", "somewhere implementing alea");
101 this.createRoom("OffscriptAleaRoomrandomizer", 103 this.createRoom("OffscriptAleaRoomrandomizer", "in a weird room that will transport you somewhere else");
102 "in a weird room that will transport you somewhere else");
103 this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); 104 this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character");
104 this.createRoom("OffscriptMovingcharacterMo", "in M-O's room"); 105 this.createRoom("OffscriptMovingcharacterMo", "in M-O's room");
105 106
@@ -199,12 +200,13 @@ public class Game {
199 } 200 }
200 201
201 /** 202 /**
202 * Sets the current room. 203 * Sets the current room and stacks previous rooms.
203 * 204 *
204 * @param room 205 * @param room
205 * the destination room 206 * the destination room
206 */ 207 */
207 public void goToRoom(final Room room) { 208 public void goToRoom(final Room room) {
209 this.previousRooms.push(this.currentRoom);
208 this.currentRoom = room; 210 this.currentRoom = room;
209 } 211 }
210 212
@@ -219,6 +221,15 @@ public class Game {
219 } 221 }
220 222
221 /** 223 /**
224 * Sets the current room to the previous room.
225 */
226 public void goToPreviousRoom() {
227 if (!this.previousRooms.empty()) {
228 this.currentRoom = this.previousRooms.pop();
229 }
230 }
231
232 /**
222 * Returns the current room's exit located in the given direction. 233 * Returns the current room's exit located in the given direction.
223 * 234 *
224 * @param direction 235 * @param direction