aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/esieequest/controller/Performer.java13
-rw-r--r--src/esieequest/model/Game.java46
-rw-r--r--src/esieequest/model/items/Beamer.java4
-rw-r--r--src/esieequest/model/items/Inventory.java16
-rw-r--r--src/esieequest/model/items/Item.java8
-rw-r--r--src/esieequest/model/items/KeyCard.java14
-rw-r--r--src/esieequest/model/map/LockedDoor.java49
7 files changed, 136 insertions, 14 deletions
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
index add3fe5..de8d814 100644
--- a/src/esieequest/controller/Performer.java
+++ b/src/esieequest/controller/Performer.java
@@ -9,6 +9,7 @@ import esieequest.model.items.Beamer;
9import esieequest.model.items.Inventory; 9import esieequest.model.items.Inventory;
10import esieequest.model.items.Item; 10import esieequest.model.items.Item;
11import esieequest.model.map.Door; 11import esieequest.model.map.Door;
12import esieequest.model.map.LockedDoor;
12import esieequest.model.map.Room; 13import esieequest.model.map.Room;
13import esieequest.model.map.TrapDoor; 14import esieequest.model.map.TrapDoor;
14import esieequest.view.View; 15import esieequest.view.View;
@@ -115,6 +116,14 @@ class Performer {
115 this.echo(this.game.getNoExitMessage()); 116 this.echo(this.game.getNoExitMessage());
116 return; 117 return;
117 } 118 }
119 if (door.getClass() == LockedDoor.class) {
120 final LockedDoor lockedDoor = (LockedDoor) door;
121 final boolean authorised = this.game.getPlayer().getInventory().containsItem(lockedDoor.getKey());
122 if (!authorised) {
123 this.echo("This door is locked.");
124 return;
125 }
126 }
118 final Room nextRoom = door.getDestination(); 127 final Room nextRoom = door.getDestination();
119 this.game.getPlayer().goToRoom(nextRoom); 128 this.game.getPlayer().goToRoom(nextRoom);
120 this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); 129 this.view.updateRoom(this.game.getPlayer().getCurrentRoom());
@@ -155,7 +164,7 @@ class Performer {
155 * the item's name 164 * the item's name
156 */ 165 */
157 public void takeItem(final String itemName) { 166 public void takeItem(final String itemName) {
158 if (!this.game.getPlayer().getCurrentRoom().getItems().hasItem(itemName)) { 167 if (!this.game.getPlayer().getCurrentRoom().getItems().containsItem(itemName)) {
159 this.echo("No such item in this room."); 168 this.echo("No such item in this room.");
160 return; 169 return;
161 } 170 }
@@ -193,7 +202,7 @@ class Performer {
193 * the item's name 202 * the item's name
194 */ 203 */
195 private void moveItem(final Inventory source, final Inventory dest, final String itemName) { 204 private void moveItem(final Inventory source, final Inventory dest, final String itemName) {
196 if (!source.hasItem(itemName)) { 205 if (!source.containsItem(itemName)) {
197 this.echo("No such item."); 206 this.echo("No such item.");
198 return; 207 return;
199 } 208 }
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 6e6b191..0ff4b92 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -5,7 +5,9 @@ import java.util.HashMap;
5import esieequest.model.entities.Player; 5import esieequest.model.entities.Player;
6import esieequest.model.items.Beamer; 6import esieequest.model.items.Beamer;
7import esieequest.model.items.Item; 7import esieequest.model.items.Item;
8import esieequest.model.items.KeyCard;
8import esieequest.model.map.Door; 9import esieequest.model.map.Door;
10import esieequest.model.map.LockedDoor;
9import esieequest.model.map.Room; 11import esieequest.model.map.Room;
10import esieequest.model.map.TrapDoor; 12import esieequest.model.map.TrapDoor;
11 13
@@ -88,12 +90,22 @@ public class Game {
88 this.createRoom("WingCorridorTwoOffice", "in front of the office #3254"); 90 this.createRoom("WingCorridorTwoOffice", "in front of the office #3254");
89 this.createRoom("WingOffice", "in the office #3254"); 91 this.createRoom("WingOffice", "in the office #3254");
90 92
93 // off-script rooms
91 this.createRoom("OffscriptItems", "somewhere implementing weight"); 94 this.createRoom("OffscriptItems", "somewhere implementing weight");
92 this.createRoom("OffscriptItemsStorageroom", "in a storage room"); 95 this.createRoom("OffscriptItemsStorageroom", "in a storage room");
96
93 this.createRoom("OffscriptTeleportation", "somewhere implementing teleportation"); 97 this.createRoom("OffscriptTeleportation", "somewhere implementing teleportation");
94 this.createRoom("OffscriptTeleportationBeamerroom", "on a checkpoint"); 98 this.createRoom("OffscriptTeleportationBeamerroom", "on a checkpoint");
99
100 this.createRoom("OffscriptTrap", "somewhere implementing a trap");
101 this.createRoom("OffscriptTrapDeadend", "in a dead end");
102
103 this.createRoom("OffscriptLock", "somewhere implementing a lock");
104 this.createRoom("OffscriptLockLockedroom", "in a locked room");
105
95 this.createRoom("OffscriptAlea", "somewhere implementing alea"); 106 this.createRoom("OffscriptAlea", "somewhere implementing alea");
96 this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else"); 107 this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else");
108
97 this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); 109 this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character");
98 this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room"); 110 this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room");
99 } 111 }
@@ -167,15 +179,28 @@ public class Game {
167 this.setRoomExit("WingCorridorTwoOffice", "east", "WingOffice"); 179 this.setRoomExit("WingCorridorTwoOffice", "east", "WingOffice");
168 this.setRoomExit("WingOffice", "west", "WingCorridorTwoOffice"); 180 this.setRoomExit("WingOffice", "west", "WingCorridorTwoOffice");
169 181
170 this.rooms.get("WingCorridorOne").addExit("east", new TrapDoor(this.rooms.get("OffscriptItems"))); 182 this.rooms.get("WingCorridorOne").addExit("east", new Door(this.rooms.get("OffscriptItems")));
183 // this.rooms.get("WingCorridorOne").addExit("east", new
184 // TrapDoor(this.rooms.get("OffscriptItems")));
171 185
172 this.setRoomExit("OffscriptItems", "north", "OffscriptItemsStorageroom"); 186 this.setRoomExit("OffscriptItems", "north", "OffscriptItemsStorageroom");
173 this.setRoomExit("OffscriptItems", "east", "OffscriptTeleportation"); 187 this.setRoomExit("OffscriptItems", "east", "OffscriptTeleportation");
174 this.setRoomExit("OffscriptItemsStorageroom", "south", "OffscriptItems"); 188 this.setRoomExit("OffscriptItemsStorageroom", "south", "OffscriptItems");
175 this.setRoomExit("OffscriptTeleportation", "north", "OffscriptTeleportationBeamerroom"); 189 this.setRoomExit("OffscriptTeleportation", "north", "OffscriptTeleportationBeamerroom");
176 this.setRoomExit("OffscriptTeleportation", "west", "OffscriptItems"); 190 this.setRoomExit("OffscriptTeleportation", "west", "OffscriptItems");
177 this.setRoomExit("OffscriptTeleportation", "east", "OffscriptAlea"); 191 this.setRoomExit("OffscriptTeleportation", "east", "OffscriptTrap");
178 this.setRoomExit("OffscriptTeleportationBeamerroom", "south", "OffscriptTeleportation"); 192 this.setRoomExit("OffscriptTeleportationBeamerroom", "south", "OffscriptTeleportation");
193 // this.setRoomExit("OffscriptTrap", "north", "OffscriptTrapDeadend");
194 this.rooms.get("OffscriptTrap").addExit("north", new TrapDoor(this.rooms.get("OffscriptTrapDeadend")));
195 this.setRoomExit("OffscriptTrap", "west", "OffscriptTeleportation");
196 this.setRoomExit("OffscriptTrap", "east", "OffscriptLock");
197 // this.setRoomExit("OffscriptTrapDeadend", "south", "OffscriptTrap");
198 // this.setRoomExit("OffscriptLock", "north", "OffscriptLockedroom");
199 this.rooms.get("OffscriptLock").addExit("north", new LockedDoor(this.rooms.get("OffscriptLockLockedroom")));
200 this.setRoomExit("OffscriptLock", "west", "OffscriptTrap");
201 this.setRoomExit("OffscriptLock", "east", "OffscriptAlea");
202 // this.setRoomExit("OffscriptLockedroom", "south", "OffscriptLock");
203 this.rooms.get("OffscriptLockLockedroom").addExit("south", new LockedDoor(this.rooms.get("OffscriptLock")));
179 this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRandomizingroom"); 204 this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRandomizingroom");
180 this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation"); 205 this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation");
181 this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter"); 206 this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter");
@@ -189,11 +214,18 @@ public class Game {
189 * Creates and adds items into rooms. 214 * Creates and adds items into rooms.
190 */ 215 */
191 private void createItems() { 216 private void createItems() {
192 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Weighted Storage Cube", new Item("A Weighted Storage Cube.", 5)); 217 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Weighted Storage Cube", new Item("A Weighted Storage Cube.", 5, true));
193 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Edgeless Safety Cube", new Item("An Edgeless Safety Cube.", 5)); 218 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Edgeless Safety Cube", new Item("An Edgeless Safety Cube.", 5, true));
194 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Portable Black-hole", new Item("A portable black-hole that has a negative mass.", -10)); 219 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Portable Black-hole", new Item("A portable black-hole that has a negative mass.", -10, true));
195 220
196 this.rooms.get("OffscriptTeleportationBeamerroom").getItems().putItem("Portable Quantum Tunelling Device", new Beamer("Basically a teleporter.", 2)); 221 this.rooms.get("OffscriptTeleportationBeamerroom").getItems().putItem("Portable Quantum Tunelling Device", new Beamer("Basically a teleporter."));
222
223 final KeyCard keyCard = new KeyCard("A KeyCard that opens a locked door.");
224 final LockedDoor lockedDoorLock = (LockedDoor) this.rooms.get("OffscriptLock").getExit("north");
225 lockedDoorLock.setKey(keyCard);
226 final LockedDoor lockedDoorLockedRoom = (LockedDoor) this.rooms.get("OffscriptLockLockedroom").getExit("south");
227 lockedDoorLockedRoom.setKey(keyCard);
228 this.rooms.get("OffscriptLock").getItems().putItem("KeyCard", keyCard);
197 } 229 }
198 230
199 /** 231 /**
diff --git a/src/esieequest/model/items/Beamer.java b/src/esieequest/model/items/Beamer.java
index ba8f361..5618ea8 100644
--- a/src/esieequest/model/items/Beamer.java
+++ b/src/esieequest/model/items/Beamer.java
@@ -19,8 +19,8 @@ public class Beamer extends Item {
19 * @param description 19 * @param description
20 * @param weight 20 * @param weight
21 */ 21 */
22 public Beamer(final String description, final int weight) { 22 public Beamer(final String description) {
23 super(description, weight); 23 super(description, true);
24 } 24 }
25 25
26 /** 26 /**
diff --git a/src/esieequest/model/items/Inventory.java b/src/esieequest/model/items/Inventory.java
index 6de8f1d..94691ad 100644
--- a/src/esieequest/model/items/Inventory.java
+++ b/src/esieequest/model/items/Inventory.java
@@ -45,18 +45,30 @@ public class Inventory {
45 } 45 }
46 46
47 /** 47 /**
48 * Tells is an inventory contains a given item by its name. 48 * Tells if the inventory contains a given item by its name.
49 * 49 *
50 * @param itemName 50 * @param itemName
51 * the item's name 51 * the item's name
52 * 52 *
53 * @return the existence of the item 53 * @return the existence of the item
54 */ 54 */
55 public boolean hasItem(final String itemName) { 55 public boolean containsItem(final String itemName) {
56 return this.items.get(itemName) != null; 56 return this.items.get(itemName) != null;
57 } 57 }
58 58
59 /** 59 /**
60 * Tells if the inventory contains a given item.
61 *
62 * @param item
63 * the item
64 *
65 * @return the existence of the item
66 */