From c5a7663453f6d67c2f4aa88a0e9756b6f24997d5 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 16 Apr 2014 15:51:17 +0200 Subject: Implement TransporterDoor --- src/esieequest/model/Game.java | 8 ++++--- src/esieequest/model/map/TransporterDoor.java | 30 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/esieequest/model/map/TransporterDoor.java (limited to 'src') 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 @@ package esieequest.model; import java.util.HashMap; +import java.util.HashSet; import esieequest.model.entities.Player; import esieequest.model.items.Beamer; @@ -10,6 +11,7 @@ import esieequest.model.map.Door; import esieequest.model.map.HiddenDoor; import esieequest.model.map.LockedDoor; import esieequest.model.map.Room; +import esieequest.model.map.TransporterDoor; import esieequest.model.map.TrapDoor; /** @@ -105,7 +107,6 @@ public class Game { this.createRoom("OffscriptLockLockedroom", "in a locked room"); this.createRoom("OffscriptAlea", "somewhere implementing alea"); - this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else"); this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); this.createRoom("OffscriptMovingcharacterSumobotroom", "in the Chirac-101's room"); @@ -202,10 +203,11 @@ public class Game { this.setRoomExit("OffscriptLock", "east", "OffscriptAlea"); // this.setRoomExit("OffscriptLockedroom", "south", "OffscriptLock"); this.rooms.get("OffscriptLockLockedroom").addExit("south", new LockedDoor(this.rooms.get("OffscriptLock"))); - this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRandomizingroom"); + // this.setRoomExit("OffscriptAlea", "north", + // "OffscriptAleaRandomizingroom"); + this.rooms.get("OffscriptAlea").addExit("north", new TransporterDoor(new HashSet(this.rooms.values()))); this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation"); this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter"); - this.setRoomExit("OffscriptAleaRandomizingroom", "south", "OffscriptAlea"); this.setRoomExit("OffscriptMovingcharacter", "north", "OffscriptMovingcharacterSumobotroom"); this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea"); 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 @@ +package esieequest.model.map; + +import java.util.Random; +import java.util.Set; + +/** + * A door that transports the player in a random room. + * + * @author Pacien TRAN-GIRARD + */ +public class TransporterDoor extends Door { + + private final Set possibleDestinations; + + public TransporterDoor(final Set possibleDestinations) { + super(null); + this.possibleDestinations = possibleDestinations; + } + + @Override + public Room getDestination() { + return this.findRandomRoom(); + } + + private Room findRandomRoom() { + final int randomIndex = new Random().nextInt(this.possibleDestinations.size()); + return (Room) this.possibleDestinations.toArray()[randomIndex]; + } + +} -- cgit v1.2.3