From c99590be11ab4bd5e5f7aaf02d8e0bc03df105fb Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 16 Apr 2014 19:09:43 +0200 Subject: Implement alea override --- src/esieequest/controller/Interpreter.java | 3 +++ src/esieequest/controller/Performer.java | 18 ++++++++++++++++++ src/esieequest/model/Game.java | 7 +++++++ src/esieequest/model/commands/CommandWord.java | 2 +- src/esieequest/model/map/Door.java | 12 +++++++++++- src/esieequest/model/map/Room.java | 7 +++++++ src/esieequest/model/map/TransporterDoor.java | 3 +++ 7 files changed, 50 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index e09ad91..5f9dafa 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java @@ -79,6 +79,9 @@ class Interpreter { case LOOK: this.performer.look(); return; + case ALEA: + this.performer.forceAlea(command.getOption()); + return; // items related: case INVENTORY: diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 59a3973..17d2cd8 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java @@ -11,6 +11,7 @@ import esieequest.model.items.Item; import esieequest.model.map.Door; import esieequest.model.map.LockedDoor; import esieequest.model.map.Room; +import esieequest.model.map.TransporterDoor; import esieequest.model.map.TrapDoor; import esieequest.view.View; @@ -249,4 +250,21 @@ class Performer { } } + public void forceAlea(final String forcedRoomName) { + Room destinationRoom = null; + if (forcedRoomName != null) { + destinationRoom = this.game.getRooms().get(forcedRoomName); + if (destinationRoom == null) { + this.echo("No such room."); + return; + } + } + for (final Room room : this.game.getRooms().values()) { + for (final Door exit : room.getExits().values()) { + if (exit.getClass() == TransporterDoor.class) { + ((TransporterDoor) exit).setDestination(destinationRoom); + } + } + } + } } diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index e5e3b56..17fad02 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java @@ -268,4 +268,11 @@ public class Game { return "Available commands:"; } + /** + * @return the rooms + */ + public HashMap getRooms() { + return this.rooms; + } + } diff --git a/src/esieequest/model/commands/CommandWord.java b/src/esieequest/model/commands/CommandWord.java index 555fe15..7162b7a 100644 --- a/src/esieequest/model/commands/CommandWord.java +++ b/src/esieequest/model/commands/CommandWord.java @@ -7,6 +7,6 @@ package esieequest.model.commands; */ public enum CommandWord { - NEW, LOAD, SAVE, SOUND, HELP, QUIT, LOOK, FORWARD, BACK, GO, TURN, DO, TAKE, DROP, TALK, INVENTORY, USE, UNKNOWN; + NEW, LOAD, SAVE, SOUND, HELP, QUIT, LOOK, FORWARD, BACK, GO, TURN, DO, TAKE, DROP, TALK, INVENTORY, USE, ALEA, UNKNOWN; } diff --git a/src/esieequest/model/map/Door.java b/src/esieequest/model/map/Door.java index 122b529..dfa0551 100644 --- a/src/esieequest/model/map/Door.java +++ b/src/esieequest/model/map/Door.java @@ -7,7 +7,7 @@ package esieequest.model.map; */ public class Door { - private final Room destination; + private Room destination; /** * Creates a new Door. @@ -28,4 +28,14 @@ public class Door { return this.destination; } + /** + * Sets the destination room. + * + * @param destination + * the destination room + */ + public void setDestination(final Room destination) { + this.destination = destination; + } + } diff --git a/src/esieequest/model/map/Room.java b/src/esieequest/model/map/Room.java index 421e781..3e606d7 100644 --- a/src/esieequest/model/map/Room.java +++ b/src/esieequest/model/map/Room.java @@ -115,4 +115,11 @@ public class Room { return this.items; } + /** + * @return the exits + */ + public HashMap getExits() { + return this.exits; + } + } diff --git a/src/esieequest/model/map/TransporterDoor.java b/src/esieequest/model/map/TransporterDoor.java index 8c5fc6e..47fb6c2 100644 --- a/src/esieequest/model/map/TransporterDoor.java +++ b/src/esieequest/model/map/TransporterDoor.java @@ -19,6 +19,9 @@ public class TransporterDoor extends Door { @Override public Room getDestination() { + if (super.getDestination() != null) { + return super.getDestination(); + } return this.findRandomRoom(); } -- cgit v1.2.3