aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-04-16 15:51:17 +0200
committerPacien TRAN-GIRARD2014-04-16 15:51:17 +0200
commitc5a7663453f6d67c2f4aa88a0e9756b6f24997d5 (patch)
tree3f873fc449087be4072f9de9c327bc68aae50b4c
parentba422a863c58fb034e917621d0cb27f09f06183b (diff)
downloadesieequest-c5a7663453f6d67c2f4aa88a0e9756b6f24997d5.tar.gz
Implement TransporterDoor
-rw-r--r--src/esieequest/model/Game.java8
-rw-r--r--src/esieequest/model/map/TransporterDoor.java30
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 @@
1package esieequest.model; 1package esieequest.model;
2 2
3import java.util.HashMap; 3import java.util.HashMap;
4import java.util.HashSet;
4 5
5import esieequest.model.entities.Player; 6import esieequest.model.entities.Player;
6import esieequest.model.items.Beamer; 7import esieequest.model.items.Beamer;
@@ -10,6 +11,7 @@ import esieequest.model.map.Door;
10import esieequest.model.map.HiddenDoor; 11import esieequest.model.map.HiddenDoor;
11import esieequest.model.map.LockedDoor; 12import esieequest.model.map.LockedDoor;
12import esieequest.model.map.Room; 13import esieequest.model.map.Room;
14import esieequest.model.map.TransporterDoor;
13import esieequest.model.map.TrapDoor; 15import 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 @@
1package esieequest.model.map;
2
3import java.util.Random;
4import java.util.Set;
5
6/**
7 * A door that transports the player in a random room.
8 *
9 * @author Pacien TRAN-GIRARD
10 */
11public 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}