diff options
Diffstat (limited to 'src/esieequest/model/doors/TransporterDoor.java')
-rw-r--r-- | src/esieequest/model/doors/TransporterDoor.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/esieequest/model/doors/TransporterDoor.java b/src/esieequest/model/doors/TransporterDoor.java new file mode 100644 index 0000000..27fbe1d --- /dev/null +++ b/src/esieequest/model/doors/TransporterDoor.java | |||
@@ -0,0 +1,54 @@ | |||
1 | package esieequest.model.doors; | ||
2 | |||
3 | import java.util.Random; | ||
4 | |||
5 | import esieequest.model.map.Room; | ||
6 | |||
7 | /** | ||
8 | * A door that transports the player in a random room. | ||
9 | * | ||
10 | * @author Pacien TRAN-GIRARD | ||
11 | */ | ||
12 | public class TransporterDoor extends Door { | ||
13 | |||
14 | private static Room destination; | ||
15 | |||
16 | private final Random randomGenerator; | ||
17 | private final Room[] possibleDestinations; | ||
18 | |||
19 | public TransporterDoor(final Room[] possibleDestinations) { | ||
20 | super(null); | ||
21 | |||
22 | this.randomGenerator = new Random(); | ||
23 | this.possibleDestinations = possibleDestinations; | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public Room getDestination() { | ||
28 | if (TransporterDoor.destination != null) { | ||
29 | return TransporterDoor.destination; | ||
30 | } | ||
31 | return this.findRandomRoom(); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * Takes a random Room in the possible destinations. | ||
36 | * | ||
37 | * @return a randomly chosen Room | ||
38 | */ | ||
39 | private Room findRandomRoom() { | ||
40 | final int randomIndex = this.randomGenerator.nextInt(this.possibleDestinations.length); | ||
41 | return this.possibleDestinations[randomIndex]; | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Overrides the random selection of the destination. | ||
46 | * | ||
47 | * @param destination | ||
48 | * the destination Room | ||
49 | */ | ||
50 | public static void forceDestination(final Room destination) { | ||
51 | TransporterDoor.destination = destination; | ||
52 | } | ||
53 | |||
54 | } | ||