aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/esieequest/model/Game.java26
-rw-r--r--src/esieequest/model/doors/LockedDoor.java16
-rw-r--r--src/esieequest/model/items/Beamer.java2
-rw-r--r--src/esieequest/model/items/Item.java51
-rw-r--r--src/esieequest/model/items/KeyCard.java20
-rw-r--r--src/esieequest/model/items/SimpleItem.java86
-rw-r--r--src/esieequest/view/Viewable.java4
-rw-r--r--src/esieequest/view/app/UserInterface.java4
-rw-r--r--src/esieequest/view/text/TextInterface.java4
-rw-r--r--src/esieequest/view/web/WebInterface.java4
10 files changed, 138 insertions, 79 deletions
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 830b48c..6267d1a 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -7,9 +7,7 @@ import esieequest.model.doors.HiddenDoor;
7import esieequest.model.doors.LockedDoor; 7import esieequest.model.doors.LockedDoor;
8import esieequest.model.doors.TransporterDoor; 8import esieequest.model.doors.TransporterDoor;
9import esieequest.model.doors.TrapDoor; 9import esieequest.model.doors.TrapDoor;
10import esieequest.model.items.Beamer;
11import esieequest.model.items.Item; 10import esieequest.model.items.Item;
12import esieequest.model.items.KeyCard;
13import esieequest.model.map.Direction; 11import esieequest.model.map.Direction;
14import esieequest.model.map.Room; 12import esieequest.model.map.Room;
15 13
@@ -86,8 +84,15 @@ public class Game {
86 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.SOUTH, Room.SECRET_LAB); 84 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.SOUTH, Room.SECRET_LAB);
87 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.EAST, Room.SECRET_CORRIDOR_END); 85 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.EAST, Room.SECRET_CORRIDOR_END);
88 this.d(Room.SECRET_CORRIDOR_END, Direction.NORTH, new TrapDoor(Room.DEAD_END)); 86 this.d(Room.SECRET_CORRIDOR_END, Direction.NORTH, new TrapDoor(Room.DEAD_END));
89 this.d(Room.SECRET_CORRIDOR_END, Direction.SOUTH, new LockedDoor(Room.LOCKED_ROOM)); 87
90 this.d(Room.LOCKED_ROOM, Direction.NORTH, new LockedDoor(Room.SECRET_CORRIDOR_END)); 88 final LockedDoor lockedDoorEnter = new LockedDoor(Room.LOCKED_ROOM);
89 lockedDoorEnter.setKey(Item.KEYCARD);
90 this.d(Room.SECRET_CORRIDOR_END, Direction.SOUTH, lockedDoorEnter);
91
92 final LockedDoor lockedDoorExit = new LockedDoor(Room.SECRET_CORRIDOR_END);
93 lockedDoorExit.setKey(Item.KEYCARD);
94 this.d(Room.LOCKED_ROOM, Direction.NORTH, lockedDoorExit);
95
91 this.d(Room.SECRET_CORRIDOR_END, Direction.EAST, new TransporterDoor(Room.values())); 96 this.d(Room.SECRET_CORRIDOR_END, Direction.EAST, new TransporterDoor(Room.values()));
92 } 97 }
93 98
@@ -124,16 +129,13 @@ public class Game {
124 * Adds Item-s in the map. 129 * Adds Item-s in the map.
125 */ 130 */
126 private void addItems() { 131 private void addItems() {
127 this.i(Room.STORAGE_ROOM, Direction.WEST, new Item("Weighted Storage Cube", 5, true)); 132 this.i(Room.STORAGE_ROOM, Direction.WEST, Item.STORAGE_CUBE);
128 this.i(Room.STORAGE_ROOM, Direction.EAST, new Item("Edgeless Safety Cube", 5, true)); 133 this.i(Room.STORAGE_ROOM, Direction.EAST, Item.SAFETY_CUBE);
129 this.i(Room.STORAGE_ROOM, Direction.NORTH, new Item("Portable black-hole", -10, false)); 134 this.i(Room.STORAGE_ROOM, Direction.NORTH, Item.BLACK_HOLE);
130 135
131 this.i(Room.SECRET_LAB, Direction.SOUTH, new Beamer("Beamer")); 136 this.i(Room.SECRET_LAB, Direction.SOUTH, Item.BEAMER);
132 137
133 KeyCard keyCard = new KeyCard("KeyCard"); 138 this.i(Room.DEAD_END, Direction.NORTH, Item.KEYCARD);
134 this.i(Room.DEAD_END, Direction.NORTH, keyCard);
135 ((LockedDoor) Room.SECRET_CORRIDOR_END.getSide(Direction.SOUTH).getDoor()).setKey(keyCard);
136 ((LockedDoor) Room.LOCKED_ROOM.getSide(Direction.NORTH).getDoor()).setKey(keyCard);
137 } 139 }
138 140
139 /** 141 /**
diff --git a/src/esieequest/model/doors/LockedDoor.java b/src/esieequest/model/doors/LockedDoor.java
index 28c535e..49f61be 100644
--- a/src/esieequest/model/doors/LockedDoor.java
+++ b/src/esieequest/model/doors/LockedDoor.java
@@ -3,7 +3,7 @@ package esieequest.model.doors;
3import esieequest.model.Game; 3import esieequest.model.Game;
4import esieequest.model.Player; 4import esieequest.model.Player;
5import esieequest.model.Text; 5import esieequest.model.Text;
6import esieequest.model.items.KeyCard; 6import esieequest.model.items.Item;
7import esieequest.model.map.Room; 7import esieequest.model.map.Room;
8import esieequest.view.Viewable; 8import esieequest.view.Viewable;
9 9
@@ -15,7 +15,7 @@ import esieequest.view.Viewable;
15 */ 15 */
16public class LockedDoor extends Door { 16public class LockedDoor extends Door {
17 17
18 private KeyCard keyCard; 18 private Item key;
19 19
20 /** 20 /**
21 * Creates a new locked door. 21 * Creates a new locked door.
@@ -32,18 +32,18 @@ public class LockedDoor extends Door {
32 * 32 *
33 * @return the KeyCard 33 * @return the KeyCard
34 */ 34 */
35 public KeyCard getKey() { 35 public Item getKey() {
36 return this.keyCard; 36 return this.key;
37 } 37 }
38 38
39 /** 39 /**
40 * Sets the KeyCard authorised to open this door. 40 * Sets the KeyCard authorised to open this door.
41 * 41 *
42 * @param keyCard 42 * @param key
43 * the KeyCard to set 43 * the KeyCard to set
44 */ 44 */
45 public void setKey(final KeyCard keyCard) { 45 public void setKey(final Item key) {
46 this.keyCard = keyCard; 46 this.key = key;
47 } 47 }
48 48
49 @Override 49 @Override
@@ -65,7 +65,7 @@ public class LockedDoor extends Door {
65 * @return if the Player is authorised to pass 65 * @return if the Player is authorised to pass
66 */ 66 */
67 private boolean isAuthorised(final Player player) { 67 private boolean isAuthorised(final Player player) {
68 return player.hasItem(this.keyCard); 68 return player.hasItem(this.key);
69 } 69 }
70 70
71} 71}
diff --git a/src/esieequest/model/items/Beamer.java b/src/esieequest/model/items/Beamer.java
index 61bef94..3a4ade9 100644
--- a/src/esieequest/model/items/Beamer.java
+++ b/src/esieequest/model/items/Beamer.java
@@ -12,7 +12,7 @@ import esieequest.view.Viewable;
12 * 12 *
13 * @author Pacien TRAN-GIRARD 13 * @author Pacien TRAN-GIRARD
14 */ 14 */
15public class Beamer extends Item { 15public class Beamer extends SimpleItem {
16 16
17 private Room room; 17 private Room room;
18 18
diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java
index c6f872f..2a0aa2c 100644
--- a/src/esieequest/model/items/Item.java
+++ b/src/esieequest/model/items/Item.java
@@ -1,37 +1,28 @@
1package esieequest.model.items; 1package esieequest.model.items;
2 2
3import esieequest.model.Game; 3import esieequest.model.Game;
4import esieequest.model.Text;
5import esieequest.view.Viewable; 4import esieequest.view.Viewable;
6 5
7/** 6public enum Item {
8 * Represents an item with a description and a weight, stored in a room. Can be
9 * picked, used and dropped.
10 *
11 * @author Pacien TRAN-GIRARD
12 */
13public class Item {
14 7
15 private final String name; 8 // @formatter:off
16 private final int weight; 9
17 private final boolean droppable; 10 STORAGE_CUBE(new SimpleItem("Weighted Storage Cube", 5, true)),
11 SAFETY_CUBE(new SimpleItem("Edgeless Safety Cube", 5, true)),
12 BLACK_HOLE(new SimpleItem("Portable black-hole", -10, false)),
13
14 KEYCARD(new SimpleItem("KeyCard", 0, false)),
18 15
19 /** 16 BEAMER(new Beamer("Beamer")),
20 * Creates an item with the given characteristics. 17
21 * 18 ;
22 * @param name 19
23 * the description of the item 20 // @formatter:on
24 * @param weight 21
25 * the weight of the item 22 private final SimpleItem item;
26 */
27 public Item(final String name, final int weight, final boolean droppable) {
28 this.name = name;
29 this.weight = weight;
30 this.droppable = droppable;
31 }
32 23
33 public Item(final String description, final boolean droppable) { 24 Item(final SimpleItem item) {
34 this(description, 0, droppable); 25 this.item = item;
35 } 26 }
36 27
37 /** 28 /**
@@ -40,7 +31,7 @@ public class Item {
40 * @return the description 31 * @return the description
41 */ 32 */
42 public String getName() { 33 public String getName() {
43 return this.name; 34 return this.item.getName();
44 } 35 }
45 36
46 /** 37 /**
@@ -49,7 +40,7 @@ public class Item {
49 * @return the weight 40 * @return the weight
50 */ 41 */
51 public int getWeight() { 42 public int getWeight() {
52 return this.weight; 43 return this.item.getWeight();
53 } 44 }
54 45