From 86d6f56dd14fdb94411a02679b9ad4bd556d8a32 Mon Sep 17 00:00:00 2001
From: Pacien TRAN-GIRARD
Date: Sat, 19 Apr 2014 14:41:30 +0200
Subject: Refactoring + implement Sides
---
.classpath | 2 +
lib/guava-16.0.1.jar | Bin 0 -> 2228009 bytes
lib/guava-gwt-16.0.1.jar | Bin 0 -> 837282 bytes
src/esieequest/Main.java | 6 +-
src/esieequest/controller/GameEngine.java | 33 +-
src/esieequest/controller/Input.java | 59 ++++
src/esieequest/controller/Interpreter.java | 110 -------
src/esieequest/controller/Parser.java | 46 ---
src/esieequest/controller/Performer.java | 320 --------------------
src/esieequest/controller/Utils.java | 55 ++--
.../controller/commands/AleaCommand.java | 39 +++
.../controller/commands/BackCommand.java | 21 ++
src/esieequest/controller/commands/Command.java | 100 +++++++
.../controller/commands/CommandInterface.java | 25 ++
src/esieequest/controller/commands/DoCommand.java | 35 +++
.../controller/commands/DropCommand.java | 41 +++
.../controller/commands/ForwardCommand.java | 24 ++
src/esieequest/controller/commands/GoCommand.java | 53 ++++
.../controller/commands/HelpCommand.java | 20 ++
.../controller/commands/InventoryCommand.java | 20 ++
.../controller/commands/LoadCommand.java | 19 ++
.../controller/commands/LookCommand.java | 29 ++
src/esieequest/controller/commands/NewCommand.java | 28 ++
.../controller/commands/QuitCommand.java | 22 ++
.../controller/commands/SaveCommand.java | 19 ++
.../controller/commands/SoundCommand.java | 19 ++
.../controller/commands/TakeCommand.java | 52 ++++
.../controller/commands/TalkCommand.java | 26 ++
.../controller/commands/TurnCommand.java | 37 +++
src/esieequest/controller/commands/UseCommand.java | 35 +++
.../controller/commands/package-info.java | 4 +
src/esieequest/esieequest.gwt.xml | 7 +-
src/esieequest/model/Game.java | 332 +++++++--------------
src/esieequest/model/Player.java | 288 ++++++++++++++++++
src/esieequest/model/Text.java | 96 ++++++
src/esieequest/model/characters/Character.java | 36 +++
.../model/characters/MovingCharacter.java | 133 +++++++++
src/esieequest/model/characters/Sumobot.java | 48 +++
src/esieequest/model/characters/package-info.java | 5 +
src/esieequest/model/commands/Command.java | 62 ----
src/esieequest/model/commands/CommandWord.java | 12 -
src/esieequest/model/commands/package-info.java | 5 -
src/esieequest/model/doors/Door.java | 60 ++++
src/esieequest/model/doors/HiddenDoor.java | 22 ++
src/esieequest/model/doors/LockedDoor.java | 71 +++++
src/esieequest/model/doors/TransporterDoor.java | 54 ++++
src/esieequest/model/doors/TrapDoor.java | 31 ++
src/esieequest/model/doors/package-info.java | 4 +
src/esieequest/model/entities/Character.java | 25 --
src/esieequest/model/entities/MovingCharacter.java | 33 --
src/esieequest/model/entities/Player.java | 125 --------
src/esieequest/model/entities/Sumobot.java | 32 --
src/esieequest/model/entities/package-info.java | 5 -
src/esieequest/model/items/Beamer.java | 30 +-
src/esieequest/model/items/Inventory.java | 125 --------
src/esieequest/model/items/Item.java | 28 +-
src/esieequest/model/map/Direction.java | 79 +++++
src/esieequest/model/map/Door.java | 41 ---
src/esieequest/model/map/HiddenDoor.java | 20 --
src/esieequest/model/map/LockedDoor.java | 55 ----
src/esieequest/model/map/Orientation.java | 17 ++
src/esieequest/model/map/Room.java | 279 ++++++++++++-----
src/esieequest/model/map/Side.java | 109 +++++++
src/esieequest/model/map/TransporterDoor.java | 36 ---
src/esieequest/model/map/TrapDoor.java | 21 --
src/esieequest/view/app/UserInterface.java | 25 +-
src/esieequest/view/text/TextInterface.java | 2 +
src/esieequest/view/web/WebInterface.java | 19 +-
68 files changed, 2218 insertions(+), 1453 deletions(-)
create mode 100644 lib/guava-16.0.1.jar
create mode 100644 lib/guava-gwt-16.0.1.jar
create mode 100644 src/esieequest/controller/Input.java
delete mode 100644 src/esieequest/controller/Interpreter.java
delete mode 100644 src/esieequest/controller/Parser.java
delete mode 100644 src/esieequest/controller/Performer.java
create mode 100644 src/esieequest/controller/commands/AleaCommand.java
create mode 100644 src/esieequest/controller/commands/BackCommand.java
create mode 100644 src/esieequest/controller/commands/Command.java
create mode 100644 src/esieequest/controller/commands/CommandInterface.java
create mode 100644 src/esieequest/controller/commands/DoCommand.java
create mode 100644 src/esieequest/controller/commands/DropCommand.java
create mode 100644 src/esieequest/controller/commands/ForwardCommand.java
create mode 100644 src/esieequest/controller/commands/GoCommand.java
create mode 100644 src/esieequest/controller/commands/HelpCommand.java
create mode 100644 src/esieequest/controller/commands/InventoryCommand.java
create mode 100644 src/esieequest/controller/commands/LoadCommand.java
create mode 100644 src/esieequest/controller/commands/LookCommand.java
create mode 100644 src/esieequest/controller/commands/NewCommand.java
create mode 100644 src/esieequest/controller/commands/QuitCommand.java
create mode 100644 src/esieequest/controller/commands/SaveCommand.java
create mode 100644 src/esieequest/controller/commands/SoundCommand.java
create mode 100644 src/esieequest/controller/commands/TakeCommand.java
create mode 100644 src/esieequest/controller/commands/TalkCommand.java
create mode 100644 src/esieequest/controller/commands/TurnCommand.java
create mode 100644 src/esieequest/controller/commands/UseCommand.java
create mode 100644 src/esieequest/controller/commands/package-info.java
create mode 100644 src/esieequest/model/Player.java
create mode 100644 src/esieequest/model/Text.java
create mode 100644 src/esieequest/model/characters/Character.java
create mode 100644 src/esieequest/model/characters/MovingCharacter.java
create mode 100644 src/esieequest/model/characters/Sumobot.java
create mode 100644 src/esieequest/model/characters/package-info.java
delete mode 100644 src/esieequest/model/commands/Command.java
delete mode 100644 src/esieequest/model/commands/CommandWord.java
delete mode 100644 src/esieequest/model/commands/package-info.java
create mode 100644 src/esieequest/model/doors/Door.java
create mode 100644 src/esieequest/model/doors/HiddenDoor.java
create mode 100644 src/esieequest/model/doors/LockedDoor.java
create mode 100644 src/esieequest/model/doors/TransporterDoor.java
create mode 100644 src/esieequest/model/doors/TrapDoor.java
create mode 100644 src/esieequest/model/doors/package-info.java
delete mode 100644 src/esieequest/model/entities/Character.java
delete mode 100644 src/esieequest/model/entities/MovingCharacter.java
delete mode 100644 src/esieequest/model/entities/Player.java
delete mode 100644 src/esieequest/model/entities/Sumobot.java
delete mode 100644 src/esieequest/model/entities/package-info.java
delete mode 100644 src/esieequest/model/items/Inventory.java
create mode 100644 src/esieequest/model/map/Direction.java
delete mode 100644 src/esieequest/model/map/Door.java
delete mode 100644 src/esieequest/model/map/HiddenDoor.java
delete mode 100644 src/esieequest/model/map/LockedDoor.java
create mode 100644 src/esieequest/model/map/Orientation.java
delete mode 100644 src/esieequest/model/map/TransporterDoor.java
delete mode 100644 src/esieequest/model/map/TrapDoor.java
diff --git a/.classpath b/.classpath
index 8836eed..9697427 100644
--- a/.classpath
+++ b/.classpath
@@ -4,5 +4,7 @@
+
+
diff --git a/lib/guava-16.0.1.jar b/lib/guava-16.0.1.jar
new file mode 100644
index 0000000..2c8127d
Binary files /dev/null and b/lib/guava-16.0.1.jar differ
diff --git a/lib/guava-gwt-16.0.1.jar b/lib/guava-gwt-16.0.1.jar
new file mode 100644
index 0000000..d49ada7
Binary files /dev/null and b/lib/guava-gwt-16.0.1.jar differ
diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java
index 362af9c..4759a6e 100755
--- a/src/esieequest/Main.java
+++ b/src/esieequest/Main.java
@@ -47,7 +47,7 @@ public class Main extends JApplet {
*/
public static void main(final String[] args) {
final List arguments = Arrays.asList(args);
- final Game game = new Game();
+ Game game;
View view;
if (arguments.contains("--file")) {
@@ -63,7 +63,9 @@ public class Main extends JApplet {
}
if (arguments.contains("--challenge")) {
- game.getPlayer().setMaxNbSteps(50);
+ game = new Game(50);
+ } else {
+ game = new Game();
}
new GameEngine(game, view);
diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java
index c09967b..df3d34a 100644
--- a/src/esieequest/controller/GameEngine.java
+++ b/src/esieequest/controller/GameEngine.java
@@ -1,6 +1,9 @@
package esieequest.controller;
+import esieequest.controller.commands.Command;
import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.characters.MovingCharacter;
import esieequest.view.View;
/**
@@ -14,8 +17,6 @@ public class GameEngine {
private final Game game;
private final View view;
- private final Interpreter interpreter;
-
/**
* Instantiates a game engine with the given model and view.
*
@@ -30,19 +31,35 @@ public class GameEngine {
this.view.setController(this);
- this.interpreter = new Interpreter(this.game, this.view);
-
this.view.show();
}
/**
- * Interprets a command (forward it to the interpreter).
+ * Interprets a command.
*
* @param commandString
- * the command string
+ * the command String
+ */
+ public void interpret(final String inputString) {
+ final Input input = new Input(inputString);
+
+ final Command command = input.getCommand();
+ if (command == null) {
+ this.view.echo(Text.UNKNOWN_COMMAND.getText());
+ return;
+ }
+
+ final String argument = input.getArgument();
+
+ this.executeRoutines();
+ command.execute(argument, this.game, this.view);
+ }
+
+ /**
+ * Actions executed every time a Command is entered.
*/
- public void interpret(final String command) {
- this.interpreter.interpret(command);
+ private void executeRoutines() {
+ MovingCharacter.moveAll();
}
}
diff --git a/src/esieequest/controller/Input.java b/src/esieequest/controller/Input.java
new file mode 100644
index 0000000..4b4ada5
--- /dev/null
+++ b/src/esieequest/controller/Input.java
@@ -0,0 +1,59 @@
+package esieequest.controller;
+
+import esieequest.controller.commands.Command;
+
+/**
+ * An user textual input.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class Input {
+
+ private Command command;
+ private final String argument;
+
+ /**
+ *
+ * @param command
+ * @param argument
+ */
+ public Input(final Command command, final String argument) {
+ this.command = command;
+ this.argument = argument;
+ }
+
+ /**
+ * Builds an Input from a textual input String.
+ *
+ * @param inputString
+ * the textual input String
+ */
+ public Input(final String inputString) {
+ final String[] elements = inputString.split(" ", 2);
+ try {
+ this.command = Command.valueOf(elements[0].toUpperCase());
+ } catch (final Exception exception) {
+ this.command = null;
+ }
+ if (elements.length >= 2) {
+ this.argument = elements[1];
+ } else {
+ this.argument = null;
+ }
+ }
+
+ /**
+ * @return the command
+ */
+ public Command getCommand() {
+ return this.command;
+ }
+
+ /**
+ * @return the argument
+ */
+ public String getArgument() {
+ return this.argument;
+ }
+
+}
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
deleted file mode 100644
index 1895099..0000000
--- a/src/esieequest/controller/Interpreter.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package esieequest.controller;
-
-import esieequest.model.Game;
-import esieequest.model.commands.Command;
-import esieequest.view.View;
-
-/**
- * The command interpreter.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoît LUBRANO DI SBARAGLIONE
- */
-class Interpreter {
-
- private final Performer performer;
- private final Parser parser;
-
- /**
- * Instantiates the Interpreter.
- *
- * @param game
- * the Game model
- * @param view
- * the View
- */
- public Interpreter(final Game game, final View view) {
- this.performer = new Performer(game, view);
- this.parser = new Parser();
- }
-
- /**
- * Interprets a command.
- *
- * @param commandString
- * the command String
- */
- public void interpret(final String commandString) {
- final Command command = this.parser.getCommand(commandString);
- this.dispatch(command);
- }
-
- /**
- * Dispatches to the method associated with the command's action.
- *
- * @param command
- * the command
- */
- public void dispatch(final Command command) {
- if (command.getAction() != null) {
- switch (command.getAction()) {
-
- // game related:
- case NEW:
- this.performer.newGame();
- return;
- case LOAD:
- this.performer.loadGame();
- return;
- case SAVE:
- this.performer.saveGame();
- return;
- case QUIT:
- this.performer.quitGame();
- return;
- case SOUND:
- this.performer.toggleSound();
- return;
- case HELP:
- this.performer.showHelp();
- return;
-
- // map related:
- case GO:
- this.performer.goTo(command.getOption());
- return;
- case BACK:
- this.performer.goBack();
- return;
- case LOOK:
- this.performer.look();
- return;
- case ALEA:
- this.performer.forceAlea(command.getOption());
- return;
-
- // items related:
- case INVENTORY:
- this.performer.listItems();
- return;
- case TAKE:
- this.performer.takeItem(command.getOption());
- return;
- case DROP:
- this.performer.dropItem(command.getOption());
- return;
- case USE:
- this.performer.useItem(command.getOption());
- return;
-
- // characters related
- case TALK:
- this.performer.talk(command.getOption());
- return;
-
- }
- }
- this.performer.echo("Unknown command.");
- return;
- }
-}
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java
deleted file mode 100644
index d13f940..0000000
--- a/src/esieequest/controller/Parser.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package esieequest.controller;
-
-import esieequest.model.commands.Command;
-import esieequest.model.commands.CommandWord;
-
-/**
- * The command parser.
- *
- * @author Pacien TRAN-GIRARD
- */
-class Parser {
-
- /**
- * The default constructor.
- */
- public Parser() {
- }
-
- /**
- * Creates a command from a String.
- *
- * @param commandString
- * the command as a String
- *
- * @return the command
- */
- public Command getCommand(final String commandString) {
- final String[] elements = commandString.split(" ", 2);
-
- CommandWord action = null;
- String option = null;
-
- try {
- action = CommandWord.valueOf(elements[0].toUpperCase());
- } catch (final Exception e) {
- action = CommandWord.UNKNOWN;
- } finally {
- if (elements.length > 1) {
- option = elements[1];
- }
- }
-
- return new Command(action, option);
- }
-
-}
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
deleted file mode 100644
index 6526ef7..0000000
--- a/src/esieequest/controller/Performer.java
+++ /dev/null
@@ -1,320 +0,0 @@
-package esieequest.controller;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Random;
-import java.util.Set;
-
-import esieequest.model.Game;
-import esieequest.model.commands.CommandWord;
-import esieequest.model.entities.Character;
-import esieequest.model.entities.MovingCharacter;
-import esieequest.model.items.Beamer;
-import esieequest.model.items.Inventory;
-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;
-
-/**
- * Performs actions and modifies the Game model.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoît LUBRANO DI SBARAGLIONE
- */
-class Performer {
-
- private final Game game;
- private final View view;
-
- /**
- * Instantiates a Performer.
- *
- * @param game
- * the Game model
- * @param view
- * the view
- */
- public Performer(final Game game, final View view) {
- this.game = game;
- this.view = view;
- }
-
- /**
- * Displays the message "Not implemented." in the view.
- */
- private void notImplemented() {
- this.echo("Not implemented.");
- }
-
- /**
- * Displays a message in the view.
- *
- * @param message
- * the message
- */
- public void echo(final String message) {
- this.view.echo(message);
- }
-
- /**
- * Loads a new game.
- */
- public void newGame() {
- // this.loadGame(default game);
- // TODO
- this.view.enable();
- this.echo(this.game.getWelcomeMessage());
- }
-
- /**
- * Loads a saved game.
- */
- public void loadGame() {
- // TODO
- this.notImplemented();
- }
-
- /**
- * Saves the current game.
- */
- public void saveGame() {
- // TODO
- this.notImplemented();
- }
-
- /**
- * Toggles the sound.
- */
- public void toggleSound() {
- // TODO
- this.notImplemented();
- }
-
- /**
- * Ends the current game.
- */
- public void quitGame() {
- this.echo(this.game.getQuitMessage());
- this.view.disable();
- }
-
- /**
- * Displays the help message and the available commands.
- */
- public void showHelp() {
- final Set commands = new HashSet();
- for (final CommandWord command : CommandWord.values()) {
- commands.add(command.name().toLowerCase());
- }
- this.echo(Utils.list(commands, "Commands:", "No commands."));
- }
-
- /**
- * Changes the current room to the one placed in the given direction.
- *
- * @param direction
- * the direction of the new room
- */
- public void goTo(final String direction) {
- final Door door = this.game.getPlayer().getCurrentRoom().getExit(direction);
- if (door == null) {
- this.echo(this.game.getNoExitMessage());
- return;
- }
- if (door.getClass() == LockedDoor.class) {
- final LockedDoor lockedDoor = (LockedDoor) door;
- final boolean authorised = this.game.getPlayer().getInventory().containsItem(lockedDoor.getKey());
- if (!authorised) {
- this.echo("This door is locked.");
- return;
- }
- }
- final Room nextRoom = door.getDestination();
- this.game.getPlayer().goToRoom(nextRoom);
- this.view.updateRoom(this.game.getPlayer().getCurrentRoom());
- this.walk();
- if (door.getClass() == TrapDoor.class) {
- this.game.getPlayer().clearRoomHistory();
- }
- }
-
- /**
- * Changes the current room to the previous one.
- */
- public void goBack() {
- this.game.getPlayer().goToPreviousRoom();
- this.view.updateRoom(this.game.getPlayer().getCurrentRoom());
- this.walk();
- }
-
- /**
- * Increments and checks the number of steps made by the player.
- */
- private void walk() {
- this.game.getPlayer().setNbSteps(this.game.getPlayer().getNbSteps() + 1);
- if (this.game.getPlayer().getNbSteps() == this.game.getPlayer().getMaxNbSteps()) {
- this.echo("You died of exhaustion...");
- this.quitGame();
- }
-
- this.moveMovingCharacters();
- }
-
- /**
- * Moves all MovingCharacters that can to adjacent rooms.
- */
- private void moveMovingCharacters() {
- final HashMap movingCharactersPositions = new HashMap();
- final Collection rooms = this.game.getRooms().values();
- for (final Room room : rooms) {
- if (room.getCharacter() == null) {
- continue;
- }
- if (room.getCharacter() instanceof MovingCharacter) {
- if (!((MovingCharacter) room.getCharacter()).canMove()) {
- continue;
- }
- final int randomIndex = new Random().nextInt(room.getExits().values().size());
- final Room destinationRoom = ((Door) room.getExits().values().toArray()[randomIndex]).getDestination();
- movingCharactersPositions.put(room, destinationRoom);
- }
- }
-
- for (final Room source : movingCharactersPositions.keySet()) {
- this.swapCharacters(source, movingCharactersPositions.get(source));
- }
- }
-
- /**
- * Swaps the characters in the given rooms.
- *
- * @param source
- * @param destination
- */
- private void swapCharacters(final Room source, final Room destination) {
- final Character characterS = source.getCharacter();
- final Character characterD = destination.getCharacter();
- destination.setCharacter(characterS);
- source.setCharacter(characterD);
- }
-
- /**
- * Displays informations about the current place.
- */
- public void look() {
- this.echo(this.game.getPlayer().getCurrentRoom().getInformations());
- }
-
- /**
- * Moves an item from the current Room to the Player's inventory.
- *
- * @param itemName
- * the item's name
- */
- public void takeItem(final String itemName) {
- if (!this.game.getPlayer().getCurrentRoom().getItems().containsItem(itemName)) {
- this.echo("No such item in this room.");
- return;
- }
-
- int weight = this.game.getPlayer().getInventory().getTotalWeight();
- weight += this.game.getPlayer().getCurrentRoom().getItems().getItemWeight(itemName);
- final int maxWeight = this.game.getPlayer().getMaxCarryWeight();
-
- if (weight > maxWeight) {
- this.echo("Maximum inventory weight reached. Cannot pick up item.");
- return;
- }
-
- this.moveItem(this.game.getPlayer().getCurrentRoom().getItems(), this.game.getPlayer().getInventory(), itemName);
- }
-
- /**
- * Moves an item from the Player's inventory to the current Room.
- *
- * @param itemName
- * the item's name
- */
- public void dropItem(final String itemName) {
- if (!this.game.getPlayer().getInventory().getItem(itemName).isDroppable()) {
- this.echo("This item cannot be dropped.");
- return;
- }
- this.moveItem(this.game.getPlayer().getInventory(), this.game.getPlayer().getCurrentRoom().getItems(), itemName);
- }
-
- /**
- * Moves a given item referred by its name from an inventory to another.
- *
- * @param source
- * the source inventory
- * @param dest
- * the destination inventory
- * @param itemName
- * the item's name
- */
- private void moveItem(final Inventory source, final Inventory dest, final String itemName) {
- if (!source.containsItem(itemName)) {
- this.echo("No such item.");
- return;
- }
- dest.putItem(itemName, source.takeItem(itemName));
- }
-
- /**
- * Lists the items contained in the player's inventory.
- */
- public void listItems() {
- this.echo(Utils.list(this.game.getPlayer().getInventory().getItemList(), "Items:", "No item in your inventory."));
- }
-
- /**
- * Performs an action according to the use of an item.
- *
- * @param itemName
- * the item's name
- */
- public void useItem(final String itemName) {
- final Item item = this.game.getPlayer().getInventory().getItem(itemName);
- if (item == null) {
- this.echo("You don't have such item.");
- return;
- }
- if (item.getClass() == Beamer.class) {
- final Beamer beamer = (Beamer) item;
- if (beamer.getRoom() == null) {
- beamer.setRoom(this.game.getPlayer().getCurrentRoom());
- } else {
- this.game.getPlayer().goToRoom(beamer.getRoom());
- }
- }
- }
-
- 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);
- }
- }
- }
- }
-
- public void talk(final String message) {
- this.echo(this.game.getPlayer().getCurrentRoom().getCharacter().talk());
- }
-
-}
diff --git a/src/esieequest/controller/Utils.java b/src/esieequest/controller/Utils.java
index 139798c..d45f58c 100644
--- a/src/esieequest/controller/Utils.java
+++ b/src/esieequest/controller/Utils.java
@@ -1,40 +1,43 @@
package esieequest.controller;
-import java.util.Set;
+import java.util.List;
+import com.google.common.base.Joiner;
+
+import esieequest.model.Text;
+
+/**
+ * A set of custom utility methods.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
public class Utils {
/**
+ * Converts a List into a String with a given prefix, suffix and
+ * placeholder used if the List is empty.
*
- * @param elements
- * the elements
+ * @param list
+ * the List to convert
* @param prefix
- * the prefix of the list
- * @param emptyText
- * the text that will be returned if the Set is empty
- * @return the list
+ * the prefix
+ * @param empty
+ * the placeholder
+ * @param suffix
+ * the suffix
+ * @return the converted String
*/
- public static String list(final Set elements, final String prefix, final String emptyText) {
- if (!elements.isEmpty()) {
- return prefix + Utils.buildListString(elements) + ".";
- }
- return emptyText;
- }
+ public static String listToString(final List list, final String prefix, final String empty, final String suffix) {
+ final StringBuilder str = new StringBuilder(prefix);
- /**
- * Builds a list in the form of a String from a given Set.
- *
- * @param elements
- * the Set of Strings
- *
- * @return the list
- */
- private static String buildListString(final Set elements) {
- final StringBuilder list = new StringBuilder();
- for (final String string : elements) {
- list.append(" ").append(string);
+ if (list.isEmpty()) {
+ str.append(empty);
+ } else {
+ str.append(Joiner.on(Text.LIST_SEPARATOR.getText()).join(list));
}
- return list.toString();
+ str.append(suffix);
+
+ return str.toString();
}
}
diff --git a/src/esieequest/controller/commands/AleaCommand.java b/src/esieequest/controller/commands/AleaCommand.java
new file mode 100644
index 0000000..2a5f5c4
--- /dev/null
+++ b/src/esieequest/controller/commands/AleaCommand.java
@@ -0,0 +1,39 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.doors.TransporterDoor;
+import esieequest.model.map.Room;
+import esieequest.view.View;
+
+/**
+ * Provides a way to override the random behaviour of TransporterDoor-s for
+ * testing purposes.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class AleaCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final String forcedRoomName = argument;
+ Room destinationRoom = null;
+
+ if (forcedRoomName != null) {
+ try {
+ destinationRoom = Room.valueOf(forcedRoomName.toUpperCase());
+ } catch (final Exception exception) {
+ view.echo(Text.NO_SUCH_ROOM.getText());
+ return;
+ }
+ view.echo(Text.ALEA_OVERRIDE_ENABLED.getText());
+ } else {
+ view.echo(Text.ALEA_OVERRIDE_DISABLED.getText());
+ }
+
+ TransporterDoor.forceDestination(destinationRoom);
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java
new file mode 100644
index 0000000..8919540
--- /dev/null
+++ b/src/esieequest/controller/commands/BackCommand.java
@@ -0,0 +1,21 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * Allows the user to go back on his steps and go to his previous location.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class BackCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ game.getPlayer().goToPreviousRoom();
+ view.updateRoom(game.getPlayer().getCurrentRoom());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java
new file mode 100644
index 0000000..9b032f7
--- /dev/null
+++ b/src/esieequest/controller/commands/Command.java
@@ -0,0 +1,100 @@
+package esieequest.controller.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import esieequest.controller.Utils;
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.view.View;
+
+/**
+ * The Command-s the user can use.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public enum Command {
+
+ // @formatter:off
+
+ // game related
+ NEW(new NewCommand()),
+ LOAD(new LoadCommand()),
+ SAVE(new SaveCommand()),
+ QUIT(new QuitCommand()),
+ SOUND(new SoundCommand()),
+ HELP(new HelpCommand()),
+ ALEA(new AleaCommand()),
+
+ // map related
+ GO(new GoCommand()),
+ FORWARD(new ForwardCommand()),
+ BACK(new BackCommand()),
+ TURN(new TurnCommand()),
+ LOOK(new LookCommand()),
+
+ // items related
+ DROP(new DropCommand()),
+ INVENTORY(new InventoryCommand()),
+ TAKE(new TakeCommand()),
+ USE(new UseCommand()),
+
+ // characters related
+ TALK(new TalkCommand()),
+
+ // shortcuts
+ DO(new DoCommand());
+
+ // @formatter:on
+
+ private CommandInterface command;
+
+ /**
+ * Links an enum constant to a CommandInterface.
+ *
+ * @param command
+ * the CommandInterface
+ */
+ Command(final CommandInterface command) {
+ this.command = command;
+ }
+
+ /**
+ * Executes the CommandInterface's execute() method.
+ *
+ * @param argument
+ * the argument String to pass
+ * @param game
+ * the Game model
+ * @param view
+ * the View
+ */
+ public void execute(final String argument, final Game game, final View view) {
+ this.command.execute(argument, game, view);
+ }
+
+ /**
+ * Lists all the Command-s names
+ *
+ * @return the list of all the names of the Command-s
+ */
+ public static List listCommandsNames() {
+ final ArrayList commandsList = new ArrayList();
+
+ for (final Command command : Command.values()) {
+ commandsList.add(command.name().toLowerCase());
+ }
+
+ return commandsList;
+ }
+
+ /**
+ * Lists all the Command-s names in a String
+ *
+ * @return a String listing all the names of the Command-s
+ */
+ public static String listCommandsNamesString() {
+ return Utils.listToString(Command.listCommandsNames(), Text.HELP_PREFIX.getText(), null, Text.HELP_SUFFIX.getText());
+ }
+
+}
diff --git a/src/esieequest/controller/commands/CommandInterface.java b/src/esieequest/controller/commands/CommandInterface.java
new file mode 100644
index 0000000..e3a26f9
--- /dev/null
+++ b/src/esieequest/controller/commands/CommandInterface.java
@@ -0,0 +1,25 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * The Command interface.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public interface CommandInterface {
+
+ /**
+ * Performs the task corresponding to the Command.
+ *
+ * @param argument
+ * the argument to pass to the Command
+ * @param game
+ * the Game model
+ * @param view
+ * the View
+ */
+ public void execute(String argument, Game game, View view);
+
+}
diff --git a/src/esieequest/controller/commands/DoCommand.java b/src/esieequest/controller/commands/DoCommand.java
new file mode 100644
index 0000000..e99c67d
--- /dev/null
+++ b/src/esieequest/controller/commands/DoCommand.java
@@ -0,0 +1,35 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.map.Side;
+import esieequest.view.View;
+
+/**
+ * A shortcut Command that executes a TALK or a TAKE Command accordingly to the
+ * context.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class DoCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final Side currentSide = game.getPlayer().getCurrentSide();
+
+ if (currentSide.hasCharacter()) {
+ Command.TALK.execute(argument, game, view);
+ return;
+ }
+
+ if (currentSide.hasItem()) {
+ Command.TAKE.execute(argument, game, view);
+ return;
+ }
+
+ view.echo(Text.NOTHING_TO_DO.getText());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java
new file mode 100644
index 0000000..3685c21
--- /dev/null
+++ b/src/esieequest/controller/commands/DropCommand.java
@@ -0,0 +1,41 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.items.Item;
+import esieequest.view.View;
+
+/**
+ * Allows the user to drop an Item from his inventory (referred by its name) to
+ * the current Room Side.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class DropCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final String itemName = argument;
+
+ if (itemName == null) {
+ view.echo(Text.NO_ITEM_SPECIFIED.getText());
+ return;
+ }
+
+ if (!game.getPlayer().hasItem(itemName)) {
+ view.echo(Text.NO_SUCH_ITEM.getText());
+ return;
+ }
+
+ if (game.getPlayer().getCurrentSide().hasItem()) {
+ view.echo(Text.ROOM_INVENTORY_FULL.getText());
+ return;
+ }
+
+ final Item item = game.getPlayer().takeItem(itemName);
+ game.getPlayer().getCurrentSide().putItem(item);
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/ForwardCommand.java b/src/esieequest/controller/commands/ForwardCommand.java
new file mode 100644
index 0000000..f15a4e2
--- /dev/null
+++ b/src/esieequest/controller/commands/ForwardCommand.java
@@ -0,0 +1,24 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.map.Direction;
+import esieequest.view.View;
+
+/**
+ * Allows the user to move forward in the Map (in the Room at the Direction he
+ * is facing).
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class ForwardCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final Direction direction = game.getPlayer().getCurrentDirection();
+
+ Command.GO.execute(direction.name(), game, view);
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java
new file mode 100644
index 0000000..06260b2
--- /dev/null
+++ b/src/esieequest/controller/commands/GoCommand.java
@@ -0,0 +1,53 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.doors.Door;
+import esieequest.model.map.Direction;
+import esieequest.view.View;
+
+/**
+ * Allows the user to move from connected Room-s to Room-s by giving the
+ * Direction.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class GoCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final Direction direction;
+
+ try {
+ direction = Direction.valueOf(argument.toUpperCase());
+ } catch (final Exception exception) {
+ view.echo(Text.NO_SUCH_DIRECTION.getText());
+ return;
+ }
+
+ final Door door = game.getPlayer().getCurrentRoom().getSide(direction).getDoor();
+
+ if (door == null) {
+ view.echo(Text.NO_DOOR.getText());
+ return;
+ }
+
+ final boolean crossed = door.cross(game, view);
+
+ if (!crossed) {
+ return;
+ }
+
+ view.updateRoom(game.getPlayer().getCurrentRoom());
+
+ // handle challenge mode
+ game.getPlayer().setNbSteps(game.getPlayer().getNbSteps() + 1);
+ if (game.getPlayer().getNbSteps() == game.getPlayer().getNbStepsLimit()) {
+ view.echo(Text.CHALLENGE_FAILED.getText());
+ view.disable();
+ }
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/HelpCommand.java b/src/esieequest/controller/commands/HelpCommand.java
new file mode 100644
index 0000000..37b99e4
--- /dev/null
+++ b/src/esieequest/controller/commands/HelpCommand.java
@@ -0,0 +1,20 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * Prints the available commands.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class HelpCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ view.echo(Command.listCommandsNamesString());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/InventoryCommand.java b/src/esieequest/controller/commands/InventoryCommand.java
new file mode 100644
index 0000000..da37e07
--- /dev/null
+++ b/src/esieequest/controller/commands/InventoryCommand.java
@@ -0,0 +1,20 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * Prints the list of the items in the Player's inventory.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class InventoryCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ view.echo(game.getPlayer().listItemsNamesString());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/LoadCommand.java b/src/esieequest/controller/commands/LoadCommand.java
new file mode 100644
index 0000000..4a3972b
--- /dev/null
+++ b/src/esieequest/controller/commands/LoadCommand.java
@@ -0,0 +1,19 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * Loads a saved Game.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class LoadCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/LookCommand.java b/src/esieequest/controller/commands/LookCommand.java
new file mode 100644
index 0000000..d053b25
--- /dev/null
+++ b/src/esieequest/controller/commands/LookCommand.java
@@ -0,0 +1,29 @@
+package esieequest.controller.commands;
+
+import java.util.ArrayList;
+
+import com.google.common.base.Joiner;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.view.View;
+
+/**
+ * Prints informations about the current location.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class LookCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final ArrayList informations = new ArrayList();
+
+ informations.add(game.getPlayer().getCurrentRoom().getInformations());
+ informations.add(Text.DIRECTION_PREFIX + game.getPlayer().getCurrentDirection().name().toLowerCase() + Text.DIRECTION_SUFFIX);
+
+ view.echo(Joiner.on(Text.NEW_LINE.getText()).join(informations));
+
+ }
+}
diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java
new file mode 100644
index 0000000..b49d36b
--- /dev/null
+++ b/src/esieequest/controller/commands/NewCommand.java
@@ -0,0 +1,28 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.map.Direction;
+import esieequest.model.map.Room;
+import esieequest.view.View;
+
+/**
+ * Creates a new game.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class NewCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ // TODO: load a new game
+ game.getPlayer().setCurrentDirection(Direction.NORTH);
+ game.getPlayer().setCurrentRoom(Room.AMPHITHEATER_SEAT);
+
+ view.enable();
+ view.echo(Text.WELCOME.getText());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/QuitCommand.java b/src/esieequest/controller/commands/QuitCommand.java
new file mode 100644
index 0000000..739bf93
--- /dev/null
+++ b/src/esieequest/controller/commands/QuitCommand.java
@@ -0,0 +1,22 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.view.View;
+
+/**
+ * Allows the user to quit the game.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class QuitCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ view.echo(Text.QUIT.getText());
+ view.disable();
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/SaveCommand.java b/src/esieequest/controller/commands/SaveCommand.java
new file mode 100644
index 0000000..44e83c0
--- /dev/null
+++ b/src/esieequest/controller/commands/SaveCommand.java
@@ -0,0 +1,19 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * Saves the current Game.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class SaveCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/SoundCommand.java b/src/esieequest/controller/commands/SoundCommand.java
new file mode 100644
index 0000000..d375173
--- /dev/null
+++ b/src/esieequest/controller/commands/SoundCommand.java
@@ -0,0 +1,19 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * Allows the user to enable or disable the game's sounds.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class SoundCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java
new file mode 100644
index 0000000..97eb8b7
--- /dev/null
+++ b/src/esieequest/controller/commands/TakeCommand.java
@@ -0,0 +1,52 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.items.Item;
+import esieequest.model.map.Room;
+import esieequest.model.map.Side;
+import esieequest.view.View;
+
+/**
+ * Allows the player to take an Item from a Room and transfer it to his
+ * inventory.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class TakeCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ Item item;
+ if (argument != null) {
+ final String itemName = argument;
+ final Room currentRoom = game.getPlayer().getCurrentRoom();
+ if (!currentRoom.hasItem(itemName)) {
+ view.echo(Text.NO_SUCH_ITEM.getText());
+ return;
+ }
+ item = currentRoom.getItem(itemName);
+ } else {
+ final Side currentSide = game.getPlayer().getCurrentSide();
+ if (!currentSide.hasItem()) {
+ view.echo(Text.NO_ITEM.getText());
+ return;
+ }
+ item = currentSide.getItem();
+ }
+
+ // handle inventory weight limit
+ final int maximumWeight = game.getPlayer().getCarryWeightLimit();
+ final int futureWeight = game.getPlayer().getItemsWeight() + item.getWeight();
+ if (futureWeight > maximumWeight) {
+ view.echo(Text.INVENTORY_FULL.getText());
+ return;
+ }
+
+ game.getPlayer().getCurrentRoom().removeItem(item);
+ game.getPlayer().addItem(item);
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/TalkCommand.java b/src/esieequest/controller/commands/TalkCommand.java
new file mode 100644
index 0000000..1637870
--- /dev/null
+++ b/src/esieequest/controller/commands/TalkCommand.java
@@ -0,0 +1,26 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.view.View;
+
+/**
+ * Allows the Player to TALK to a Character.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class TalkCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ if (!game.getPlayer().getCurrentSide().hasCharacter()) {
+ view.echo(Text.NO_CHARACTER.getText());
+ return;
+ }
+
+ view.echo(game.getPlayer().getCurrentSide().getCharacter().talk());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java
new file mode 100644
index 0000000..e451263
--- /dev/null
+++ b/src/esieequest/controller/commands/TurnCommand.java
@@ -0,0 +1,37 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.map.Direction;
+import esieequest.model.map.Orientation;
+import esieequest.view.View;
+
+/**
+ * Allows the user to turn on himself, that is to say to point to another
+ * Direction.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class TurnCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ Orientation orientation;
+
+ try {
+ orientation = Orientation.valueOf(argument.toUpperCase());
+ } catch (final Exception exception) {
+ view.echo(Text.NO_SUCH_DIRECTION.getText());
+ return;
+ }
+
+ final Direction currentDirection = game.getPlayer().getCurrentDirection();
+ final Direction newDirection = currentDirection.rotate(orientation);
+ game.getPlayer().setCurrentDirection(newDirection);
+
+ view.updateSide(game.getPlayer().getCurrentSide());
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java
new file mode 100644
index 0000000..d8b8416
--- /dev/null
+++ b/src/esieequest/controller/commands/UseCommand.java
@@ -0,0 +1,35 @@
+package esieequest.controller.commands;
+
+import esieequest.model.Game;
+import esieequest.model.Text;
+import esieequest.model.items.Item;
+import esieequest.view.View;
+
+/**
+ * Allows the player to use an item located in his inventory.
+ *
+ * @author Pacien TRAN-GIRARD
+ */
+public class UseCommand implements CommandInterface {
+
+ @Override
+ public void execute(final String argument, final Game game, final View view) {
+
+ final String itemName = argument;
+
+ if (itemName == null) {
+ view.echo(Text.NO_ITEM_SPECIFIED.getText());
+ return;
+ }
+
+ if (!game.getPlayer().hasItem(itemName)) {
+ view.echo(Text.NO_SUCH_ITEM.getText());
+ return;
+ }
+
+ final Item item = game.getPlayer().getItem(itemName);
+ item.use(game, view);
+
+ }
+
+}
diff --git a/src/esieequest/controller/commands/package-info.java b/src/esieequest/controller/commands/package-info.java
new file mode 100644
index 0000000..f53942a
--- /dev/null
+++ b/src/esieequest/controller/commands/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * The commands package. Contains Commands executed by the user to perform actions in the Game.
+ */
+package esieequest.controller.commands;
\ No newline at end of file
diff --git a/src/esieequest/esieequest.gwt.xml b/src/esieequest/esieequest.gwt.xml
index b97b0a2..1a5c10c 100644
--- a/src/esieequest/esieequest.gwt.xml
+++ b/src/esieequest/esieequest.gwt.xml
@@ -1,10 +1,10 @@
+"http://google-web-toolkit.googlecode.com/svn/tags/2.6.0/distro-source/core/src/gwt-module.dtd">
@@ -18,6 +18,7 @@
+
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 87d3d51..830b48c 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -1,284 +1,174 @@
package esieequest.model;
-import java.util.HashMap;
-import java.util.HashSet;
-
-import esieequest.model.entities.Player;
-import esieequest.model.entities.Sumobot;
+import esieequest.model.characters.Character;
+import esieequest.model.characters.Sumobot;
+import esieequest.model.doors.Door;
+import esieequest.model.doors.HiddenDoor;
+import esieequest.model.doors.LockedDoor;
+import esieequest.model.doors.TransporterDoor;
+import esieequest.model.doors.TrapDoor;
import esieequest.model.items.Beamer;
import esieequest.model.items.Item;
import esieequest.model.items.KeyCard;
-import esieequest.model.map.Door;
-import esieequest.model.map.HiddenDoor;
-import esieequest.model.map.LockedDoor;
+import esieequest.model.map.Direction;
import esieequest.model.map.Room;
-import esieequest.model.map.TransporterDoor;
-import esieequest.model.map.TrapDoor;
/**
- * Represents the game.
+ * The Game model.
*
* @author Pacien TRAN-GIRARD
- * @author Benoît LUBRANO DI SBARAGLIONE
*/
public class Game {
- private final HashMap rooms;
-
private final Player player;
/**
- * The default constructor.
+ * Creates a Game with a step limit for the Player.
+ *
+ * @param maxNbSteps
+ * the step limit for the Player
*/
- public Game() {
- this.rooms = new HashMap();
-
- this.player = new Player(10);
-
- this.createRooms();
- this.linkRooms();
- this.createItems();
- this.createCharacters();
- this.goToRoom("AmphitheaterSeat");
+ public Game(final int maxNbSteps) {
+ this.player = new Player(10, maxNbSteps);
+ this.connectRooms();
+ this.addItems();
+ this.addCharacters();
}
/**
- * Returns the player
- *
- * @return the player
+ * Creates a Game.
*/
- public Player getPlayer() {
- return this.player;
+ public Game() {
+ this(0);
}
/**
- * Creates a new room.
- *
- * @param name
- * the name of the room
- * @param description
- * the description of the room
+ * @return the player
*/
- private void createRoom(final String name, final String description) {
- this.rooms.put(name, new Room(description));
+ public Player getPlayer() {
+ return this.player;
}
/**
- * Creates all the rooms.
+ * Connects Room-s together using Door-s.
*/
- private void createRooms() {
- this.createRoom("AmphitheaterSeat", "in the amphitheater");
- this.createRoom("AmphitheaterStage", "on the amphitheater stage");
-
- this.createRoom("CafeteriaStreet", "in the main corridor, in front of the cafeteria");
- this.createRoom("Cafeteria", "at the cafeteria");
-
- this.createRoom("EsieespaceStreet", "in the main corridor, in front of the ESIEEspace HQ");
- this.createRoom("EsieespaceFront", "in front of the ESIEEspace HQ");
- this.createRoom("EsieespaceEntrance", "at the ESIEEspace HQ entrance");
- this.createRoom("Esieespace", "in the ESIEEspace HQ");
-
- this.createRoom("ClubnixStreet", "in the main corridor, in front of the Club*Nix");
- this.createRoom("ClubnixFront", "in front of the Club*Nix");
- this.createRoom("ClubnixEntrance", "at the Club*Nix entrance");
- this.createRoom("Clubnix", "in the Club*Nix");
-
- this.createRoom("EntranceStreet", "in the main corridor, at the reception");
- this.createRoom("EntranceStairs", "on the main entrance stairs");
- this.createRoom("EntranceRoundabout", "on the roundabout");
-
- this.createRoom("WingStreet", "in font of wing #3");
- this.createRoom("WingCorridorOne", "in the corridor in wing #3, on the ground floor");
- this.createRoom("WingStairsOne", "in the stairwell on the ground floor");
- this.createRoom("WingStairsTwo", "in the stairwell on the first floor");
- this.createRoom("WingCorridorTwo", "in the corridor in wing #3, on the first floor");
- this.createRoom("WingCorridorTwoOffice", "in front of the office #3254");
- this.createRoom("WingOffice", "in the office #3254");
-
- // off-script rooms
- this.createRoom("Secret corridor 1", "in a secret corridor");
- this.createRoom("Secret corridor 2", "at the end of a secret corridor");
- this.createRoom("Storage room", "in a storage room");
- this.createRoom("Secret lab", "in a secret lab");
- this.createRoom("Dead-end", "in a dead end");
- this.createRoom("Locked room", "in a locked room");
-
+ private void connectRooms() {
+ this.d(Room.AMPHITHEATER_SEAT, Direction.NORTH, Room.AMPHITHEATER_STAGE);
+ this.d(Room.AMPHITHEATER_STAGE, Direction.WEST, Room.CAFETERIA);
+ this.d(Room.CAFETERIA, Direction.NORTH, Room.CAFETERIA_STREET);
+ this.d(Room.CAFETERIA_STREET, Direction.EAST, Room.ESIEESPACE_STREET);
+
+ this.d(Room.ESIEESPACE_STREET, Direction.SOUTH, Room.ESIEESPACE_FRONT);
+ this.d(Room.ESIEESPACE_FRONT, Direction.EAST, Room.ESIEESPACE_ENTRANCE);
+ this.d(Room.ESIEESPACE_ENTRANCE, Direction.NORTH, Room.ESIEESPACE);
+
+ this.d(Room.ESIEESPACE_STREET, Direction.EAST, Room.ENTRANCE_STREET);
+ this.d(Room.ENTRANCE_STREET, Direction.SOUTH, Room.ENTRANCE_STAIRS);
+ this.d(Room.ENTRANCE_STAIRS, Direction.SOUTH, Room.ENTRANCE_ROUNDABOUT);
+
+ this.d(Room.ENTRANCE_STREET, Direction.EAST, Room.WING_STREET);
+ this.d(Room.WING_STREET, Direction.NORTH, Room.WING_FLOOR_ONE);
+ this.d(Room.WING_FLOOR_ONE, Direction.WEST, Room.WING_STAIRS_ONE);
+ this.d(Room.WING_STAIRS_ONE, Direction.SOUTH, Room.WING_STAIRS_TWO);
+ this.d(Room.WING_STAIRS_ONE, Direction.UP, Room.WING_STAIRS_TWO);
+ this.d(Room.WING_STAIRS_TWO, Direction.EAST, Room.WING_FLOOR_TWO);
+ this.d(Room.WING_FLOOR_TWO, Direction.NORTH, Room.WING_OFFICE_CORRIDOR);
+ this.d(Room.WING_OFFICE_CORRIDOR, Direction.EAST, Room.WING_OFFICE);
+
+ this.d(Room.WING_STREET, Direction.EAST, Room.CLUBNIX_STREET);
+ this.d(Room.CLUBNIX_STREET, Direction.SOUTH, Room.CLUBNIX_FRONT);
+ this.d(Room.CLUBNIX_FRONT, Direction.EAST, Room.CLUBNIX_ENTRANCE);
+ this.d(Room.CLUBNIX_ENTRANCE, Direction.NORTH, Room.CLUBNIX);
+
+ this.d(Room.WING_FLOOR_ONE, Direction.EAST, new HiddenDoor(Room.SECRET_CORRIDOR_ENTRANCE));
+ this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.WEST, new Door(Room.WING_FLOOR_ONE));
+ this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.NORTH, Room.STORAGE_ROOM);
+ this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.SOUTH, Room.SECRET_LAB);
+ this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.EAST, Room.SECRET_CORRIDOR_END);
+ this.d(Room.SECRET_CORRIDOR_END, Direction.NORTH, new TrapDoor(Room.DEAD_END));
+ this.d(Room.SECRET_CORRIDOR_END, Direction.SOUTH, new LockedDoor(Room.LOCKED_ROOM));
+ this.d(Room.LOCKED_ROOM, Direction.NORTH, new LockedDoor(Room.SECRET_CORRIDOR_END));
+ this.d(Room.SECRET_CORRIDOR_END, Direction.EAST, new TransporterDoor(Room.values()));
}
/**
- * Sets the exit room of a given room designated by its name.
+ * Adds two Door that connect two Room-s in both ways.
*
- * @param roomName
- * the name of the room
+ * @param source
+ * the source Room
* @param direction
- * the direction of the exit
- * @param exitRoomName
- * the name of the exit room
+ * the direction of the Door, seen from the source Room
+ * @param destination
+ * the destination Room
*/
- private void setRoomExit(final String roomName, final String direction, final String exitRoomName) {
- final Room room = this.rooms.get(exitRoomName);
- final Door door = new Door(room);
- this.rooms.get(roomName).addExit(direction, door);
+ private void d(final Room source, final Direction direction, final Room destination) {
+ source.getSide(direction).setDoor(new Door(destination));
+ destination.getSide(direction.getOpposite()).setDoor(new Door(source));
}
/**
- * Connects all the rooms.
- */
- private void linkRooms() {
- this.setRoomExit("AmphitheaterSeat", "north", "AmphitheaterStage");
- this.setRoomExit("AmphitheaterStage", "west", "Cafeteria");
-
- this.setRoomExit("CafeteriaStreet", "south", "Cafeteria");
- this.setRoomExit("CafeteriaStreet", "east", "EsieespaceStreet");
- this.setRoomExit("Cafeteria", "north", "CafeteriaStreet");
- this.setRoomExit("Cafeteria", "east", "AmphitheaterStage");
-
- this.setRoomExit("EsieespaceStreet", "west", "Cafeteria");
- this.setRoomExit("EsieespaceStreet", "south", "EsieespaceFront");
- this.setRoomExit("EsieespaceStreet", "east", "EntranceStreet");
- this.setRoomExit("EsieespaceFront", "north", "EsieespaceStreet");
- this.setRoomExit("EsieespaceFront", "east", "EsieespaceEntrance");
- this.setRoomExit("EsieespaceEntrance", "north", "Esieespace");
- this.setRoomExit("EsieespaceEntrance", "west", "EsieespaceFront");
- this.setRoomExit("Esieespace", "south", "EsieespaceEntrance");
-
- this.setRoomExit("ClubnixStreet", "west", "WingStreet");
- this.setRoomExit("ClubnixStreet", "south", "ClubnixFront");
- this.setRoomExit("ClubnixFront", "north", "ClubnixStreet");
- this.setRoomExit("ClubnixFront", "east", "ClubnixEntrance");
- this.setRoomExit("ClubnixEntrance", "north", "Clubnix");
- this.setRoomExit("ClubnixEntrance", "west", "ClubnixFront");
- this.setRoomExit("Clubnix", "south", "ClubnixEntrance");
-
- this.setRoomExit("EntranceStreet", "west", "EsieespaceStreet");
- this.setRoomExit("EntranceStreet", "south", "EntranceStairs");
- this.setRoomExit("EntranceStreet", "east", "WingStreet");
- this.setRoomExit("EntranceStairs", "north", "EntranceStreet");
- this.setRoomExit("EntranceStairs", "south", "EntranceRoundabout");
- this.setRoomExit("EntranceRoundabout", "north", "EntranceStairs");
-
- this.setRoomExit("WingStreet", "north", "WingCorridorOne");
- this.setRoomExit("WingStreet", "west", "EntranceStreet");
- this.setRoomExit("WingStreet", "east", "ClubnixStreet");
- this.setRoomExit("WingCorridorOne", "west", "WingStairsOne");
- this.setRoomExit("WingCorridorOne", "south", "WingStreet");
- this.setRoomExit("WingStairsOne", "south", "WingStairsTwo");
- this.setRoomExit("WingStairsOne", "up", "WingStairsTwo");
- this.setRoomExit("WingStairsOne", "east", "WingCorridorOne");
- this.setRoomExit("WingStairsTwo", "south", "WingStairsOne");
- this.setRoomExit("WingStairsTwo", "down", "WingStairsOne");
- this.setRoomExit("WingStairsTwo", "east", "WingCorridorTwo");
- this.setRoomExit("WingCorridorTwo", "north", "WingCorridorTwoOffice");
- this.setRoomExit("WingCorridorTwo", "west", "WingStairsTwo");
- this.setRoomExit("WingCorridorTwoOffice", "south", "WingCorridorTwo");
- this.setRoomExit("WingCorridorTwoOffice", "east", "WingOffice");
- this.setRoomExit("WingOffice", "west", "WingCorridorTwoOffice");
- this.rooms.get("WingCorridorOne").addExit("east", new HiddenDoor(this.rooms.get("Secret corridor 1")));
-
- this.setRoomExit("Secret corridor 1", "west", "WingCorridorOne");
- this.setRoomExit("Secret corridor 1", "east", "Secret corridor 2");
- this.setRoomExit("Secret corridor 2", "west", "Secret corridor 1");
-
- this.setRoomExit("Secret corridor 1", "north", "Storage room");
- this.setRoomExit("Storage room", "south", "Secret corridor 1");
- this.setRoomExit("Secret corridor 1", "south", "Secret lab");
- this.setRoomExit("Secret lab", "north", "Secret corridor 1");
-
- this.rooms.get("Secret corridor 2").addExit("north", new TrapDoor(this.rooms.get("Dead-end")));
- this.rooms.get("Secret corridor 2").addExit("south", new LockedDoor(this.rooms.get("Locked room")));
- this.rooms.get("Locked room").addExit("north", new LockedDoor(this.rooms.get("Secret corridor 2")));
- this.rooms.get("Secret corridor 2").addExit("east", new TransporterDoor(new HashSet(this.rooms.values())));
- }
-
- /**
- * Creates and adds items into rooms.
- */
- private void createItems() {
- this.rooms.get("Storage room").getItems().putItem("Weighted Storage Cube", new Item("A Weighted Storage Cube.", 5, true));
- this.rooms.get("Storage room").getItems().putItem("Edgeless Safety Cube", new Item("An Edgeless Safety Cube.", 5, true));
- this.rooms.get("Storage room").getItems().putItem("Portable Black-hole", new Item("A portable black-hole that has a negative mass.", -10, false));
-
- this.rooms.get("Secret lab").getItems().putItem("Portable Quantum Tunneling Device", new Beamer("Basically a teleporter."));
-
- final KeyCard keyCard = new KeyCard("A KeyCard that opens a locked door.");
- ((LockedDoor) this.rooms.get("Secret corridor 2").getExit("south")).setKey(keyCard);
- ((LockedDoor) this.rooms.get("Locked room").getExit("north")).setKey(keyCard);
- this.rooms.get("Dead-end").getItems().putItem("KeyCard", keyCard);
- }
-
- private void createCharacters() {
- this.rooms.get("Locked room").setCharacter(new Sumobot());
- }
-
- /**
- * Sets the current room designated by its name.
+ * Adds a Door to a Room.
*
- * @param roomName
- * the destination room name
+ * @param room
+ * the source Room
+ * @param direction
+ * the Direction of the Door in the given Room
+ * @param door
+ * the Door
*/
- public void goToRoom(final String roomName) {
- this.player.goToRoom(this.rooms.get(roomName));
+ private void d(final Room room, final Direction direction, final Door door) {
+ room.getSide(direction).setDoor(door);
}
/**
- * Returns the "eat" message.
- *
- * @return the "eat message
+ * Adds Item-s in the map.
*/
- public String getEatMessage() {
- return "oNommNommNomm...";
- }
+ private void addItems() {
+ this.i(Room.STORAGE_ROOM, Direction.WEST, new Item("Weighted Storage Cube", 5, true));
+ this.i(Room.STORAGE_ROOM, Direction.EAST, new Item("Edgeless Safety Cube", 5, true));
+ this.i(Room.STORAGE_ROOM, Direction.NORTH, new Item("Portable black-hole", -10, false));
- /**
- * Returns the welcome message.
- *
- * @return the welcome message
- */
- public String getWelcomeMessage() {
- return "Welcome to ESIEEquest! ESIEEquest is a new, amazingly boring adventure game.";
- }
+ this.i(Room.SECRET_LAB, Direction.SOUTH, new Beamer("Beamer"));
- /**
- * Returns the help message.
- *
- * @return the help message
- */
- public String getHelpMessage() {
- return "Everybody else disappeared. You are alone. You wander around at the ESIEE.";
+ KeyCard keyCard = new KeyCard("KeyCard");
+ this.i(Room.DEAD_END, Direction.NORTH, keyCard);
+ ((LockedDoor) Room.SECRET_CORRIDOR_END.getSide(Direction.SOUTH).getDoor()).setKey(keyCard);
+ ((LockedDoor) Room.LOCKED_ROOM.getSide(Direction.NORTH).getDoor()).setKey(keyCard);
}
/**
- * Returns the quit message.
+ * Adds a given Item in a Room with a Direction.
*
- * @return the quit message
+ * @param room
+ * the Room
+ * @param direction
+ * the Direction
+ * @param item
+ * the Item
*/
- public String getQuitMessage() {
- return "Thank you for wasting your time. Good bye.";
+ private void i(final Room room, final Direction direction, final Item item) {
+ room.getSide(direction).setItem(item);
}
/**
- * Returns the "no exit" message.
- *
- * @return the "no exit" message
+ * Adds Character-s to the map.
*/
- public String getNoExitMessage() {
- return "There is no exit.";
+ private void addCharacters() {
+ this.c(Room.LOCKED_ROOM, Direction.SOUTH, new Sumobot(Room.LOCKED_ROOM, Direction.SOUTH));
}
/**
- * Returns the command list prefix.
+ * Adds a Character in a Room with a Direction.
*
- * @return the command list prefix
- */
- public String getCommandListPrefix() {
- ret