diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/esieequest/model/Game.java | 8 | ||||
-rw-r--r-- | src/esieequest/model/map/TransporterDoor.java | 30 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index d1607a9..68dc1c2 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package esieequest.model; | 1 | package esieequest.model; |
2 | 2 | ||
3 | import java.util.HashMap; | 3 | import java.util.HashMap; |
4 | import java.util.HashSet; | ||
4 | 5 | ||
5 | import esieequest.model.entities.Player; | 6 | import esieequest.model.entities.Player; |
6 | import esieequest.model.items.Beamer; | 7 | import esieequest.model.items.Beamer; |
@@ -10,6 +11,7 @@ import esieequest.model.map.Door; | |||
10 | import esieequest.model.map.HiddenDoor; | 11 | import esieequest.model.map.HiddenDoor; |
11 | import esieequest.model.map.LockedDoor; | 12 | import esieequest.model.map.LockedDoor; |
12 | import esieequest.model.map.Room; | 13 | import esieequest.model.map.Room; |
14 | import esieequest.model.map.TransporterDoor; | ||
13 | import esieequest.model.map.TrapDoor; | 15 | import esieequest.model.map.TrapDoor; |
14 | 16 | ||
15 | /** | 17 | /** |
@@ -105,7 +107,6 @@ public class Game { | |||
105 | this.createRoom("OffscriptLockLockedroom", "in a locked room"); | 107 | this.createRoom("OffscriptLockLockedroom", "in a locked room"); |
106 | 108 | ||
107 | this.createRoom("OffscriptAlea", "somewhere implementing alea"); | 109 | this.createRoom("OffscriptAlea", "somewhere implementing alea"); |
108 | this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else"); | ||
109 | 110 | ||
110 | this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); | 111 | this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); |
111 | this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room"); | 112 | this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room"); |
@@ -202,10 +203,11 @@ public class Game { | |||
202 | this.setRoomExit("OffscriptLock", "east", "OffscriptAlea"); | 203 | this.setRoomExit("OffscriptLock", "east", "OffscriptAlea"); |
203 | // this.setRoomExit("OffscriptLockedroom", "south", "OffscriptLock"); | 204 | // this.setRoomExit("OffscriptLockedroom", "south", "OffscriptLock"); |
204 | this.rooms.get("OffscriptLockLockedroom").addExit("south", new LockedDoor(this.rooms.get("OffscriptLock"))); | 205 | this.rooms.get("OffscriptLockLockedroom").addExit("south", new LockedDoor(this.rooms.get("OffscriptLock"))); |
205 | this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRandomizingroom"); | 206 | // this.setRoomExit("OffscriptAlea", "north", |
207 | // "OffscriptAleaRandomizingroom"); | ||
208 | this.rooms.get("OffscriptAlea").addExit("north", new TransporterDoor(new HashSet<Room>(this.rooms.values()))); | ||
206 | this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation"); | 209 | this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation"); |
207 | this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter"); | 210 | this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter"); |
208 | this.setRoomExit("OffscriptAleaRandomizingroom", "south", "OffscriptAlea"); | ||
209 | this.setRoomExit("OffscriptMovingcharacter", "north", "OffscriptMovingcharacterSumobotroom"); | 211 | this.setRoomExit("OffscriptMovingcharacter", "north", "OffscriptMovingcharacterSumobotroom"); |
210 | this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea"); | 212 | this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea"); |
211 | this.setRoomExit("OffscriptMovingcharacterSumobotroom", "south", "OffscriptMovingcharacter"); | 213 | this.setRoomExit("OffscriptMovingcharacterSumobotroom", "south", "OffscriptMovingcharacter"); |
diff --git a/src/esieequest/model/map/TransporterDoor.java b/src/esieequest/model/map/TransporterDoor.java new file mode 100644 index 0000000..8c5fc6e --- /dev/null +++ b/src/esieequest/model/map/TransporterDoor.java | |||
@@ -0,0 +1,30 @@ | |||
1 | package esieequest.model.map; | ||
2 | |||
3 | import java.util.Random; | ||
4 | import java.util.Set; | ||
5 | |||
6 | /** | ||
7 | * A door that transports the player in a random room. | ||
8 | * | ||
9 | * @author Pacien TRAN-GIRARD | ||
10 | */ | ||
11 | public class TransporterDoor extends Door { | ||
12 | |||
13 | private final Set<Room> possibleDestinations; | ||
14 | |||
15 | public TransporterDoor(final Set<Room> possibleDestinations) { | ||
16 | super(null); | ||
17 | this.possibleDestinations = possibleDestinations; | ||
18 | } | ||
19 | |||
20 | @Override | ||
21 | public Room getDestination() { | ||
22 | return this.findRandomRoom(); | ||
23 | } | ||
24 | |||
25 | private Room findRandomRoom() { | ||
26 | final int randomIndex = new Random().nextInt(this.possibleDestinations.size()); | ||
27 | return (Room) this.possibleDestinations.toArray()[randomIndex]; | ||
28 | } | ||
29 | |||
30 | } | ||