diff options
Diffstat (limited to 'src/esieequest/model/Game.java')
-rw-r--r-- | src/esieequest/model/Game.java | 69 |
1 files changed, 20 insertions, 49 deletions
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 62dfc94..cc6157d 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java | |||
@@ -1,7 +1,10 @@ | |||
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 | import esieequest.model.entities.Player; | ||
6 | import esieequest.model.items.Item; | ||
7 | import esieequest.model.map.Room; | ||
5 | 8 | ||
6 | /** | 9 | /** |
7 | * Represents the game. | 10 | * Represents the game. |
@@ -12,17 +15,16 @@ import java.util.Stack; | |||
12 | public class Game { | 15 | public class Game { |
13 | 16 | ||
14 | private final HashMap<String, Room> rooms; | 17 | private final HashMap<String, Room> rooms; |
15 | private Room currentRoom; | ||
16 | 18 | ||
17 | private final Stack<Room> previousRooms; | 19 | private final Player player; |
18 | 20 | ||
19 | /** | 21 | /** |
20 | * The default constructor. | 22 | * The default constructor. |
21 | */ | 23 | */ |
22 | public Game() { | 24 | public Game() { |
23 | this.rooms = new HashMap<String, Room>(); | 25 | this.rooms = new HashMap<String, Room>(); |
24 | this.currentRoom = null; | 26 | |
25 | this.previousRooms = new Stack<Room>(); | 27 | this.player = new Player(10); |
26 | 28 | ||
27 | this.createRooms(); | 29 | this.createRooms(); |
28 | this.linkRooms(); | 30 | this.linkRooms(); |
@@ -31,6 +33,15 @@ public class Game { | |||
31 | } | 33 | } |
32 | 34 | ||
33 | /** | 35 | /** |
36 | * Returns the player | ||
37 | * | ||
38 | * @return the player | ||
39 | */ | ||
40 | public Player getPlayer() { | ||
41 | return this.player; | ||
42 | } | ||
43 | |||
44 | /** | ||
34 | * Creates a new room. | 45 | * Creates a new room. |
35 | * | 46 | * |
36 | * @param name | 47 | * @param name |
@@ -180,19 +191,9 @@ public class Game { | |||
180 | * Creates and adds items into rooms. | 191 | * Creates and adds items into rooms. |
181 | */ | 192 | */ |
182 | private void createItems() { | 193 | private void createItems() { |
183 | this.rooms.get("Cafeteria").addItem("Banana", new Item("A yellow banana", 12)); | 194 | this.rooms.get("Cafeteria").getItems().putItem("banana", new Item("A yellow banana", 5)); |
184 | this.rooms.get("Cafeteria").addItem("Orange", new Item("An orange orange", 15)); | 195 | this.rooms.get("Cafeteria").getItems().putItem("orange", new Item("An orange orange", 6)); |
185 | } | 196 | this.rooms.get("Cafeteria").getItems().putItem("anti-matter", new Item("A block of anti-matter with a negative mass", -10)); |
186 | |||
187 | /** | ||
188 | * Sets the current room and stacks previous rooms. | ||
189 | * | ||
190 | * @param room | ||
191 | * the destination room | ||
192 | */ | ||
193 | public void goToRoom(final Room room) { | ||
194 | this.previousRooms.push(this.currentRoom); | ||
195 | this.currentRoom = room; | ||
196 | } | 197 | } |
197 | 198 | ||
198 | /** | 199 | /** |
@@ -202,37 +203,7 @@ public class Game { | |||
202 | * the destination room name | 203 | * the destination room name |
203 | */ | 204 | */ |
204 | public void goToRoom(final String roomName) { | 205 | public void goToRoom(final String roomName) { |
205 | this.currentRoom = this.rooms.get(roomName); | 206 | this.player.goToRoom(this.rooms.get(roomName)); |
206 | } | ||
207 | |||
208 | /** | ||
209 | * Sets the current room to the previous room. | ||
210 | */ | ||
211 | public void goToPreviousRoom() { | ||
212 | if (!this.previousRooms.empty()) { | ||
213 | this.currentRoom = this.previousRooms.pop(); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Returns the current room. | ||
219 | * | ||
220 | * @return the current room | ||
221 | */ | ||
222 | public Room getCurrentRoom() { | ||
223 | return this.currentRoom; | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * Returns the current room's exit located in the given direction. | ||
228 | * | ||
229 | * @param direction | ||
230 | * the direction of the exit | ||
231 | * | ||
232 | * @return the exit room | ||
233 | */ | ||
234 | public Room getRoomExit(final String direction) { | ||
235 | return this.currentRoom.getExit(direction); | ||
236 | } | 207 | } |
237 | 208 | ||
238 | /** | 209 | /** |