diff options
Diffstat (limited to 'src/esieequest/model/Game.java')
-rw-r--r-- | src/esieequest/model/Game.java | 21 |
1 files changed, 16 insertions, 5 deletions
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 @@ | |||
1 | package esieequest.model; | 1 | package esieequest.model; |
2 | 2 | ||
3 | import java.util.HashMap; | 3 | import java.util.HashMap; |
4 | import 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 |