diff options
author | Pacien TRAN-GIRARD | 2014-04-15 20:08:49 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-04-15 20:08:49 +0200 |
commit | 6e388ec789ba5897cc65a32cfac070c79c042eae (patch) | |
tree | 643abb2f9a0c0ee35a07e3ac2fef5841ddccbc05 /src | |
parent | 0276794641327ad41bc8aade12ac5befdfd3dcfb (diff) | |
download | esieequest-6e388ec789ba5897cc65a32cfac070c79c042eae.tar.gz |
Implement TrapDoor
Diffstat (limited to 'src')
-rwxr-xr-x | src/esieequest/Main.java | 4 | ||||
-rw-r--r-- | src/esieequest/controller/Performer.java | 18 | ||||
-rw-r--r-- | src/esieequest/model/Game.java | 43 | ||||
-rw-r--r-- | src/esieequest/model/entities/Player.java | 15 | ||||
-rw-r--r-- | src/esieequest/model/map/Door.java | 20 | ||||
-rw-r--r-- | src/esieequest/model/map/Room.java | 8 | ||||
-rw-r--r-- | src/esieequest/model/map/TrapDoor.java | 15 |
7 files changed, 84 insertions, 39 deletions
diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index e8cff08..362af9c 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java | |||
@@ -62,10 +62,10 @@ public class Main extends JApplet { | |||
62 | view = new Window(); | 62 | view = new Window(); |
63 | } | 63 | } |
64 | 64 | ||
65 | if(arguments.contains("--challenge")) { | 65 | if (arguments.contains("--challenge")) { |
66 | game.getPlayer().setMaxNbSteps(50); | 66 | game.getPlayer().setMaxNbSteps(50); |
67 | } | 67 | } |
68 | 68 | ||
69 | new GameEngine(game, view); | 69 | new GameEngine(game, view); |
70 | } | 70 | } |
71 | 71 | ||
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 63cf75b..b5c32ba 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java | |||
@@ -6,7 +6,9 @@ import java.util.Set; | |||
6 | import esieequest.model.Game; | 6 | import esieequest.model.Game; |
7 | import esieequest.model.commands.CommandWord; | 7 | import esieequest.model.commands.CommandWord; |
8 | import esieequest.model.items.Inventory; | 8 | import esieequest.model.items.Inventory; |
9 | import esieequest.model.map.Door; | ||
9 | import esieequest.model.map.Room; | 10 | import esieequest.model.map.Room; |
11 | import esieequest.model.map.TrapDoor; | ||
10 | import esieequest.view.View; | 12 | import esieequest.view.View; |
11 | 13 | ||
12 | /** | 14 | /** |
@@ -106,13 +108,17 @@ class Performer { | |||
106 | * the direction of the new room | 108 | * the direction of the new room |
107 | */ | 109 | */ |
108 | public void goTo(final String direction) { | 110 | public void goTo(final String direction) { |
109 | final Room nextRoom = this.game.getPlayer().getCurrentRoom().getExit(direction); | 111 | final Door door = this.game.getPlayer().getCurrentRoom().getExit(direction); |
110 | if (nextRoom != null) { | 112 | if (door == null) { |
111 | this.game.getPlayer().goToRoom(nextRoom); | ||
112 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); | ||
113 | this.walk(); | ||
114 | } else { | ||
115 | this.echo(this.game.getNoExitMessage()); | 113 | this.echo(this.game.getNoExitMessage()); |
114 | return; | ||
115 | } | ||
116 | final Room nextRoom = door.getDestination(); | ||
117 | this.game.getPlayer().goToRoom(nextRoom); | ||
118 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); | ||
119 | this.walk(); | ||
120 | if (door.getClass() == TrapDoor.class) { | ||
121 | this.game.getPlayer().clearRoomHistory(); | ||
116 | } | 122 | } |
117 | } | 123 | } |
118 | 124 | ||
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index cc6157d..83fa143 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java | |||
@@ -4,7 +4,9 @@ import java.util.HashMap; | |||
4 | 4 | ||
5 | import esieequest.model.entities.Player; | 5 | import esieequest.model.entities.Player; |
6 | import esieequest.model.items.Item; | 6 | import esieequest.model.items.Item; |
7 | import esieequest.model.map.Door; | ||
7 | import esieequest.model.map.Room; | 8 | import esieequest.model.map.Room; |
9 | import esieequest.model.map.TrapDoor; | ||
8 | 10 | ||
9 | /** | 11 | /** |
10 | * Represents the game. | 12 | * Represents the game. |
@@ -54,20 +56,6 @@ public class Game { | |||
54 | } | 56 | } |
55 | 57 | ||
56 | /** | 58 | /** |
57 | * Sets the exit room of a given room designated by its name. | ||
58 | * | ||
59 | * @param roomName | ||
60 | * the name of the room | ||
61 | * @param direction | ||
62 | * the direction of the exit | ||
63 | * @param exitRoomName | ||
64 | * the name of the exit room | ||
65 | */ | ||
66 | private void setRoomExit(final String roomName, final String direction, final String exitRoomName) { | ||
67 | this.rooms.get(roomName).addExit(direction, this.rooms.get(exitRoomName)); | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Creates all the rooms. | 59 | * Creates all the rooms. |
72 | */ | 60 | */ |
73 | private void createRooms() { | 61 | private void createRooms() { |
@@ -101,15 +89,28 @@ public class Game { | |||
101 | 89 | ||
102 | this.createRoom("OffscriptItems", "somewhere implementing weight"); | 90 | this.createRoom("OffscriptItems", "somewhere implementing weight"); |
103 | this.createRoom("OffscriptItemsStorageroom", "in a storage room"); | 91 | this.createRoom("OffscriptItemsStorageroom", "in a storage room"); |
104 | this.createRoom("OffscriptTime", "somewhere implementing time"); | ||
105 | this.createRoom("OffscriptTimeCountdownroom", "in a dangerous room"); | ||
106 | this.createRoom("OffscriptTeleportation", "somewhere implementing teleportation"); | 92 | this.createRoom("OffscriptTeleportation", "somewhere implementing teleportation"); |
107 | this.createRoom("OffscriptTeleportationAnchorroom", "on a checkpoint"); | 93 | this.createRoom("OffscriptTeleportationAnchorroom", "on a checkpoint"); |
108 | this.createRoom("OffscriptAlea", "somewhere implementing alea"); | 94 | this.createRoom("OffscriptAlea", "somewhere implementing alea"); |
109 | this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else"); | 95 | this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else"); |
110 | this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); | 96 | this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); |
111 | this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room"); | 97 | this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room"); |
98 | } | ||
112 | 99 | ||
100 | /** | ||
101 | * Sets the exit room of a given room designated by its name. | ||
102 | * | ||
103 | * @param roomName | ||
104 | * the name of the room | ||
105 | * @param direction | ||
106 | * the direction of the exit | ||
107 | * @param exitRoomName | ||
108 | * the name of the exit room | ||
109 | */ | ||
110 | private void setRoomExit(final String roomName, final String direction, final String exitRoomName) { | ||
111 | final Room room = this.rooms.get(exitRoomName); | ||
112 | final Door door = new Door(room); | ||
113 | this.rooms.get(roomName).addExit(direction, door); | ||
113 | } | 114 | } |
114 | 115 | ||
115 | /** | 116 | /** |
@@ -153,7 +154,6 @@ public class Game { | |||
153 | this.setRoomExit("WingStreet", "east", "ClubnixStreet"); | 154 | this.setRoomExit("WingStreet", "east", "ClubnixStreet"); |
154 | this.setRoomExit("WingCorridorOne", "west", "WingStairsOne"); | 155 | this.setRoomExit("WingCorridorOne", "west", "WingStairsOne"); |
155 | this.setRoomExit("WingCorridorOne", "south", "WingStreet"); | 156 | this.setRoomExit("WingCorridorOne", "south", "WingStreet"); |
156 | this.setRoomExit("WingCorridorOne", "east", "OffscriptItems"); | ||
157 | this.setRoomExit("WingStairsOne", "south", "WingStairsTwo"); | 157 | this.setRoomExit("WingStairsOne", "south", "WingStairsTwo"); |
158 | this.setRoomExit("WingStairsOne", "up", "WingStairsTwo"); | 158 | this.setRoomExit("WingStairsOne", "up", "WingStairsTwo"); |
159 | this.setRoomExit("WingStairsOne", "east", "WingCorridorOne"); | 159 | this.setRoomExit("WingStairsOne", "east", "WingCorridorOne"); |
@@ -166,14 +166,11 @@ public class Game { | |||
166 | this.setRoomExit("WingCorridorTwoOffice", "east", "WingOffice"); | 166 | this.setRoomExit("WingCorridorTwoOffice", "east", "WingOffice"); |
167 | this.setRoomExit("WingOffice", "west", "WingCorridorTwoOffice"); | 167 | this.setRoomExit("WingOffice", "west", "WingCorridorTwoOffice"); |
168 | 168 | ||
169 | this.rooms.get("WingCorridorOne").addExit("east", new TrapDoor(this.rooms.get("OffscriptItems"))); | ||
170 | |||
169 | this.setRoomExit("OffscriptItems", "north", "OffscriptItemsStorageroom"); | 171 | this.setRoomExit("OffscriptItems", "north", "OffscriptItemsStorageroom"); |
170 | this.setRoomExit("OffscriptItems", "west", "WingCorridorOne"); | 172 | this.setRoomExit("OffscriptItems", "east", "OffscriptTeleportation"); |
171 | this.setRoomExit("OffscriptItems", "east", "OffscriptTime"); | ||
172 | this.setRoomExit("OffscriptItemsStorageroom", "south", "OffscriptItems"); | 173 | this.setRoomExit("OffscriptItemsStorageroom", "south", "OffscriptItems"); |
173 | this.setRoomExit("OffscriptTime", "north", "OffscriptTimeCountdownroom"); | ||
174 | this.setRoomExit("OffscriptTime", "west", "OffscriptTakeStorageroom"); | ||
175 | this.setRoomExit("OffscriptTime", "east", "OffscriptTeleportation"); | ||
176 | this.setRoomExit("OffscriptTimeCountdownroom", "south", "OffscriptTime"); | ||
177 | this.setRoomExit("OffscriptTeleportation", "north", "OffscriptTeleportationAnchorroom"); | 174 | this.setRoomExit("OffscriptTeleportation", "north", "OffscriptTeleportationAnchorroom"); |
178 | this.setRoomExit("OffscriptTeleportation", "west", "OffscriptTime"); | 175 | this.setRoomExit("OffscriptTeleportation", "west", "OffscriptTime"); |
179 | this.setRoomExit("OffscriptTeleportation", "east", "OffscriptAlea"); | 176 | this.setRoomExit("OffscriptTeleportation", "east", "OffscriptAlea"); |
diff --git a/src/esieequest/model/entities/Player.java b/src/esieequest/model/entities/Player.java index aaa6651..11a893f 100644 --- a/src/esieequest/model/entities/Player.java +++ b/src/esieequest/model/entities/Player.java | |||
@@ -62,6 +62,13 @@ public class Player { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Clears the previous rooms history. | ||
66 | */ | ||
67 | public void clearRoomHistory() { | ||
68 | this.previousRooms.clear(); | ||
69 | } | ||
70 | |||
71 | /** | ||
65 | * Gets the player's inventory. | 72 | * Gets the player's inventory. |
66 | * | 73 | * |
67 | * @return the player's inventory | 74 | * @return the player's inventory |
@@ -81,14 +88,14 @@ public class Player { | |||
81 | * @return the nbSteps | 88 | * @return the nbSteps |
82 | */ | 89 | */ |
83 | public int getNbSteps() { | 90 | public int getNbSteps() { |
84 | return nbSteps; | 91 | return this.nbSteps; |
85 | } | 92 | } |
86 | 93 | ||
87 | /** | 94 | /** |
88 | * @param nbSteps | 95 | * @param nbSteps |
89 | * the nbSteps to set | 96 | * the nbSteps to set |
90 | */ | 97 | */ |
91 | public void setNbSteps(int nbSteps) { | 98 | public void setNbSteps(final int nbSteps) { |
92 | this.nbSteps = nbSteps; | 99 | this.nbSteps = nbSteps; |
93 | } | 100 | } |
94 | 101 | ||
@@ -96,14 +103,14 @@ public class Player { | |||
96 | * @return the maxNbSteps | 103 | * @return the maxNbSteps |
97 | */ | 104 | */ |
98 | public int getMaxNbSteps() { | 105 | public int getMaxNbSteps() { |