From 1f4c3072310613facdbe318098762e79a1ed6970 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Thu, 29 May 2014 01:21:28 +0200 Subject: Reorganise packages --- src/esieequest/Main.java | 12 +- src/esieequest/controller/Callback.java | 15 - src/esieequest/controller/GameEngine.java | 113 ---- src/esieequest/controller/Input.java | 48 -- .../controller/commands/AleaCommand.java | 39 -- .../controller/commands/BackCommand.java | 30 - src/esieequest/controller/commands/Command.java | 101 --- src/esieequest/controller/commands/DoCommand.java | 40 -- .../controller/commands/DropCommand.java | 41 -- src/esieequest/controller/commands/Executable.java | 25 - src/esieequest/controller/commands/GoCommand.java | 61 -- .../controller/commands/HelpCommand.java | 26 - .../controller/commands/InventoryCommand.java | 27 - .../controller/commands/LoadCommand.java | 60 -- .../controller/commands/LookCommand.java | 36 -- src/esieequest/controller/commands/NewCommand.java | 41 -- .../controller/commands/QuitCommand.java | 28 - .../controller/commands/SaveCommand.java | 29 - .../controller/commands/TakeCommand.java | 67 -- .../controller/commands/TalkCommand.java | 46 -- .../controller/commands/ToggleSoundCommand.java | 26 - .../controller/commands/TurnCommand.java | 45 -- src/esieequest/controller/commands/UseCommand.java | 35 -- .../controller/commands/package-info.java | 4 - src/esieequest/controller/package-info.java | 5 - src/esieequest/controller/utils/EnumUtils.java | 162 ----- src/esieequest/controller/utils/ListUtils.java | 44 -- .../controller/utils/SerialisableList.java | 27 - .../controller/utils/SerialisableObject.java | 27 - src/esieequest/controller/utils/package-info.java | 5 - src/esieequest/engine/Callback.java | 15 + src/esieequest/engine/GameEngine.java | 113 ++++ src/esieequest/engine/Input.java | 48 ++ src/esieequest/engine/commands/AleaCommand.java | 39 ++ src/esieequest/engine/commands/BackCommand.java | 30 + src/esieequest/engine/commands/Command.java | 101 +++ src/esieequest/engine/commands/DoCommand.java | 40 ++ src/esieequest/engine/commands/DropCommand.java | 41 ++ src/esieequest/engine/commands/Executable.java | 25 + src/esieequest/engine/commands/GoCommand.java | 61 ++ src/esieequest/engine/commands/HelpCommand.java | 26 + .../engine/commands/InventoryCommand.java | 27 + src/esieequest/engine/commands/LoadCommand.java | 60 ++ src/esieequest/engine/commands/LookCommand.java | 36 ++ src/esieequest/engine/commands/NewCommand.java | 41 ++ src/esieequest/engine/commands/QuitCommand.java | 28 + src/esieequest/engine/commands/SaveCommand.java | 29 + src/esieequest/engine/commands/TakeCommand.java | 67 ++ src/esieequest/engine/commands/TalkCommand.java | 46 ++ .../engine/commands/ToggleSoundCommand.java | 26 + src/esieequest/engine/commands/TurnCommand.java | 45 ++ src/esieequest/engine/commands/UseCommand.java | 35 ++ src/esieequest/engine/commands/package-info.java | 4 + src/esieequest/engine/package-info.java | 5 + src/esieequest/engine/utils/EnumUtils.java | 162 +++++ src/esieequest/engine/utils/ListUtils.java | 44 ++ src/esieequest/engine/utils/SerialisableList.java | 27 + .../engine/utils/SerialisableObject.java | 27 + src/esieequest/engine/utils/package-info.java | 5 + src/esieequest/esieequest.gwt.xml | 12 +- src/esieequest/game/Game.java | 248 ++++++++ src/esieequest/game/Player.java | 186 ++++++ src/esieequest/game/Text.java | 152 +++++ src/esieequest/game/characters/Athanase.java | 82 +++ src/esieequest/game/characters/Character.java | 75 +++ .../game/characters/FollowingCharacter.java | 52 ++ .../game/characters/MovingCharacter.java | 137 ++++ .../game/characters/SimpleCharacter.java | 49 ++ src/esieequest/game/characters/Sumobot.java | 58 ++ .../game/characters/WanderingCharacter.java | 52 ++ src/esieequest/game/characters/package-info.java | 5 + src/esieequest/game/doors/Door.java | 43 ++ src/esieequest/game/doors/HiddenDoor.java | 22 + src/esieequest/game/doors/LockedDoor.java | 54 ++ src/esieequest/game/doors/TransporterDoor.java | 54 ++ src/esieequest/game/doors/TrapDoor.java | 32 + src/esieequest/game/doors/package-info.java | 4 + src/esieequest/game/items/Banana.java | 25 + src/esieequest/game/items/Beamer.java | 68 ++ src/esieequest/game/items/Disk.java | 55 ++ src/esieequest/game/items/Inventory.java | 214 +++++++ src/esieequest/game/items/Item.java | 107 ++++ src/esieequest/game/items/Note.java | 34 + src/esieequest/game/items/PortableConsole.java | 42 ++ src/esieequest/game/items/SimpleItem.java | 88 +++ src/esieequest/game/items/package-info.java | 5 + src/esieequest/game/map/Direction.java | 80 +++ src/esieequest/game/map/Orientation.java | 17 + src/esieequest/game/map/Room.java | 361 +++++++++++ src/esieequest/game/map/Side.java | 85 +++ src/esieequest/game/map/package-info.java | 5 + src/esieequest/game/package-info.java | 5 + src/esieequest/game/states/Quest.java | 33 + src/esieequest/game/states/Scene.java | 50 ++ src/esieequest/game/states/package-info.java | 5 + src/esieequest/model/Game.java | 248 -------- src/esieequest/model/Player.java | 186 ------ src/esieequest/model/Text.java | 152 ----- src/esieequest/model/characters/Athanase.java | 82 --- src/esieequest/model/characters/Character.java | 75 --- .../model/characters/FollowingCharacter.java | 52 -- .../model/characters/MovingCharacter.java | 137 ---- .../model/characters/SimpleCharacter.java | 49 -- src/esieequest/model/characters/Sumobot.java | 58 -- .../model/characters/WanderingCharacter.java | 52 -- src/esieequest/model/characters/package-info.java | 5 - src/esieequest/model/doors/Door.java | 43 -- src/esieequest/model/doors/HiddenDoor.java | 22 - src/esieequest/model/doors/LockedDoor.java | 54 -- src/esieequest/model/doors/TransporterDoor.java | 54 -- src/esieequest/model/doors/TrapDoor.java | 32 - src/esieequest/model/doors/package-info.java | 4 - src/esieequest/model/events/Quest.java | 33 - src/esieequest/model/events/Scene.java | 50 -- src/esieequest/model/events/package-info.java | 5 - src/esieequest/model/items/Banana.java | 25 - src/esieequest/model/items/Beamer.java | 68 -- src/esieequest/model/items/Disk.java | 55 -- src/esieequest/model/items/Inventory.java | 214 ------- src/esieequest/model/items/Item.java | 107 ---- src/esieequest/model/items/Note.java | 34 - src/esieequest/model/items/PortableConsole.java | 42 -- src/esieequest/model/items/SimpleItem.java | 88 --- src/esieequest/model/items/package-info.java | 5 - src/esieequest/model/map/Direction.java | 80 --- src/esieequest/model/map/Orientation.java | 17 - src/esieequest/model/map/Room.java | 361 ----------- src/esieequest/model/map/Side.java | 85 --- src/esieequest/model/map/package-info.java | 5 - src/esieequest/model/package-info.java | 5 - src/esieequest/ui/Viewable.java | 116 ++++ src/esieequest/ui/package-info.java | 5 + src/esieequest/ui/rich/Applet.java | 28 + src/esieequest/ui/rich/UserInterface.java | 698 +++++++++++++++++++++ src/esieequest/ui/rich/Window.java | 32 + src/esieequest/ui/rich/package-info.java | 5 + src/esieequest/ui/text/Console.java | 25 + src/esieequest/ui/text/FileReader.java | 47 ++ src/esieequest/ui/text/TextInterface.java | 144 +++++ src/esieequest/ui/text/package-info.java | 5 + src/esieequest/ui/web/Main.java | 26 + src/esieequest/ui/web/WebInterface.java | 478 ++++++++++++++ src/esieequest/ui/web/WebInterface.ui.xml | 89 +++ src/esieequest/ui/web/package-info.java | 5 + src/esieequest/view/Viewable.java | 116 ---- src/esieequest/view/app/Applet.java | 28 - src/esieequest/view/app/UserInterface.java | 698 --------------------- src/esieequest/view/app/Window.java | 32 - src/esieequest/view/app/package-info.java | 5 - src/esieequest/view/package-info.java | 5 - src/esieequest/view/text/Console.java | 25 - src/esieequest/view/text/FileReader.java | 47 -- src/esieequest/view/text/TextInterface.java | 144 ----- src/esieequest/view/text/package-info.java | 5 - src/esieequest/view/web/Main.java | 26 - src/esieequest/view/web/WebInterface.java | 478 -------------- src/esieequest/view/web/WebInterface.ui.xml | 89 --- src/esieequest/view/web/package-info.java | 5 - 158 files changed, 5552 insertions(+), 5552 deletions(-) delete mode 100644 src/esieequest/controller/Callback.java delete mode 100644 src/esieequest/controller/GameEngine.java delete mode 100644 src/esieequest/controller/Input.java delete mode 100644 src/esieequest/controller/commands/AleaCommand.java delete mode 100644 src/esieequest/controller/commands/BackCommand.java delete mode 100644 src/esieequest/controller/commands/Command.java delete mode 100644 src/esieequest/controller/commands/DoCommand.java delete mode 100644 src/esieequest/controller/commands/DropCommand.java delete mode 100644 src/esieequest/controller/commands/Executable.java delete mode 100644 src/esieequest/controller/commands/GoCommand.java delete mode 100644 src/esieequest/controller/commands/HelpCommand.java delete mode 100644 src/esieequest/controller/commands/InventoryCommand.java delete mode 100644 src/esieequest/controller/commands/LoadCommand.java delete mode 100644 src/esieequest/controller/commands/LookCommand.java delete mode 100644 src/esieequest/controller/commands/NewCommand.java delete mode 100644 src/esieequest/controller/commands/QuitCommand.java delete mode 100644 src/esieequest/controller/commands/SaveCommand.java delete mode 100644 src/esieequest/controller/commands/TakeCommand.java delete mode 100644 src/esieequest/controller/commands/TalkCommand.java delete mode 100644 src/esieequest/controller/commands/ToggleSoundCommand.java delete mode 100644 src/esieequest/controller/commands/TurnCommand.java delete mode 100644 src/esieequest/controller/commands/UseCommand.java delete mode 100644 src/esieequest/controller/commands/package-info.java delete mode 100644 src/esieequest/controller/package-info.java delete mode 100644 src/esieequest/controller/utils/EnumUtils.java delete mode 100644 src/esieequest/controller/utils/ListUtils.java delete mode 100644 src/esieequest/controller/utils/SerialisableList.java delete mode 100644 src/esieequest/controller/utils/SerialisableObject.java delete mode 100644 src/esieequest/controller/utils/package-info.java create mode 100644 src/esieequest/engine/Callback.java create mode 100644 src/esieequest/engine/GameEngine.java create mode 100644 src/esieequest/engine/Input.java create mode 100644 src/esieequest/engine/commands/AleaCommand.java create mode 100644 src/esieequest/engine/commands/BackCommand.java create mode 100644 src/esieequest/engine/commands/Command.java create mode 100644 src/esieequest/engine/commands/DoCommand.java create mode 100644 src/esieequest/engine/commands/DropCommand.java create mode 100644 src/esieequest/engine/commands/Executable.java create mode 100644 src/esieequest/engine/commands/GoCommand.java create mode 100644 src/esieequest/engine/commands/HelpCommand.java create mode 100644 src/esieequest/engine/commands/InventoryCommand.java create mode 100644 src/esieequest/engine/commands/LoadCommand.java create mode 100644 src/esieequest/engine/commands/LookCommand.java create mode 100644 src/esieequest/engine/commands/NewCommand.java create mode 100644 src/esieequest/engine/commands/QuitCommand.java create mode 100644 src/esieequest/engine/commands/SaveCommand.java create mode 100644 src/esieequest/engine/commands/TakeCommand.java create mode 100644 src/esieequest/engine/commands/TalkCommand.java create mode 100644 src/esieequest/engine/commands/ToggleSoundCommand.java create mode 100644 src/esieequest/engine/commands/TurnCommand.java create mode 100644 src/esieequest/engine/commands/UseCommand.java create mode 100644 src/esieequest/engine/commands/package-info.java create mode 100644 src/esieequest/engine/package-info.java create mode 100644 src/esieequest/engine/utils/EnumUtils.java create mode 100644 src/esieequest/engine/utils/ListUtils.java create mode 100644 src/esieequest/engine/utils/SerialisableList.java create mode 100644 src/esieequest/engine/utils/SerialisableObject.java create mode 100644 src/esieequest/engine/utils/package-info.java create mode 100644 src/esieequest/game/Game.java create mode 100644 src/esieequest/game/Player.java create mode 100644 src/esieequest/game/Text.java create mode 100644 src/esieequest/game/characters/Athanase.java create mode 100644 src/esieequest/game/characters/Character.java create mode 100644 src/esieequest/game/characters/FollowingCharacter.java create mode 100644 src/esieequest/game/characters/MovingCharacter.java create mode 100644 src/esieequest/game/characters/SimpleCharacter.java create mode 100644 src/esieequest/game/characters/Sumobot.java create mode 100644 src/esieequest/game/characters/WanderingCharacter.java create mode 100644 src/esieequest/game/characters/package-info.java create mode 100644 src/esieequest/game/doors/Door.java create mode 100644 src/esieequest/game/doors/HiddenDoor.java create mode 100644 src/esieequest/game/doors/LockedDoor.java create mode 100644 src/esieequest/game/doors/TransporterDoor.java create mode 100644 src/esieequest/game/doors/TrapDoor.java create mode 100644 src/esieequest/game/doors/package-info.java create mode 100644 src/esieequest/game/items/Banana.java create mode 100644 src/esieequest/game/items/Beamer.java create mode 100644 src/esieequest/game/items/Disk.java create mode 100644 src/esieequest/game/items/Inventory.java create mode 100644 src/esieequest/game/items/Item.java create mode 100644 src/esieequest/game/items/Note.java create mode 100644 src/esieequest/game/items/PortableConsole.java create mode 100644 src/esieequest/game/items/SimpleItem.java create mode 100644 src/esieequest/game/items/package-info.java create mode 100644 src/esieequest/game/map/Direction.java create mode 100644 src/esieequest/game/map/Orientation.java create mode 100644 src/esieequest/game/map/Room.java create mode 100644 src/esieequest/game/map/Side.java create mode 100644 src/esieequest/game/map/package-info.java create mode 100644 src/esieequest/game/package-info.java create mode 100644 src/esieequest/game/states/Quest.java create mode 100644 src/esieequest/game/states/Scene.java create mode 100644 src/esieequest/game/states/package-info.java delete mode 100644 src/esieequest/model/Game.java delete mode 100644 src/esieequest/model/Player.java delete mode 100644 src/esieequest/model/Text.java delete mode 100644 src/esieequest/model/characters/Athanase.java delete mode 100644 src/esieequest/model/characters/Character.java delete mode 100644 src/esieequest/model/characters/FollowingCharacter.java delete mode 100644 src/esieequest/model/characters/MovingCharacter.java delete mode 100644 src/esieequest/model/characters/SimpleCharacter.java delete mode 100644 src/esieequest/model/characters/Sumobot.java delete mode 100644 src/esieequest/model/characters/WanderingCharacter.java delete mode 100644 src/esieequest/model/characters/package-info.java delete mode 100644 src/esieequest/model/doors/Door.java delete mode 100644 src/esieequest/model/doors/HiddenDoor.java delete mode 100644 src/esieequest/model/doors/LockedDoor.java delete mode 100644 src/esieequest/model/doors/TransporterDoor.java delete mode 100644 src/esieequest/model/doors/TrapDoor.java delete mode 100644 src/esieequest/model/doors/package-info.java delete mode 100644 src/esieequest/model/events/Quest.java delete mode 100644 src/esieequest/model/events/Scene.java delete mode 100644 src/esieequest/model/events/package-info.java delete mode 100644 src/esieequest/model/items/Banana.java delete mode 100644 src/esieequest/model/items/Beamer.java delete mode 100644 src/esieequest/model/items/Disk.java delete mode 100644 src/esieequest/model/items/Inventory.java delete mode 100644 src/esieequest/model/items/Item.java delete mode 100644 src/esieequest/model/items/Note.java delete mode 100644 src/esieequest/model/items/PortableConsole.java delete mode 100644 src/esieequest/model/items/SimpleItem.java delete mode 100644 src/esieequest/model/items/package-info.java delete mode 100644 src/esieequest/model/map/Direction.java delete mode 100644 src/esieequest/model/map/Orientation.java delete mode 100644 src/esieequest/model/map/Room.java delete mode 100644 src/esieequest/model/map/Side.java delete mode 100644 src/esieequest/model/map/package-info.java delete mode 100644 src/esieequest/model/package-info.java create mode 100644 src/esieequest/ui/Viewable.java create mode 100644 src/esieequest/ui/package-info.java create mode 100644 src/esieequest/ui/rich/Applet.java create mode 100644 src/esieequest/ui/rich/UserInterface.java create mode 100644 src/esieequest/ui/rich/Window.java create mode 100644 src/esieequest/ui/rich/package-info.java create mode 100644 src/esieequest/ui/text/Console.java create mode 100644 src/esieequest/ui/text/FileReader.java create mode 100644 src/esieequest/ui/text/TextInterface.java create mode 100644 src/esieequest/ui/text/package-info.java create mode 100644 src/esieequest/ui/web/Main.java create mode 100644 src/esieequest/ui/web/WebInterface.java create mode 100644 src/esieequest/ui/web/WebInterface.ui.xml create mode 100644 src/esieequest/ui/web/package-info.java delete mode 100644 src/esieequest/view/Viewable.java delete mode 100644 src/esieequest/view/app/Applet.java delete mode 100644 src/esieequest/view/app/UserInterface.java delete mode 100644 src/esieequest/view/app/Window.java delete mode 100644 src/esieequest/view/app/package-info.java delete mode 100644 src/esieequest/view/package-info.java delete mode 100644 src/esieequest/view/text/Console.java delete mode 100644 src/esieequest/view/text/FileReader.java delete mode 100644 src/esieequest/view/text/TextInterface.java delete mode 100644 src/esieequest/view/text/package-info.java delete mode 100644 src/esieequest/view/web/Main.java delete mode 100644 src/esieequest/view/web/WebInterface.java delete mode 100644 src/esieequest/view/web/WebInterface.ui.xml delete mode 100644 src/esieequest/view/web/package-info.java (limited to 'src') diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index f8b013f..c755741 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java @@ -5,12 +5,12 @@ import java.util.List; import javax.swing.JApplet; -import esieequest.controller.GameEngine; -import esieequest.view.Viewable; -import esieequest.view.app.Applet; -import esieequest.view.app.Window; -import esieequest.view.text.Console; -import esieequest.view.text.FileReader; +import esieequest.engine.GameEngine; +import esieequest.ui.Viewable; +import esieequest.ui.rich.Applet; +import esieequest.ui.rich.Window; +import esieequest.ui.text.Console; +import esieequest.ui.text.FileReader; /** * The main class of the program. diff --git a/src/esieequest/controller/Callback.java b/src/esieequest/controller/Callback.java deleted file mode 100644 index ef03b72..0000000 --- a/src/esieequest/controller/Callback.java +++ /dev/null @@ -1,15 +0,0 @@ -package esieequest.controller; - -/** - * The Callback interface. - * - * @author Pacien TRAN-GIRARD - */ -public interface Callback { - - /** - * Will be run after the execution of the function. - */ - public void call(); - -} diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java deleted file mode 100644 index ae76059..0000000 --- a/src/esieequest/controller/GameEngine.java +++ /dev/null @@ -1,113 +0,0 @@ -package esieequest.controller; - -import esieequest.controller.commands.Command; -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.model.characters.MovingCharacter; -import esieequest.model.events.Scene; -import esieequest.model.items.Beamer; -import esieequest.model.items.Item; -import esieequest.model.map.Room; -import esieequest.view.Viewable; - -/** - * The game main controller class. - * - * @author Pacien TRAN-GIRARD - * @author Benoît LUBRANO DI SBARAGLIONE - */ -public class GameEngine { - - private final Game game; - private final Viewable view; - - /** - * Instantiates a game engine with the given model and view. - * - * @param game - * the game model - * @param view - * the view - */ - public GameEngine(final Viewable view, final Game game) { - this.game = game; - this.view = view; - - this.view.setController(this); - - this.view.show(); - } - - /** - * Instantiates a game with the given view and mode. - * - * @param view - * the view - * @param challengeMode - * the mode - */ - public GameEngine(final Viewable view, final boolean challengeMode) { - this(view, new Game(challengeMode)); - } - - /** - * Instantiates a game with the given view. - * - * @param view - * the view - */ - public GameEngine(final Viewable view) { - this(view, false); - } - - /** - * Interprets a command. - * - * @param inputString - * the input String - */ - public void interpret(final String inputString) { - final Input input = new Input(inputString/* .toLowerCase() */); - - final Command command = input.getCommand(); - if (command == null) { - this.view.echo(Text.UNKNOWN_COMMAND.toString()); - return; - } - - final String argument = input.getArgument(); - - command.execute(argument, this.game, this.view); - this.executeRoutines(); - } - - /** - * Performs routine actions executed every time a Command is entered. - */ - private void executeRoutines() { - this.checkStalemate(); - MovingCharacter.moveAll(this.game); - } - - private void checkStalemate() { - - final boolean inDeadEnd = this.game.getPlayer().getCurrentRoom() == Room.DEAD_END; - final boolean canGoBack = this.game.getPlayer().canGoBack(); - final boolean hasBeamer = this.game.getPlayer().getInventory().hasItem(Item.BEAMER); - boolean canTeleport = hasBeamer; - - if (hasBeamer) { - final Beamer beamer = (Beamer) Item.BEAMER.getItem(); - canTeleport = (beamer.getRoom() != null) && (beamer.getRoom() != Room.DEAD_END); - } - - final boolean trapped = inDeadEnd && !canGoBack && !canTeleport; - - if (trapped) { - this.view.playScene(Scene.GAME_LOST); - this.view.echo("You are trapped. You losed."); - } - - } - -} diff --git a/src/esieequest/controller/Input.java b/src/esieequest/controller/Input.java deleted file mode 100644 index 784985e..0000000 --- a/src/esieequest/controller/Input.java +++ /dev/null @@ -1,48 +0,0 @@ -package esieequest.controller; - -import lombok.Getter; -import esieequest.controller.commands.Command; - -/** - * An user textual input. - * - * @author Pacien TRAN-GIRARD - */ -public class Input { - - @Getter - private Command command; - @Getter - 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; - } - } - -} diff --git a/src/esieequest/controller/commands/AleaCommand.java b/src/esieequest/controller/commands/AleaCommand.java deleted file mode 100644 index 093f088..0000000 --- a/src/esieequest/controller/commands/AleaCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -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.Viewable; - -/** - * Provides a way to override the random behaviour of TransporterDoor-s for - * testing purposes. - * - * @author Pacien TRAN-GIRARD - */ -public class AleaCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - final String forcedRoomName = argument; - Room destinationRoom = null; - - if (!forcedRoomName.isEmpty()) { - try { - destinationRoom = Room.valueOf(forcedRoomName.toUpperCase()); - } catch (final Exception exception) { - view.echo(Text.NO_SUCH_ROOM.toString()); - return; - } - view.echo(Text.ALEA_OVERRIDE_ENABLED.toString()); - } else { - view.echo(Text.ALEA_OVERRIDE_DISABLED.toString()); - } - - TransporterDoor.forceDestination(destinationRoom); - - } - -} diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java deleted file mode 100644 index b2322ed..0000000 --- a/src/esieequest/controller/commands/BackCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Allows the user to go back on his steps and go to his previous location. - * - * @author Pacien TRAN-GIRARD - */ -public class BackCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - game.getPlayer().goToPreviousRoom(); - - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() - .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() - .canGoBack()); - - } - -} diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java deleted file mode 100644 index 651d3da..0000000 --- a/src/esieequest/controller/commands/Command.java +++ /dev/null @@ -1,101 +0,0 @@ -package esieequest.controller.commands; - -import java.util.ArrayList; -import java.util.List; - -import esieequest.controller.utils.ListUtils; -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * 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()), - HELP(new HelpCommand()), - ALEA(new AleaCommand()), - SOUND(new ToggleSoundCommand()), - - // map related - GO(new GoCommand()), - 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 Executable command; - - /** - * Links an enum constant to a CommandInterface. - * - * @param command - * the CommandInterface - */ - Command(final Executable 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 Viewable view) { - final String arg = argument == null ? "" : argument; - this.command.execute(arg, 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 ListUtils.listToString(Command.listCommandsNames(), Text.HELP_PREFIX.toString(), - null, Text.HELP_SUFFIX.toString()); - } - -} diff --git a/src/esieequest/controller/commands/DoCommand.java b/src/esieequest/controller/commands/DoCommand.java deleted file mode 100644 index cb596e8..0000000 --- a/src/esieequest/controller/commands/DoCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.model.map.Side; -import esieequest.view.Viewable; - -/** - * A shortcut Command that executes a TALK or a TAKE Command accordingly to the - * context. - * - * @author Pacien TRAN-GIRARD - */ -public class DoCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - final Side currentSide = game.getPlayer().getCurrentSide(); - - if (currentSide.hasCharacter()) { - Command.TALK.execute(argument, game, view); - return; - } - - if (currentSide.getInventory().getSize() == 1) { - Command.TAKE.execute(argument, game, view); - return; - } - - view.echo(Text.NOTHING_TO_DO.toString()); - - } - -} diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java deleted file mode 100644 index 6ed2b81..0000000 --- a/src/esieequest/controller/commands/DropCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.model.items.Item; -import esieequest.view.Viewable; - -/** - * 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 Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - final String itemName = argument; - - if (itemName.isEmpty()) { - view.echo(Text.NO_ITEM_SPECIFIED.toString()); - return; - } - - if (!game.getPlayer().getInventory().hasItem(itemName)) { - view.echo(Text.NO_SUCH_ITEM.toString()); - return; - } - - final Item item = game.getPlayer().getInventory().takeItem(itemName); - game.getPlayer().getCurrentSide().getInventory().putItem(item); - - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() - .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() - .canGoBack()); - view.updateInventory(game.getPlayer().getInventory()); - - } - -} diff --git a/src/esieequest/controller/commands/Executable.java b/src/esieequest/controller/commands/Executable.java deleted file mode 100644 index ab84b78..0000000 --- a/src/esieequest/controller/commands/Executable.java +++ /dev/null @@ -1,25 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.view.Viewable; - -/** - * The Executable interface. - * - * @author Pacien TRAN-GIRARD - */ -public interface Executable { - - /** - * Performs the task corresponding to the Command. - * - * @param argument - * the argument to pass to the Command (null if empty String) - * @param game - * the Game model - * @param view - * the View - */ - public void execute(final String argument, final Game game, final Viewable view); - -} diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java deleted file mode 100644 index 4bcd0e1..0000000 --- a/src/esieequest/controller/commands/GoCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -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.Viewable; - -/** - * Allows the user to move from connected Room-s to Room-s by giving the - * Direction. - * - * @author Pacien TRAN-GIRARD - */ -public class GoCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - Direction direction; - - if (!argument.isEmpty()) { - - try { - direction = Direction.valueOf(argument.toUpperCase()); - } catch (final IllegalArgumentException e) { - view.echo(Text.NO_SUCH_DIRECTION.toString()); - return; - } - - } else { - - direction = game.getPlayer().getCurrentDirection(); - - } - - if (!game.getPlayer().getCurrentRoom().getSide(direction).hasDoor()) { - view.echo(Text.NO_DOOR.toString()); - return; - } - - final Door door = game.getPlayer().getCurrentRoom().getSide(direction).getDoor(); - - final boolean crossed = door.cross(game, view); - - if (!crossed) { - return; - } - - view.updateLocation(game.getPlayer().getCurrentRoom(), direction, game.getPlayer() - .getCurrentSide(), game.getPlayer().canGoBack()); - - // handle challenge mode - if (game.getPlayer().walk()) { - view.echo(Text.CHALLENGE_FAILED.toString()); - view.disableInput(); - } - - } - -} diff --git a/src/esieequest/controller/commands/HelpCommand.java b/src/esieequest/controller/commands/HelpCommand.java deleted file mode 100644 index 1c3c59b..0000000 --- a/src/esieequest/controller/commands/HelpCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Prints the available commands. - * - * @author Pacien TRAN-GIRARD - */ -public class HelpCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - view.echo(Command.listCommandsNamesString()); - - } - -} diff --git a/src/esieequest/controller/commands/InventoryCommand.java b/src/esieequest/controller/commands/InventoryCommand.java deleted file mode 100644 index 6b5a5b1..0000000 --- a/src/esieequest/controller/commands/InventoryCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Prints the list of the items in the Player's inventory. - * - * @author Pacien TRAN-GIRARD - */ -public class InventoryCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - view.echo(game.getPlayer().getInventory().listItemsNamesString() - + game.getPlayer().getInventory().getWeightString()); - - } - -} diff --git a/src/esieequest/controller/commands/LoadCommand.java b/src/esieequest/controller/commands/LoadCommand.java deleted file mode 100644 index 65dab15..0000000 --- a/src/esieequest/controller/commands/LoadCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package esieequest.controller.commands; - -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.json.simple.parser.ParseException; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Loads a saved Game. - * - * @author Pacien TRAN-GIRARD - */ -public class LoadCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (argument.isEmpty()) { - view.echo(Text.MISSING_ARGUMENT.toString()); - return; - } - - final String jsonString; - if (argument.startsWith("{")) { - jsonString = argument; - } else { - jsonString = view.load(argument); - } - - JSONObject datas = new JSONObject(); - try { - datas = (JSONObject) JSONValue.parseWithException(jsonString); - } catch (final ParseException e) { - view.echo(Text.PARSING_ERROR_PREFIX.toString() + e.getMessage() - + Text.PARSING_ERROR_SUFFIX.toString()); - return; - } - - try { - game.newGame(false, false); - game.deserialise(datas); - } catch (final IllegalArgumentException | ClassCastException | NullPointerException e) { - view.echo(Text.DESERIALISING_ERROR_PREFIX.toString() + e.getMessage() - + Text.DESERIALISING_ERROR_SUFFIX.toString()); - e.printStackTrace(); - return; - } - - view.updateQuest(game.getPlayer().getCurrentQuest()); - view.updateInventory(game.getPlayer().getInventory()); - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() - .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() - .canGoBack()); - view.enableInput(); - - } -} diff --git a/src/esieequest/controller/commands/LookCommand.java b/src/esieequest/controller/commands/LookCommand.java deleted file mode 100644 index d2650da..0000000 --- a/src/esieequest/controller/commands/LookCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -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.Viewable; - -/** - * Prints informations about the current location. - * - * @author Pacien TRAN-GIRARD - */ -public class LookCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - 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.toString()).join(informations)); - - } -} diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java deleted file mode 100644 index 50659c9..0000000 --- a/src/esieequest/controller/commands/NewCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.controller.Callback; -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.model.events.Scene; -import esieequest.view.Viewable; - -/** - * Creates a new game. - * - * @author Pacien TRAN-GIRARD - */ -public class NewCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - final boolean challengeMode = argument.equals(Text.CHALLENGE_FLAG.toString()); - - game.newGame(true, challengeMode); - - view.echo(Text.WELCOME.toString()); - - Scene.INTRO.setCallback(new Callback() { - @Override - public void call() { - view.updateQuest(game.getPlayer().getCurrentQuest()); - view.updateInventory(game.getPlayer().getInventory()); - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() - .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() - .canGoBack()); - - view.enableInput(); - } - }); - - view.playScene(Scene.INTRO); - - } -} diff --git a/src/esieequest/controller/commands/QuitCommand.java b/src/esieequest/controller/commands/QuitCommand.java deleted file mode 100644 index ebcd630..0000000 --- a/src/esieequest/controller/commands/QuitCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Allows the user to quit the game. - * - * @author Pacien TRAN-GIRARD - */ -public class QuitCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - view.echo(Text.QUIT.toString()); - view.disableInput(); - view.stopMusic(); - - } - -} diff --git a/src/esieequest/controller/commands/SaveCommand.java b/src/esieequest/controller/commands/SaveCommand.java deleted file mode 100644 index 95466e6..0000000 --- a/src/esieequest/controller/commands/SaveCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Saves the current Game. - * - * @author Pacien TRAN-GIRARD - */ -public class SaveCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - final String filePath = argument; - - if (filePath.isEmpty()) { - view.echo(Text.FILE_PATH_NOT_SPECIFIED.toString()); - return; - } - - final String serialisedGame = game.serialise().toJSONString(); - view.save(filePath, serialisedGame); - - } - -} diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java deleted file mode 100644 index cd3f6c7..0000000 --- a/src/esieequest/controller/commands/TakeCommand.java +++ /dev/null @@ -1,67 +0,0 @@ -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.Viewable; - -/** - * Allows the player to take an Item from a Room and transfer it to his - * inventory. - * - * @author Pacien TRAN-GIRARD - */ -public class TakeCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - Item item; - - if (!argument.isEmpty()) { - - final String itemName = argument; - final Room currentRoom = game.getPlayer().getCurrentRoom(); - - if (!currentRoom.hasItem(itemName)) { - view.echo(Text.NO_SUCH_ITEM.toString()); - return; - } - - item = currentRoom.getItem(itemName); - - } else { - - final Side currentSide = game.getPlayer().getCurrentSide(); - - if (currentSide.getInventory().getSize() != 1) { - view.echo(Text.NO_ITEM.toString()); - return; - } - - item = currentSide.getInventory().getItem(); - - } - - // handle inventory weight limit - final int maximumWeight = game.getPlayer().getInventoryWeightLimit(); - final int futureWeight = game.getPlayer().getInventory().getTotalWeight() - + item.getWeight(); - if (futureWeight > maximumWeight) { - view.echo(Text.INVENTORY_FULL.toString()); - return; - } - - game.getPlayer().getCurrentRoom().removeItem(item); - game.getPlayer().getInventory().putItem(item); - - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() - .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() - .canGoBack()); - view.updateInventory(game.getPlayer().getInventory()); - - } - -} diff --git a/src/esieequest/controller/commands/TalkCommand.java b/src/esieequest/controller/commands/TalkCommand.java deleted file mode 100644 index 19c9eae..0000000 --- a/src/esieequest/controller/commands/TalkCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.model.characters.Character; -import esieequest.view.Viewable; - -/** - * Allows the Player to TALK to a Character. - * - * @author Pacien TRAN-GIRARD - */ -public class TalkCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - Character character = null; - - if (!argument.isEmpty()) { - - final String characterName = argument.toLowerCase(); - - if (!game.getPlayer().getCurrentRoom().hasCharacter(characterName)) { - view.echo(Text.NO_SUCH_CHARACTER.toString()); - return; - } - - character = game.getPlayer().getCurrentRoom().getCharacter(characterName); - - } else { - - if (!game.getPlayer().getCurrentSide().hasCharacter()) { - view.echo(Text.NO_CHARACTER.toString()); - return; - } - - character = game.getPlayer().getCurrentSide().getCharacter(); - - } - - character.talk(game, view); - - } - -} diff --git a/src/esieequest/controller/commands/ToggleSoundCommand.java b/src/esieequest/controller/commands/ToggleSoundCommand.java deleted file mode 100644 index 4cf0f7d..0000000 --- a/src/esieequest/controller/commands/ToggleSoundCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.view.Viewable; - -/** - * Mute/unmute the game musics. - * - * @author Pacien TRAN-GIRARD - */ -public class ToggleSoundCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - if (!argument.isEmpty()) { - view.echo(Text.TOO_MANY_ARGUMENTS.toString()); - return; - } - - view.toggleSound(); - - } - -} diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java deleted file mode 100644 index 0a597c9..0000000 --- a/src/esieequest/controller/commands/TurnCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -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.Viewable; - -/** - * Allows the user to turn on himself, that is to say to point to another - * Direction. - * - * @author Pacien TRAN-GIRARD - */ -public class TurnCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - final String direction = argument.toUpperCase(); - - if (direction.isEmpty()) { - view.echo(Text.NO_DIRECTION_SPECIFIED.toString()); - return; - } - - Orientation orientation; - - try { - orientation = Orientation.valueOf(direction); - } catch (final IllegalArgumentException e) { - view.echo(Text.NO_SUCH_DIRECTION.toString()); - return; - } - - final Direction currentDirection = game.getPlayer().getCurrentDirection(); - final Direction newDirection = currentDirection.rotate(orientation); - game.getPlayer().setCurrentDirection(newDirection); - - view.updateLocation(game.getPlayer().getCurrentRoom(), newDirection, game.getPlayer() - .getCurrentSide(), game.getPlayer().canGoBack()); - - } - -} diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java deleted file mode 100644 index c5317e8..0000000 --- a/src/esieequest/controller/commands/UseCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.model.Text; -import esieequest.model.items.Item; -import esieequest.view.Viewable; - -/** - * Allows the player to use an item located in his inventory. - * - * @author Pacien TRAN-GIRARD - */ -public class UseCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - - final String itemName = argument.toLowerCase(); - - if (itemName.isEmpty()) { - view.echo(Text.NO_ITEM_SPECIFIED.toString()); - return; - } - - if (!game.getPlayer().getInventory().hasItem(itemName)) { - view.echo(Text.NO_SUCH_ITEM.toString()); - return; - } - - final Item item = game.getPlayer().getInventory().getItem(itemName); - item.use(game, view); - - } - -} diff --git a/src/esieequest/controller/commands/package-info.java b/src/esieequest/controller/commands/package-info.java deleted file mode 100644 index f53942a..0000000 --- a/src/esieequest/controller/commands/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 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/controller/package-info.java b/src/esieequest/controller/package-info.java deleted file mode 100644 index dd67b33..0000000 --- a/src/esieequest/controller/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * The controller package. Contains the logical part of the game. - */ -package esieequest.controller; - diff --git a/src/esieequest/controller/utils/EnumUtils.java b/src/esieequest/controller/utils/EnumUtils.java deleted file mode 100644 index b07708c..0000000 --- a/src/esieequest/controller/utils/EnumUtils.java +++ /dev/null @@ -1,162 +0,0 @@ -package esieequest.controller.utils; - -import java.util.ArrayList; -import java.util.List; - -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -/** - * A collection of utilities to manipulate and serialise Enum-s. - * - * @author Pacien TRAN-GIRARD - */ -public class EnumUtils { - - private static final String KEY_LABEL = "K"; - private static final String VALUE_LABEL = "V"; - - /** - * Safely names an Enum value. - * - * @param enumValue - * the Enum value - * - * @return the name of the Enum value - */ - public static > String name(final E enumValue) { - if (enumValue != null) { - return enumValue.name(); - } - return null; - } - - /** - * Safely names Enum values from an array. - * - * @param enumValues - * the array of the Enum values - * - * @return the array of the Enum names, with null for missing elements - */ - public static > String[] nameAll(final E[] enumValues) { - - final ArrayList names = new ArrayList<>(); - - for (final E enumValue : enumValues) { - names.add(EnumUtils. name(enumValue)); - } - - return names.toArray(new String[0]); - - } - - /** - * Retrieves safely the Enum value of a String. - * - * @param enumType - * the Enum type - * @param name - * the name of the Enum value to retrieve - * - * @return the Enum value, or null if not found - */ - public static > E valueOf(final Class enumType, final String name) { - - if (name == null) { - return null; - } - - try { - return Enum.valueOf(enumType, name); - } catch (final Exception e) { - return null; - } - - } - - /** - * Retrieves all Enum values by their name. - * - * @param enumType - * the Enum type - * @param names - * the array of names of the Enum values to retrieve - * - * @return the array of Enum values, with null for missing elements - */ - public static > List valuesOf(final Class enumType, final String[] names) { - - final ArrayList values = new ArrayList<>(); - - if (names == null) { - return values; - } - - for (final String name : names) { - values.add(EnumUtils.valueOf(enumType, name)); - } - - return values; - - } - - /** - * Serialises all Enum objects into a JSONArray, ignoring empty objects. - * - * @param serialisableEnumObjects - * an array of SerialisableEnumObject-s - * - * @return the JSONArray of all the objects - */ - public static & SerialisableObject> JSONArray serialiseEnumObjects( - final E[] serialisableEnumObjects) { - - final JSONArray jsonArray = new JSONArray(); - - for (final E serialisableEnumObject : serialisableEnumObjects) { - - final JSONObject serialisedValue = serialisableEnumObject.serialise(); - - if (!serialisedValue.isEmpty()) { - final JSONObject jsonObject = new JSONObject(); - jsonObject.put(EnumUtils.KEY_LABEL, serialisableEnumObject.name()); - jsonObject.put(EnumUtils.VALUE_LABEL, serialisedValue); - jsonArray.add(jsonObject); - } - - } - - return jsonArray; - - } - - /** - * Deserialises objects of an Enum type from a JSONArray. - * - * @param enumType - * the Enum type - * @param jsonArray - * the JSONArray - */ - public static > void deserialiseEnumObjects(final Class enumType, - final JSONArray jsonArray) { - - if (jsonArray == null) { - return; - } - - for (final Object object : jsonArray) { - - final JSONObject jsonObject = (JSONObject) object; - final String key = (String) jsonObject.get(EnumUtils.KEY_LABEL); - - final SerialisableObject serialisableObject = (SerialisableObject) EnumUtils.valueOf( - enumType, key); - serialisableObject.deserialise((JSONObject) jsonObject.get(EnumUtils.VALUE_LABEL)); - - } - - } - -} diff --git a/src/esieequest/controller/utils/ListUtils.java b/src/esieequest/controller/utils/ListUtils.java deleted file mode 100644 index 1d0f9ec..0000000 --- a/src/esieequest/controller/utils/ListUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -package esieequest.controller.utils; - -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 ListUtils { - - /** - * Converts a List into a String with a given prefix, suffix and - * placeholder used if the List is empty. - * - * @param list - * the List to convert - * @param prefix - * the prefix - * @param empty - * the placeholder - * @param suffix - * the suffix - * @return the converted String - */ - public static String listToString(final List list, final String prefix, - final String empty, final String suffix) { - final StringBuilder str = new StringBuilder(prefix); - - if (list.isEmpty()) { - str.append(empty); - } else { - str.append(Joiner.on(Text.LIST_SEPARATOR.toString()).join(list)); - } - str.append(suffix); - - return str.toString(); - } - -} diff --git a/src/esieequest/controller/utils/SerialisableList.java b/src/esieequest/controller/utils/SerialisableList.java deleted file mode 100644 index 8e2cb78..0000000 --- a/src/esieequest/controller/utils/SerialisableList.java +++ /dev/null @@ -1,27 +0,0 @@ -package esieequest.controller.utils; - -import org.json.simple.JSONArray; - -/** - * Represents an Object that can be serialised and deserialised. - * - * @author Pacien TRAN-GIRARD - */ -public interface SerialisableList { - - /** - * Serialises to a JSONObject. - * - * @return the JSONObject - */ - public JSONArray serialise(); - - /** - * Deserialises from a JSONObject. - * - * @param o - * the JSONObject - */ - public void deserialise(final JSONArray o); - -} diff --git a/src/esieequest/controller/utils/SerialisableObject.java b/src/esieequest/controller/utils/SerialisableObject.java deleted file mode 100644 index 334f408..0000000 --- a/src/esieequest/controller/utils/SerialisableObject.java +++ /dev/null @@ -1,27 +0,0 @@ -package esieequest.controller.utils; - -import org.json.simple.JSONObject; - -/** - * Represents an Object that can be serialised and deserialised. - * - * @author Pacien TRAN-GIRARD - */ -public interface SerialisableObject { - - /** - * Serialises to a JSONObject. - * - * @return the JSONObject - */ - public JSONObject serialise(); - - /** - * Deserialises from a JSONObject. - * - * @param o - * the JSONObject - */ - public void deserialise(final JSONObject o); - -} diff --git a/src/esieequest/controller/utils/package-info.java b/src/esieequest/controller/utils/package-info.java deleted file mode 100644 index 2e6d871..0000000 --- a/src/esieequest/controller/utils/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * A general utility package. - */ -package esieequest.controller.utils; - diff --git a/src/esieequest/engine/Callback.java b/src/esieequest/engine/Callback.java new file mode 100644 index 0000000..91d8451 --- /dev/null +++ b/src/esieequest/engine/Callback.java @@ -0,0 +1,15 @@ +package esieequest.engine; + +/** + * The Callback interface. + * + * @author Pacien TRAN-GIRARD + */ +public interface Callback { + + /** + * Will be run after the execution of the function. + */ + public void call(); + +} diff --git a/src/esieequest/engine/GameEngine.java b/src/esieequest/engine/GameEngine.java new file mode 100644 index 0000000..8c1ac95 --- /dev/null +++ b/src/esieequest/engine/GameEngine.java @@ -0,0 +1,113 @@ +package esieequest.engine; + +import esieequest.engine.commands.Command; +import esieequest.game.Game; +import esieequest.game.Text; +import esieequest.game.characters.MovingCharacter; +import esieequest.game.items.Beamer; +import esieequest.game.items.Item; +import esieequest.game.map.Room; +import esieequest.game.states.Scene; +import esieequest.ui.Viewable; + +/** + * The game main controller class. + * + * @author Pacien TRAN-GIRARD + * @author Benoît LUBRANO DI SBARAGLIONE + */ +public class GameEngine { + + private final Game game; + private final Viewable view; + + /** + * Instantiates a game engine with the given model and view. + * + * @param game + * the game model + * @param view + * the view + */ + public GameEngine(final Viewable view, final Game game) { + this.game = game; + this.view = view; + + this.view.setController(this); + + this.view.show(); + } + + /** + * Instantiates a game with the given view and mode. + * + * @param view + * the view + * @param challengeMode + * the mode + */ + public GameEngine(final Viewable view, final boolean challengeMode) { + this(view, new Game(challengeMode)); + } + + /** + * Instantiates a game with the given view. + * + * @param view + * the view + */ + public GameEngine(final Viewable view) { + this(view, false); + } + + /** + * Interprets a command. + * + * @param inputString + * the input String + */ + public void interpret(final String inputString) { + final Input input = new Input(inputString/* .toLowerCase() */); + + final Command command = input.getCommand(); + if (command == null) { + this.view.echo(Text.UNKNOWN_COMMAND.toString()); + return; + } + + final String argument = input.getArgument(); + + command.execute(argument, this.game, this.view); + this.executeRoutines(); + } + + /** + * Performs routine actions executed every time a Command is entered. + */ + private void executeRoutines() { + this.checkStalemate(); + MovingCharacter.moveAll(this.game); + } + + private void checkStalemate() { + + final boolean inDeadEnd = this.game.getPlayer().getCurrentRoom() == Room.DEAD_END; + final boolean canGoBack = this.game.getPlayer().canGoBack(); + final boolean hasBeamer = this.game.getPlayer().getInventory().hasItem(Item.BEAMER); + boolean canTeleport = hasBeamer; + + if (hasBeamer) { + final Beamer beamer = (Beamer) Item.BEAMER.getItem(); + canTeleport = (beamer.getRoom() != null) && (beamer.getRoom() != Room.DEAD_END); + } + + final boolean trapped = inDeadEnd && !canGoBack && !canTeleport; + + if (trapped) { + this.view.playScene(Scene.GAME_LOST); + this.view.echo("You are trapped. You losed."); + } + + } + +} diff --git a/src/esieequest/engine/Input.java b/src/esieequest/engine/Input.java new file mode 100644 index 0000000..f1aef10 --- /dev/null +++ b/src/esieequest/engine/Input.java @@ -0,0 +1,48 @@ +package esieequest.engine; + +import lombok.Getter; +import esieequest.engine.commands.Command; + +/** + * An user textual input. + * + * @author Pacien TRAN-GIRARD + */ +public class Input { + + @Getter + private Command command; + @Getter + 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; + } + } + +} diff --git a/src/esieequest/engine/commands/AleaCommand.java b/src/esieequest/engine/commands/AleaCommand.java new file mode 100644 index 0000000..1e9fce7 --- /dev/null +++ b/src/esieequest/engine/commands/AleaCommand.java @@ -0,0 +1,39 @@ +package esieequest.engine.commands; + +import esieequest.game.Game; +import esieequest.game.Text; +import esieequest.game.doors.TransporterDoor; +import esieequest.game.map.Room; +import esieequest.ui.Viewable; + +/** + * Provides a way to override the random behaviour of TransporterDoor-s for + * testing purposes. + * + * @author Pacien TRAN-GIRARD + */ +public class AleaCommand implements Executable { + + @Override + public void execute(final String argument, final Game game, final Viewable view) { + + final String forcedRoomName = argument; + Room destinationRoom = null; + + if (!forcedRoomName.isEmpty()) { + try { + destinationRoom = Room.valueOf(forcedRoomName.toUpperCase()); + } catch (final Exception exception) { + view.echo(Text.NO_SUCH_ROOM.toString()); + return; + } + view.echo(Text.ALEA_OVERRIDE_ENABLED.toString()); + } else { + view.echo(Text.ALEA_OVERRIDE_DISABLED.toString()); + } + + TransporterDoor.forceDestination(destinationRoom); + + } + +} diff --git a/src/esieequest/engine/commands/BackCommand.java b/src/esieequest/engine/commands/BackCommand.java new file mode 100644 index 0000000..0e0e646 --- /dev/null +++ b/src/esieequest/engine/commands/BackCommand.java @@ -0,0 +1,30 @@ +package esieequest.engine.commands; + +import esieequest.game.Game; +import esieequest.game.Text; +import esieequest.ui.Viewable; + +/** + * Allows the user to go back on his steps and go to his previous location. + * + * @author Pacien TRAN-GIRARD + */ +public class BackCommand implements Executable { + + @Override + public void execute(final String argument, final Game game, final Viewable view) { + + if (!argument.isEmpty()) { + view.echo(Text.TOO_MANY_ARGUMENTS.toString()); + return; + } + + game.getPlayer().goToPreviousRoom(); + + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() + .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() + .canGoBack()); + + } + +} diff --git a/src/esieequest/engine/commands/Command.java b/src/esieequest/engine/commands/Command.java new file mode 100644 index 0000000..23b3ca6 --- /dev/null +++ b/src/esieequest/engine/commands/Command.java @@ -0,0 +1,101 @@ +package esieequest.engine.commands; + +import java.util.ArrayList; +import java.util.List; + +import esieequest.engine.utils.ListUtils; +import esieequest.game.Game; +import esieequest.game.Text; +import esieequest.ui.Viewable; + +/** + * 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()), + HELP(new HelpCommand()), + ALEA(new AleaCommand()), + SOUND(new ToggleSoundCommand()), + + // map related + GO(new GoCommand()), + BACK(new BackCommand()), + TURN(new TurnComma