diff options
Diffstat (limited to 'src/esieequest/model/Game.java')
-rw-r--r-- | src/esieequest/model/Game.java | 136 |
1 files changed, 102 insertions, 34 deletions
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index c9d7933..99afa7c 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java | |||
@@ -1,23 +1,22 @@ | |||
1 | package esieequest.model; | 1 | package esieequest.model; |
2 | 2 | ||
3 | import java.util.HashMap; | 3 | import java.util.HashMap; |
4 | import java.util.Set; | ||
5 | 4 | ||
6 | /** | 5 | /** |
6 | * Represents the game. | ||
7 | * | 7 | * |
8 | * @author Pacien TRAN-GIRARD | 8 | * @author Pacien TRAN-GIRARD |
9 | * @author Benoit LUBRANO DI SBARAGLIONE | 9 | * @author BenoƮt LUBRANO DI SBARAGLIONE |
10 | * | ||
11 | * @version February 2014 | ||
12 | */ | 10 | */ |
13 | public class Game { | 11 | public class Game { |
14 | 12 | ||
15 | private boolean running; | 13 | private final HashMap<String, Room> rooms; |
16 | private HashMap<String, Room> rooms; | ||
17 | private Room currentRoom; | 14 | private Room currentRoom; |
18 | 15 | ||
16 | /** | ||
17 | * The default constructor. | ||
18 | */ | ||
19 | public Game() { | 19 | public Game() { |
20 | this.running = false; | ||
21 | this.rooms = new HashMap<String, Room>(); | 20 | this.rooms = new HashMap<String, Room>(); |
22 | this.currentRoom = null; | 21 | this.currentRoom = null; |
23 | 22 | ||
@@ -27,14 +26,36 @@ public class Game { | |||
27 | this.goToRoom("AmphitheaterSeat"); | 26 | this.goToRoom("AmphitheaterSeat"); |
28 | } | 27 | } |
29 | 28 | ||
30 | private void createRoom(String name, String description) { | 29 | /** |
30 | * Creates a new room. | ||
31 | * | ||
32 | * @param name | ||
33 | * the name of the room | ||
34 | * @param description | ||
35 | * the description of the room | ||
36 | */ | ||
37 | private void createRoom(final String name, final String description) { | ||
31 | this.rooms.put(name, new Room(description)); | 38 | this.rooms.put(name, new Room(description)); |
32 | } | 39 | } |
33 | 40 | ||
34 | private void setRoomExit(String roomName, String direction, String exitRoomName) { | 41 | /** |
35 | this.rooms.get(roomName).setExit(direction, this.rooms.get(exitRoomName)); | 42 | * Sets the exit room of a given room designated by its name. |
43 | * | ||
44 | * @param roomName | ||
45 | * the name of the room | ||
46 | * @param direction | ||
47 | * the direction of the exit | ||
48 | * @param exitRoomName | ||
49 | * the name of the exit room | ||
50 | */ | ||
51 | private void setRoomExit(final String roomName, final String direction, | ||
52 | final String exitRoomName) { | ||
53 | this.rooms.get(roomName).addExit(direction, this.rooms.get(exitRoomName)); | ||
36 | } | 54 | } |
37 | 55 | ||
56 | /** | ||
57 | * Creates all the rooms. | ||
58 | */ | ||
38 | private void createRooms() { | 59 | private void createRooms() { |
39 | this.createRoom("AmphitheaterSeat", "in the amphitheater"); | 60 | this.createRoom("AmphitheaterSeat", "in the amphitheater"); |
40 | this.createRoom("AmphitheaterStage", "on the amphitheater stage"); | 61 | this.createRoom("AmphitheaterStage", "on the amphitheater stage"); |
@@ -84,6 +105,9 @@ public class Game { | |||
84 | 105 | ||
85 | } | 106 | } |
86 | 107 | ||
108 | /** | ||
109 | * Connects all the rooms. | ||
110 | */ | ||
87 | private void linkRooms() { | 111 | private void linkRooms() { |
88 | this.setRoomExit("AmphitheaterSeat", "north", "AmphitheaterStage"); | 112 | this.setRoomExit("AmphitheaterSeat", "north", "AmphitheaterStage"); |
89 | this.setRoomExit("AmphitheaterStage", "west", "Cafeteria"); | 113 | this.setRoomExit("AmphitheaterStage", "west", "Cafeteria"); |
@@ -166,73 +190,117 @@ public class Game { | |||
166 | this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea"); | 190 | this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea"); |
167 | } | 191 | } |
168 | 192 | ||
193 | /** | ||
194 | * Creates and adds items into rooms. | ||
195 | */ | ||
169 | private void createItems() { | 196 | private void createItems() { |
170 | this.rooms.get("Cafeteria").addItem("Banana", new Item("A yellow banana", 12)); | 197 | this.rooms.get("Cafeteria").addItem("Banana", new Item("A yellow banana", 12)); |
171 | this.rooms.get("Cafeteria").addItem("Orange", new Item("An orange orange", 15)); | 198 | this.rooms.get("Cafeteria").addItem("Orange", new Item("An orange orange", 15)); |
172 | } | 199 | } |
173 | 200 | ||
174 | public void setRunning(boolean state) { | 201 | /** |
175 | this.running = state; | 202 | * Sets the current room. |
176 | } | 203 | * |
177 | 204 | * @param room | |
178 | public boolean isRunning() { | 205 | * the destination room |
179 | return this.running; | 206 | */ |
180 | } | 207 | public void goToRoom(final Room room) { |
181 | |||
182 | public void goToRoom(Room room) { | ||
183 | this.currentRoom = room; | 208 | this.currentRoom = room; |
184 | } | 209 | } |
185 | 210 | ||
186 | public void goToRoom(String roomName) { | 211 | /** |
212 | * Sets the current room designated by its name. | ||
213 | * | ||
214 | * @param roomName | ||
215 | * the destination room name | ||
216 | */ | ||
217 | public void goToRoom(final String roomName) { | ||
187 | this.currentRoom = this.rooms.get(roomName); | 218 | this.currentRoom = this.rooms.get(roomName); |
188 | } | 219 | } |
189 | 220 | ||
190 | public Room getRoomExit(String direction) { | 221 | /** |
222 | * Returns the current room's exit located in the given direction. | ||
223 | * | ||
224 | * @param direction | ||
225 | * the direction of the exit | ||
226 | * | ||
227 | * @return the exit room | ||
228 | */ | ||
229 | public Room getRoomExit(final String direction) { | ||
191 | return this.currentRoom.getExit(direction); | 230 | return this.currentRoom.getExit(direction); |
192 | } | 231 | } |
193 | 232 | ||
233 | /** | ||
234 | * Returns informations about the current room (description, exits and | ||
235 | * items). | ||
236 | * | ||
237 | * @return the informations about the current room | ||
238 | */ | ||
194 | public String getLocationInfo() { | 239 | public String getLocationInfo() { |
195 | return this.currentRoom.getLongDescription(); | 240 | return this.currentRoom.getInformations(); |
196 | } | 241 | } |
197 | 242 | ||
243 | /** | ||
244 | * Returns the current room's image name. | ||
245 | * | ||
246 | * @return the current room's image name. | ||
247 | */ | ||
198 | public String getLocationImageName() { | 248 | public String getLocationImageName() { |
199 | return this.currentRoom.getImageName(); | 249 | return this.currentRoom.getImageName(); |
200 | } | 250 | } |
201 | 251 | ||
202 | public String getItemDescription(String itemName) { | 252 | /** |
203 | return this.currentRoom.getItem(itemName).getDescription(); | 253 | * Returns the "eat" message. |
204 | } | 254 | * |
205 | 255 | * @return the "eat message | |
206 | public Set<String> getItemList() { | 256 | */ |
207 | return this.currentRoom.getItemList(); | ||
208 | } | ||
209 | |||
210 | public String getEatMessage() { | 257 | public String getEatMessage() { |
211 | return "oNommNommNomm..."; | 258 | return "oNommNommNomm..."; |
212 | } | 259 | } |
213 | 260 | ||
261 | /** | ||
262 | * Returns the welcome message. | ||
263 | * | ||
264 | * @return the welcome message | ||
265 | */ | ||
214 | public String getWelcomeMessage() { | 266 | public String getWelcomeMessage() { |
215 | return "Welcome to ESIEEquest! ESIEEquest is a new, amazingly boring adventure game."; | 267 | return "Welcome to ESIEEquest! ESIEEquest is a new, amazingly boring adventure game."; |
216 | } | 268 | } |
217 | 269 | ||
270 | /** | ||
271 | * Returns the help message. | ||
272 | * | ||
273 | * @return the help message | ||
274 | */ | ||
218 | public String getHelpMessage() { | 275 | public String getHelpMessage() { |
219 | return "Everybody else disappeared. You are alone. You wander around at the ESIEE."; | 276 | return "Everybody else disappeared. You are alone. You wander around at the ESIEE."; |
220 | } | 277 | } |
221 | 278 | ||
279 | /** | ||
280 | * Returns the quit message. | ||
281 | * | ||
282 | * @return the quit message | ||
283 | */ | ||
222 | public String getQuitMessage() { | 284 | public String getQuitMessage() { |
223 | return "Thank you for wasting your time. Good bye."; | 285 | return "Thank you for wasting your time. Good bye."; |
224 | } | 286 | } |
225 | 287 | ||
288 | /** | ||
289 | * Returns the "no exit" message. | ||
290 | * | ||
291 | * @return the "no exit" message | ||
292 | */ | ||
226 | public String getNoExitMessage() { | 293 | public String getNoExitMessage() { |
227 | return "There is no exit."; | 294 | return "There is no exit."; |
228 | } | 295 | } |
229 | 296 | ||