aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-03-12 09:57:28 +0000
committerPacien TRAN-GIRARD2014-03-12 09:57:28 +0000
commit2603c3643d180bf33748af87be668c5cb6e0b430 (patch)
treefc1ea01afe75e544bf77c939a9d6b94258f1105e
parent9e42ce69208d1b496b96c1a2473993e215c06352 (diff)
parent07c3d56b24c9693ec060399823dd233184c054a3 (diff)
downloadesieequest-2603c3643d180bf33748af87be668c5cb6e0b430.tar.gz
Merge branch 'zuul-with-history' into 'master'
Zuul With History
-rw-r--r--report/progression.tex15
-rw-r--r--src/esieequest/controller/Interpreter.java3
-rw-r--r--src/esieequest/controller/Performer.java8
-rw-r--r--src/esieequest/model/Game.java21
4 files changed, 42 insertions, 5 deletions
diff --git a/report/progression.tex b/report/progression.tex
index 6600430..cf4f3d2 100644
--- a/report/progression.tex
+++ b/report/progression.tex
@@ -204,12 +204,27 @@ to perform actions on a particular one (take, drop, use, etc\ldots).
204 204
205\subsection{back} 205\subsection{back}
206 206
207The back command was implemented as part of commit f218bf5fa.
208
207\subsection{back test} 209\subsection{back test}
208 210
211The back command works even with any parameter. We will check this later with
212"zuul-with-enums".
213
209\subsection{back back} 214\subsection{back back}
210 215
216When the user enters back twice, he goes two rooms backward. This is working
217correctly.
218
211\subsection{Stack} 219\subsection{Stack}
212 220
221The Stack class represents a last-in-first-out (LIFO) stack of objects. The push()
222method allows to add and element at the top of the stack and the pop() method
223allows to retrieve the top item and removes it.
224
225A condition checks whether the Stack is empty before calling the pop() method,
226so that the program does not throw an Exception. This resolve the case when the
227player is at the starting point.
213 228
214\section{Zuul with tests} 229\section{Zuul with tests}
215 230
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