From 86f23485879ded7ab37938c67e49c12b9ad67d21 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 21 Apr 2014 23:50:42 +0200 Subject: Rename interfaces (-able) --- src/esieequest/Main.java | 4 +- src/esieequest/controller/GameEngine.java | 6 +- .../controller/commands/AleaCommand.java | 6 +- .../controller/commands/BackCommand.java | 6 +- src/esieequest/controller/commands/Command.java | 8 +-- .../controller/commands/CommandInterface.java | 25 ------- src/esieequest/controller/commands/DoCommand.java | 6 +- .../controller/commands/DropCommand.java | 6 +- src/esieequest/controller/commands/Executable.java | 25 +++++++ .../controller/commands/ForwardCommand.java | 6 +- src/esieequest/controller/commands/GoCommand.java | 6 +- .../controller/commands/HelpCommand.java | 6 +- .../controller/commands/InventoryCommand.java | 6 +- .../controller/commands/LoadCommand.java | 6 +- .../controller/commands/LookCommand.java | 6 +- src/esieequest/controller/commands/NewCommand.java | 6 +- .../controller/commands/QuitCommand.java | 6 +- .../controller/commands/SaveCommand.java | 6 +- .../controller/commands/SoundCommand.java | 6 +- .../controller/commands/TakeCommand.java | 6 +- .../controller/commands/TalkCommand.java | 6 +- .../controller/commands/TurnCommand.java | 6 +- src/esieequest/controller/commands/UseCommand.java | 6 +- src/esieequest/model/doors/Door.java | 4 +- src/esieequest/model/doors/LockedDoor.java | 4 +- src/esieequest/model/doors/TrapDoor.java | 4 +- src/esieequest/model/items/Beamer.java | 4 +- src/esieequest/model/items/Item.java | 4 +- src/esieequest/view/View.java | 81 ---------------------- src/esieequest/view/Viewable.java | 81 ++++++++++++++++++++++ src/esieequest/view/app/UserInterface.java | 4 +- src/esieequest/view/text/TextInterface.java | 4 +- src/esieequest/view/web/WebInterface.java | 4 +- 33 files changed, 185 insertions(+), 185 deletions(-) delete mode 100644 src/esieequest/controller/commands/CommandInterface.java create mode 100644 src/esieequest/controller/commands/Executable.java delete mode 100644 src/esieequest/view/View.java create mode 100644 src/esieequest/view/Viewable.java diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index 4759a6e..974a6be 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java @@ -7,7 +7,7 @@ import javax.swing.JApplet; import esieequest.controller.GameEngine; import esieequest.model.Game; -import esieequest.view.View; +import esieequest.view.Viewable; import esieequest.view.app.Applet; import esieequest.view.app.Window; import esieequest.view.text.Console; @@ -48,7 +48,7 @@ public class Main extends JApplet { public static void main(final String[] args) { final List arguments = Arrays.asList(args); Game game; - View view; + Viewable view; if (arguments.contains("--file")) { if (arguments.size() < 2) { diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java index df3d34a..fed79d6 100644 --- a/src/esieequest/controller/GameEngine.java +++ b/src/esieequest/controller/GameEngine.java @@ -4,7 +4,7 @@ import esieequest.controller.commands.Command; import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.characters.MovingCharacter; -import esieequest.view.View; +import esieequest.view.Viewable; /** * The game main controller class. @@ -15,7 +15,7 @@ import esieequest.view.View; public class GameEngine { private final Game game; - private final View view; + private final Viewable view; /** * Instantiates a game engine with the given model and view. @@ -25,7 +25,7 @@ public class GameEngine { * @param view * the view */ - public GameEngine(final Game game, final View view) { + public GameEngine(final Game game, final Viewable view) { this.game = game; this.view = view; diff --git a/src/esieequest/controller/commands/AleaCommand.java b/src/esieequest/controller/commands/AleaCommand.java index 2a5f5c4..33f4deb 100644 --- a/src/esieequest/controller/commands/AleaCommand.java +++ b/src/esieequest/controller/commands/AleaCommand.java @@ -4,7 +4,7 @@ import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.doors.TransporterDoor; import esieequest.model.map.Room; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Provides a way to override the random behaviour of TransporterDoor-s for @@ -12,10 +12,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class AleaCommand implements CommandInterface { +public class AleaCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final String forcedRoomName = argument; Room destinationRoom = null; diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java index 8919540..627df59 100644 --- a/src/esieequest/controller/commands/BackCommand.java +++ b/src/esieequest/controller/commands/BackCommand.java @@ -1,17 +1,17 @@ package esieequest.controller.commands; import esieequest.model.Game; -import esieequest.view.View; +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 CommandInterface { +public class BackCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable 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 index 9b032f7..7ab6961 100644 --- a/src/esieequest/controller/commands/Command.java +++ b/src/esieequest/controller/commands/Command.java @@ -6,7 +6,7 @@ import java.util.List; import esieequest.controller.Utils; import esieequest.model.Game; import esieequest.model.Text; -import esieequest.view.View; +import esieequest.view.Viewable; /** * The Command-s the user can use. @@ -47,7 +47,7 @@ public enum Command { // @formatter:on - private CommandInterface command; + private Executable command; /** * Links an enum constant to a CommandInterface. @@ -55,7 +55,7 @@ public enum Command { * @param command * the CommandInterface */ - Command(final CommandInterface command) { + Command(final Executable command) { this.command = command; } @@ -69,7 +69,7 @@ public enum Command { * @param view * the View */ - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { this.command.execute(argument, game, view); } diff --git a/src/esieequest/controller/commands/CommandInterface.java b/src/esieequest/controller/commands/CommandInterface.java deleted file mode 100644 index e3a26f9..0000000 --- a/src/esieequest/controller/commands/CommandInterface.java +++ /dev/null @@ -1,25 +0,0 @@ -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 index e99c67d..219dba9 100644 --- a/src/esieequest/controller/commands/DoCommand.java +++ b/src/esieequest/controller/commands/DoCommand.java @@ -3,7 +3,7 @@ package esieequest.controller.commands; import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.map.Side; -import esieequest.view.View; +import esieequest.view.Viewable; /** * A shortcut Command that executes a TALK or a TAKE Command accordingly to the @@ -11,10 +11,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class DoCommand implements CommandInterface { +public class DoCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final Side currentSide = game.getPlayer().getCurrentSide(); diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java index 3685c21..8d2b820 100644 --- a/src/esieequest/controller/commands/DropCommand.java +++ b/src/esieequest/controller/commands/DropCommand.java @@ -3,7 +3,7 @@ package esieequest.controller.commands; import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.items.Item; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the user to drop an Item from his inventory (referred by its name) to @@ -11,10 +11,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class DropCommand implements CommandInterface { +public class DropCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final String itemName = argument; diff --git a/src/esieequest/controller/commands/Executable.java b/src/esieequest/controller/commands/Executable.java new file mode 100644 index 0000000..36ec6be --- /dev/null +++ b/src/esieequest/controller/commands/Executable.java @@ -0,0 +1,25 @@ +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 + * @param game + * the Game model + * @param view + * the View + */ + public void execute(String argument, Game game, Viewable view); + +} diff --git a/src/esieequest/controller/commands/ForwardCommand.java b/src/esieequest/controller/commands/ForwardCommand.java index f15a4e2..9134fdc 100644 --- a/src/esieequest/controller/commands/ForwardCommand.java +++ b/src/esieequest/controller/commands/ForwardCommand.java @@ -2,7 +2,7 @@ package esieequest.controller.commands; import esieequest.model.Game; import esieequest.model.map.Direction; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the user to move forward in the Map (in the Room at the Direction he @@ -10,10 +10,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class ForwardCommand implements CommandInterface { +public class ForwardCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final Direction direction = game.getPlayer().getCurrentDirection(); diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index 61718a1..ccb974b 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -4,7 +4,7 @@ import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.doors.Door; import esieequest.model.map.Direction; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the user to move from connected Room-s to Room-s by giving the @@ -12,10 +12,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class GoCommand implements CommandInterface { +public class GoCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final Direction direction; diff --git a/src/esieequest/controller/commands/HelpCommand.java b/src/esieequest/controller/commands/HelpCommand.java index 37b99e4..4c4c39f 100644 --- a/src/esieequest/controller/commands/HelpCommand.java +++ b/src/esieequest/controller/commands/HelpCommand.java @@ -1,17 +1,17 @@ package esieequest.controller.commands; import esieequest.model.Game; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Prints the available commands. * * @author Pacien TRAN-GIRARD */ -public class HelpCommand implements CommandInterface { +public class HelpCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { view.echo(Command.listCommandsNamesString()); diff --git a/src/esieequest/controller/commands/InventoryCommand.java b/src/esieequest/controller/commands/InventoryCommand.java index da37e07..ff7a341 100644 --- a/src/esieequest/controller/commands/InventoryCommand.java +++ b/src/esieequest/controller/commands/InventoryCommand.java @@ -1,17 +1,17 @@ package esieequest.controller.commands; import esieequest.model.Game; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Prints the list of the items in the Player's inventory. * * @author Pacien TRAN-GIRARD */ -public class InventoryCommand implements CommandInterface { +public class InventoryCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { view.echo(game.getPlayer().listItemsNamesString()); diff --git a/src/esieequest/controller/commands/LoadCommand.java b/src/esieequest/controller/commands/LoadCommand.java index 4a3972b..79ccf60 100644 --- a/src/esieequest/controller/commands/LoadCommand.java +++ b/src/esieequest/controller/commands/LoadCommand.java @@ -1,17 +1,17 @@ package esieequest.controller.commands; import esieequest.model.Game; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Loads a saved Game. * * @author Pacien TRAN-GIRARD */ -public class LoadCommand implements CommandInterface { +public class LoadCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { // TODO Auto-generated method stub } diff --git a/src/esieequest/controller/commands/LookCommand.java b/src/esieequest/controller/commands/LookCommand.java index d053b25..5006a66 100644 --- a/src/esieequest/controller/commands/LookCommand.java +++ b/src/esieequest/controller/commands/LookCommand.java @@ -6,17 +6,17 @@ import com.google.common.base.Joiner; import esieequest.model.Game; import esieequest.model.Text; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Prints informations about the current location. * * @author Pacien TRAN-GIRARD */ -public class LookCommand implements CommandInterface { +public class LookCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final ArrayList informations = new ArrayList(); diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java index b49d36b..3c23882 100644 --- a/src/esieequest/controller/commands/NewCommand.java +++ b/src/esieequest/controller/commands/NewCommand.java @@ -4,17 +4,17 @@ import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.map.Direction; import esieequest.model.map.Room; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Creates a new game. * * @author Pacien TRAN-GIRARD */ -public class NewCommand implements CommandInterface { +public class NewCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { // TODO: load a new game game.getPlayer().setCurrentDirection(Direction.NORTH); diff --git a/src/esieequest/controller/commands/QuitCommand.java b/src/esieequest/controller/commands/QuitCommand.java index 739bf93..be53589 100644 --- a/src/esieequest/controller/commands/QuitCommand.java +++ b/src/esieequest/controller/commands/QuitCommand.java @@ -2,17 +2,17 @@ package esieequest.controller.commands; import esieequest.model.Game; import esieequest.model.Text; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the user to quit the game. * * @author Pacien TRAN-GIRARD */ -public class QuitCommand implements CommandInterface { +public class QuitCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { view.echo(Text.QUIT.getText()); view.disable(); diff --git a/src/esieequest/controller/commands/SaveCommand.java b/src/esieequest/controller/commands/SaveCommand.java index 44e83c0..641b329 100644 --- a/src/esieequest/controller/commands/SaveCommand.java +++ b/src/esieequest/controller/commands/SaveCommand.java @@ -1,17 +1,17 @@ package esieequest.controller.commands; import esieequest.model.Game; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Saves the current Game. * * @author Pacien TRAN-GIRARD */ -public class SaveCommand implements CommandInterface { +public class SaveCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { // TODO Auto-generated method stub } diff --git a/src/esieequest/controller/commands/SoundCommand.java b/src/esieequest/controller/commands/SoundCommand.java index d375173..fbd11d7 100644 --- a/src/esieequest/controller/commands/SoundCommand.java +++ b/src/esieequest/controller/commands/SoundCommand.java @@ -1,17 +1,17 @@ package esieequest.controller.commands; import esieequest.model.Game; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the user to enable or disable the game's sounds. * * @author Pacien TRAN-GIRARD */ -public class SoundCommand implements CommandInterface { +public class SoundCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { // TODO Auto-generated method stub } diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java index 97eb8b7..705fb6e 100644 --- a/src/esieequest/controller/commands/TakeCommand.java +++ b/src/esieequest/controller/commands/TakeCommand.java @@ -5,7 +5,7 @@ import esieequest.model.Text; import esieequest.model.items.Item; import esieequest.model.map.Room; import esieequest.model.map.Side; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the player to take an Item from a Room and transfer it to his @@ -13,10 +13,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class TakeCommand implements CommandInterface { +public class TakeCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { Item item; if (argument != null) { diff --git a/src/esieequest/controller/commands/TalkCommand.java b/src/esieequest/controller/commands/TalkCommand.java index 1637870..b3168ae 100644 --- a/src/esieequest/controller/commands/TalkCommand.java +++ b/src/esieequest/controller/commands/TalkCommand.java @@ -2,17 +2,17 @@ package esieequest.controller.commands; import esieequest.model.Game; import esieequest.model.Text; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the Player to TALK to a Character. * * @author Pacien TRAN-GIRARD */ -public class TalkCommand implements CommandInterface { +public class TalkCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { if (!game.getPlayer().getCurrentSide().hasCharacter()) { view.echo(Text.NO_CHARACTER.getText()); diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java index e451263..a03fbab 100644 --- a/src/esieequest/controller/commands/TurnCommand.java +++ b/src/esieequest/controller/commands/TurnCommand.java @@ -4,7 +4,7 @@ import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.map.Direction; import esieequest.model.map.Orientation; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the user to turn on himself, that is to say to point to another @@ -12,10 +12,10 @@ import esieequest.view.View; * * @author Pacien TRAN-GIRARD */ -public class TurnCommand implements CommandInterface { +public class TurnCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { Orientation orientation; diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java index d8b8416..56eaf00 100644 --- a/src/esieequest/controller/commands/UseCommand.java +++ b/src/esieequest/controller/commands/UseCommand.java @@ -3,17 +3,17 @@ package esieequest.controller.commands; import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.items.Item; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Allows the player to use an item located in his inventory. * * @author Pacien TRAN-GIRARD */ -public class UseCommand implements CommandInterface { +public class UseCommand implements Executable { @Override - public void execute(final String argument, final Game game, final View view) { + public void execute(final String argument, final Game game, final Viewable view) { final String itemName = argument; diff --git a/src/esieequest/model/doors/Door.java b/src/esieequest/model/doors/Door.java index 6c1a906..9b67cda 100644 --- a/src/esieequest/model/doors/Door.java +++ b/src/esieequest/model/doors/Door.java @@ -2,7 +2,7 @@ package esieequest.model.doors; import esieequest.model.Game; import esieequest.model.map.Room; -import esieequest.view.View; +import esieequest.view.Viewable; /** * A door that links two rooms. @@ -52,7 +52,7 @@ public class Door { * * @return if the Door was effectively crossed */ - public boolean cross(final Game game, final View view) { + public boolean cross(final Game game, final Viewable view) { game.getPlayer().goToRoom(this.getDestination()); return true; } diff --git a/src/esieequest/model/doors/LockedDoor.java b/src/esieequest/model/doors/LockedDoor.java index 7305011..28c535e 100644 --- a/src/esieequest/model/doors/LockedDoor.java +++ b/src/esieequest/model/doors/LockedDoor.java @@ -5,7 +5,7 @@ import esieequest.model.Player; import esieequest.model.Text; import esieequest.model.items.KeyCard; import esieequest.model.map.Room; -import esieequest.view.View; +import esieequest.view.Viewable; /** * A door that links two rooms and requires a KeyCard to pass through. @@ -47,7 +47,7 @@ public class LockedDoor extends Door { } @Override - public boolean cross(final Game game, final View view) { + public boolean cross(final Game game, final Viewable view) { if (!this.isAuthorised(game.getPlayer())) { view.echo(Text.DOOR_LOCKED.getText()); return false; diff --git a/src/esieequest/model/doors/TrapDoor.java b/src/esieequest/model/doors/TrapDoor.java index c4c6bfa..2db5443 100644 --- a/src/esieequest/model/doors/TrapDoor.java +++ b/src/esieequest/model/doors/TrapDoor.java @@ -2,7 +2,7 @@ package esieequest.model.doors; import esieequest.model.Game; import esieequest.model.map.Room; -import esieequest.view.View; +import esieequest.view.Viewable; /** * A one-way door that links two rooms and prevent the usage of the 'back' @@ -23,7 +23,7 @@ public class TrapDoor extends Door { } @Override - public boolean cross(final Game game, final View view) { + public boolean cross(final Game game, final Viewable view) { game.getPlayer().clearRoomHistory(); return super.cross(game, view); } diff --git a/src/esieequest/model/items/Beamer.java b/src/esieequest/model/items/Beamer.java index 64426cd..61bef94 100644 --- a/src/esieequest/model/items/Beamer.java +++ b/src/esieequest/model/items/Beamer.java @@ -3,7 +3,7 @@ package esieequest.model.items; import esieequest.model.Game; import esieequest.model.Text; import esieequest.model.map.Room; -import esieequest.view.View; +import esieequest.view.Viewable; /** * A beamer is a device that can be charged, and fired. When charged, it @@ -27,7 +27,7 @@ public class Beamer extends Item { } @Override - public void use(final Game game, final View view) { + public void use(final Game game, final Viewable view) { if (this.room == null) { this.room = game.getPlayer().getCurrentRoom(); view.echo(Text.BEAMER_ROOM_MEMORISED.getText() + this.room.hashCode()); diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java index 16c614b..c6f872f 100644 --- a/src/esieequest/model/items/Item.java +++ b/src/esieequest/model/items/Item.java @@ -2,7 +2,7 @@ package esieequest.model.items; import esieequest.model.Game; import esieequest.model.Text; -import esieequest.view.View; +import esieequest.view.Viewable; /** * Represents an item with a description and a weight, stored in a room. Can be @@ -69,7 +69,7 @@ public class Item { * @param view * the View */ - public void use(final Game game, final View view) { + public void use(final Game game, final Viewable view) { view.echo(Text.NO_USE.getText()); } diff --git a/src/esieequest/view/View.java b/src/esieequest/view/View.java deleted file mode 100644 index 9b68f00..0000000 --- a/src/esieequest/view/View.java +++ /dev/null @@ -1,81 +0,0 @@ -package esieequest.view; - -import java.util.HashMap; - -import esieequest.controller.GameEngine; -import esieequest.model.events.Quest; -import esieequest.model.items.Item; -import esieequest.model.map.Room; -import esieequest.model.map.Side; - -/** - * The view interface that describes an user interface. - * - * @author Pacien TRAN-GIRARD - */ -public interface View { - - /** - * Sets the controller to use. - * - * @param gameEngine - * the GameEngine controller - */ - public void setController(GameEngine gameEngine); - - /** - * Displays the user interface. - */ - public void show(); - - /** - * Enables the user interface. - */ - public void enable(); - - /** - * Displays a message. - * - * @param message - * the message - */ - public void echo(String message); - - /** - * Disables the user interface. - */ - public void disable(); - - /** - * Updates the view to match the current room. - * - * @param room - * the room to display - */ - public void updateRoom(Room room); - - /** - * Updates the view to match a side of a room. - * - * @param side - * the side of a room - */ - public void updateSide(Side side); - - /** - * Updates the view to match the current quest. - * - * @param quest - * the current quest to display - */ - public void updateQuest(Quest quest); - - /** - * Updates the view to display the items contained in the inventory - * - * @param items - * the items - */ - public void updateInventory(HashMap items); - -} diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java new file mode 100644 index 0000000..0d1c9e9 --- /dev/null +++ b/src/esieequest/view/Viewable.java @@ -0,0 +1,81 @@ +package esieequest.view; + +import java.util.HashMap; + +import esieequest.controller.GameEngine; +import esieequest.model.events.Quest; +import esieequest.model.items.Item; +import esieequest.model.map.Room; +import esieequest.model.map.Side; + +/** + * The view interface that describes an user interface. + * + * @author Pacien TRAN-GIRARD + */ +public interface Viewable { + + /** + * Sets the controller to use. + * + * @param gameEngine + * the GameEngine controller + */ + public void setController(GameEngine gameEngine); + + /** + * Displays the user interface. + */ + public void show(); + + /** + * Enables the user interface. + */ + public void enable(); + + /** + * Displays a message. + * + * @param message + * the message + */ + public void echo(String message); + + /** + * Disables the user interface. + */ + public void disable(); + + /** + * Updates the view to match the current room. + * + * @param room + * the room to display + */ + public void updateRoom(Room room); + + /** + * Updates the view to match a side of a room. + * + * @param side + * the side of a room + */ + public void updateSide(Side side); + + /** + * Updates the view to match the current quest. + * + * @param quest + * the current quest to display + */ + public void updateQuest(Quest quest); + + /** + * Updates the view to display the items contained in the inventory + * + * @param items + * the items + */ + public void updateInventory(HashMap items); + +} diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index d6fcdae..cee4353 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -24,14 +24,14 @@ import esieequest.model.items.Item; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; -import esieequest.view.View; +import esieequest.view.Viewable; /** * The Swing based graphical user interface. * * @author Pacien TRAN-GIRARD */ -abstract class UserInterface implements View, ActionListener { +abstract class UserInterface implements Viewable, ActionListener { private GameEngine gameEngine; diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index da80f36..98e9a06 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -8,14 +8,14 @@ import esieequest.model.events.Quest; import esieequest.model.items.Item; import esieequest.model.map.Room; import esieequest.model.map.Side; -import esieequest.view.View; +import esieequest.view.Viewable; /** * The textual view. * * @author Pacien TRAN-GIRARD */ -abstract class TextInterface implements View { +abstract class TextInterface implements Viewable { private GameEngine gameEngine; diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 59075e0..2e2815d 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -29,14 +29,14 @@ import esieequest.model.items.Item; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; -import esieequest.view.View; +import esieequest.view.Viewable; /** * The web view. * * @author Pacien TRAN-GIRARD */ -class WebInterface extends Composite implements View { +class WebInterface extends Composite implements Viewable { private GameEngine gameEngine; -- cgit v1.2.3 From 7bd608905ed1be586004621af2a252eafd22c384 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 25 Apr 2014 21:02:43 +0200 Subject: Store Item in enum, remove KeyCard --- src/esieequest/model/Game.java | 26 +++++---- src/esieequest/model/doors/LockedDoor.java | 16 +++--- src/esieequest/model/items/Beamer.java | 2 +- src/esieequest/model/items/Item.java | 51 +++++++---------- src/esieequest/model/items/KeyCard.java | 20 ------- src/esieequest/model/items/SimpleItem.java | 86 +++++++++++++++++++++++++++++ src/esieequest/view/Viewable.java | 4 +- src/esieequest/view/app/UserInterface.java | 4 +- src/esieequest/view/text/TextInterface.java | 4 +- src/esieequest/view/web/WebInterface.java | 4 +- 10 files changed, 138 insertions(+), 79 deletions(-) delete mode 100644 src/esieequest/model/items/KeyCard.java create mode 100644 src/esieequest/model/items/SimpleItem.java diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 830b48c..6267d1a 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java @@ -7,9 +7,7 @@ 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.Direction; import esieequest.model.map.Room; @@ -86,8 +84,15 @@ public class Game { 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)); + + final LockedDoor lockedDoorEnter = new LockedDoor(Room.LOCKED_ROOM); + lockedDoorEnter.setKey(Item.KEYCARD); + this.d(Room.SECRET_CORRIDOR_END, Direction.SOUTH, lockedDoorEnter); + + final LockedDoor lockedDoorExit = new LockedDoor(Room.SECRET_CORRIDOR_END); + lockedDoorExit.setKey(Item.KEYCARD); + this.d(Room.LOCKED_ROOM, Direction.NORTH, lockedDoorExit); + this.d(Room.SECRET_CORRIDOR_END, Direction.EAST, new TransporterDoor(Room.values())); } @@ -124,16 +129,13 @@ public class Game { * Adds Item-s in the map. */ 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)); + this.i(Room.STORAGE_ROOM, Direction.WEST, Item.STORAGE_CUBE); + this.i(Room.STORAGE_ROOM, Direction.EAST, Item.SAFETY_CUBE); + this.i(Room.STORAGE_ROOM, Direction.NORTH, Item.BLACK_HOLE); - this.i(Room.SECRET_LAB, Direction.SOUTH, new Beamer("Beamer")); + this.i(Room.SECRET_LAB, Direction.SOUTH, Item.BEAMER); - 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); + this.i(Room.DEAD_END, Direction.NORTH, Item.KEYCARD); } /** diff --git a/src/esieequest/model/doors/LockedDoor.java b/src/esieequest/model/doors/LockedDoor.java index 28c535e..49f61be 100644 --- a/src/esieequest/model/doors/LockedDoor.java +++ b/src/esieequest/model/doors/LockedDoor.java @@ -3,7 +3,7 @@ package esieequest.model.doors; import esieequest.model.Game; import esieequest.model.Player; import esieequest.model.Text; -import esieequest.model.items.KeyCard; +import esieequest.model.items.Item; import esieequest.model.map.Room; import esieequest.view.Viewable; @@ -15,7 +15,7 @@ import esieequest.view.Viewable; */ public class LockedDoor extends Door { - private KeyCard keyCard; + private Item key; /** * Creates a new locked door. @@ -32,18 +32,18 @@ public class LockedDoor extends Door { * * @return the KeyCard */ - public KeyCard getKey() { - return this.keyCard; + public Item getKey() { + return this.key; } /** * Sets the KeyCard authorised to open this door. * - * @param keyCard + * @param key * the KeyCard to set */ - public void setKey(final KeyCard keyCard) { - this.keyCard = keyCard; + public void setKey(final Item key) { + this.key = key; } @Override @@ -65,7 +65,7 @@ public class LockedDoor extends Door { * @return if the Player is authorised to pass */ private boolean isAuthorised(final Player player) { - return player.hasItem(this.keyCard); + return player.hasItem(this.key); } } diff --git a/src/esieequest/model/items/Beamer.java b/src/esieequest/model/items/Beamer.java index 61bef94..3a4ade9 100644 --- a/src/esieequest/model/items/Beamer.java +++ b/src/esieequest/model/items/Beamer.java @@ -12,7 +12,7 @@ import esieequest.view.Viewable; * * @author Pacien TRAN-GIRARD */ -public class Beamer extends Item { +public class Beamer extends SimpleItem { private Room room; diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java index c6f872f..2a0aa2c 100644 --- a/src/esieequest/model/items/Item.java +++ b/src/esieequest/model/items/Item.java @@ -1,37 +1,28 @@ package esieequest.model.items; import esieequest.model.Game; -import esieequest.model.Text; import esieequest.view.Viewable; -/** - * Represents an item with a description and a weight, stored in a room. Can be - * picked, used and dropped. - * - * @author Pacien TRAN-GIRARD - */ -public class Item { +public enum Item { - private final String name; - private final int weight; - private final boolean droppable; + // @formatter:off + + STORAGE_CUBE(new SimpleItem("Weighted Storage Cube", 5, true)), + SAFETY_CUBE(new SimpleItem("Edgeless Safety Cube", 5, true)), + BLACK_HOLE(new SimpleItem("Portable black-hole", -10, false)), + + KEYCARD(new SimpleItem("KeyCard", 0, false)), - /** - * Creates an item with the given characteristics. - * - * @param name - * the description of the item - * @param weight - * the weight of the item - */ - public Item(final String name, final int weight, final boolean droppable) { - this.name = name; - this.weight = weight; - this.droppable = droppable; - } + BEAMER(new Beamer("Beamer")), + + ; + + // @formatter:on + + private final SimpleItem item; - public Item(final String description, final boolean droppable) { - this(description, 0, droppable); + Item(final SimpleItem item) { + this.item = item; } /** @@ -40,7 +31,7 @@ public class Item { * @return the description */ public String getName() { - return this.name; + return this.item.getName(); } /** @@ -49,7 +40,7 @@ public class Item { * @return the weight */ public int getWeight() { - return this.weight; + return this.item.getWeight(); } /** @@ -58,7 +49,7 @@ public class Item { * @return the droppability of the item. */ public boolean isDroppable() { - return this.droppable; + return this.item.isDroppable(); } /** @@ -70,7 +61,7 @@ public class Item { * the View */ public void use(final Game game, final Viewable view) { - view.echo(Text.NO_USE.getText()); + this.item.use(game, view); } } diff --git a/src/esieequest/model/items/KeyCard.java b/src/esieequest/model/items/KeyCard.java deleted file mode 100644 index dee3a08..0000000 --- a/src/esieequest/model/items/KeyCard.java +++ /dev/null @@ -1,20 +0,0 @@ -package esieequest.model.items; - -/** - * A key-card that unlocks a Door. - * - * @author Pacien TRAN-GIRARD - */ -public class KeyCard extends Item { - - /** - * Creates a new KeyCard - * - * @param description - * the description of the KeyCard - */ - public KeyCard(final String description) { - super(description, false); - } - -} diff --git a/src/esieequest/model/items/SimpleItem.java b/src/esieequest/model/items/SimpleItem.java new file mode 100644 index 0000000..59de4d3 --- /dev/null +++ b/src/esieequest/model/items/SimpleItem.java @@ -0,0 +1,86 @@ +package esieequest.model.items; + +import esieequest.model.Game; +import esieequest.model.Text; +import esieequest.view.Viewable; + +/** + * Represents an item with a description and a weight, stored in a room. Can be + * picked, used and dropped. + * + * @author Pacien TRAN-GIRARD + */ +public class SimpleItem { + + private final String name; + private final int weight; + private final boolean droppable; + + /** + * Creates an item with the given characteristics. + * + * @param name + * the name of the item + * @param weight + * the weight of the item + * @param droppable + * if the item is droppable + */ + public SimpleItem(final String name, final int weight, final boolean droppable) { + this.name = name; + this.weight = weight; + this.droppable = droppable; + } + + /** + * Creates an item with no weight. + * + * @param name + * the name of the item + * @param droppable + * if the item is droppable + */ + public SimpleItem(final String name, final boolean droppable) { + this(name, 0, droppable); + } + + /** + * Returns the description of the item. + * + * @return the description + */ + public String getName() { + return this.name; + } + + /** + * Returns the weight of the item. + * + * @return the weight + */ + public int getWeight() { + return this.weight; + } + + /** + * Tells whether the item is droppable. + * + * @return the droppability of the item. + */ + public boolean isDroppable() { + return this.droppable; + } + + /** + * Performs actions when the player uses the Item. + * + * @param game + * the Game model + * @param view + * the View + */ + public void use(final Game game, final Viewable view) { + view.echo(Text.NO_USE.getText()); + } + +} diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index 0d1c9e9..6fc8592 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -4,7 +4,7 @@ import java.util.HashMap; import esieequest.controller.GameEngine; import esieequest.model.events.Quest; -import esieequest.model.items.Item; +import esieequest.model.items.SimpleItem; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -76,6 +76,6 @@ public interface Viewable { * @param items * the items */ - public void updateInventory(HashMap items); + public void updateInventory(HashMap items); } diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index cee4353..ba6d786 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -20,7 +20,7 @@ import com.wordpress.tipsforjava.swing.StretchIcon; import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; -import esieequest.model.items.Item; +import esieequest.model.items.SimpleItem; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -330,7 +330,7 @@ abstract class UserInterface implements Viewable, ActionListener { } @Override - public void updateInventory(final HashMap items) { + public void updateInventory(final HashMap items) { // TODO Auto-generated method stub } diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index 98e9a06..c94eb1a 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -5,7 +5,7 @@ import java.util.HashMap; import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; -import esieequest.model.items.Item; +import esieequest.model.items.SimpleItem; import esieequest.model.map.Room; import esieequest.model.map.Side; import esieequest.view.Viewable; @@ -97,7 +97,7 @@ abstract class TextInterface implements Viewable { } @Override - public void updateInventory(final HashMap items) { + public void updateInventory(final HashMap items) { // TODO Auto-generated method stub } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 2e2815d..baa01e9 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -25,7 +25,7 @@ import com.google.gwt.user.client.ui.Widget; import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; -import esieequest.model.items.Item; +import esieequest.model.items.SimpleItem; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -306,7 +306,7 @@ class WebInterface extends Composite implements Viewable { } @Override - public void updateInventory(final HashMap items) { + public void updateInventory(final HashMap items) { // TODO Auto-generated method stub } -- cgit v1.2.3 From 23c4d7012568277b7985f1b1e633c4b8242f9ddd Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 3 May 2014 18:28:43 +0200 Subject: Add missing inventory weight printing --- src/esieequest/controller/commands/InventoryCommand.java | 2 +- src/esieequest/model/Player.java | 9 +++++++++ src/esieequest/model/Text.java | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/esieequest/controller/commands/InventoryCommand.java b/src/esieequest/controller/commands/InventoryCommand.java index ff7a341..0f95ead 100644 --- a/src/esieequest/controller/commands/InventoryCommand.java +++ b/src/esieequest/controller/commands/InventoryCommand.java @@ -13,7 +13,7 @@ public class InventoryCommand implements Executable { @Override public void execute(final String argument, final Game game, final Viewable view) { - view.echo(game.getPlayer().listItemsNamesString()); + view.echo(game.getPlayer().listItemsNamesString() + game.getPlayer().getWeightString()); } diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java index 3851c44..4060367 100644 --- a/src/esieequest/model/Player.java +++ b/src/esieequest/model/Player.java @@ -295,4 +295,13 @@ public class Player { return this.nbSteps == this.nbStepsLimit; } + /** + * Returns informations about the Player's inventory weight. + * + * @return informations about the Player's inventory weight + */ + public String getWeightString() { + return Text.INVENTORY_WEIGHT_PREFIX.getText() + this.getItemsWeight() + Text.INVENTORY_WEIGHT_SUFFIX.getText(); + } + } diff --git a/src/esieequest/model/Text.java b/src/esieequest/model/Text.java index 7a9bd49..283ccab 100644 --- a/src/esieequest/model/Text.java +++ b/src/esieequest/model/Text.java @@ -48,7 +48,10 @@ public enum Text { DIRECTION_SUFFIX("."), INVENTORY_PREFIX("Items: "), - INVENTORY_SUFFIX("."), + INVENTORY_SUFFIX(". "), + + INVENTORY_WEIGHT_PREFIX("Total inventory weight: "), + INVENTORY_WEIGHT_SUFFIX("."), // formatting LIST_SEPARATOR(", "), -- cgit v1.2.3 From 0a845d99117e4d4186d5be5a63cd8719901caafb Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 3 May 2014 19:06:37 +0200 Subject: Use IntrinsicMap (custom HashMap) --- src/esieequest/controller/GameEngine.java | 2 +- src/esieequest/esieequest.gwt.xml | 1 + src/esieequest/model/Player.java | 39 ++++++-------------- src/esieequest/model/items/Item.java | 8 ++++- src/net/pacien/util/IntrinsicMap.java | 59 +++++++++++++++++++++++++++++++ src/net/pacien/util/Mappable.java | 7 ++++ src/net/pacien/util/pacienutils.gwt.xml | 3 ++ src/net/pacien/util/package-info.java | 8 +++++ 8 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 src/net/pacien/util/IntrinsicMap.java create mode 100644 src/net/pacien/util/Mappable.java create mode 100644 src/net/pacien/util/pacienutils.gwt.xml create mode 100644 src/net/pacien/util/package-info.java diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java index fed79d6..c3a8725 100644 --- a/src/esieequest/controller/GameEngine.java +++ b/src/esieequest/controller/GameEngine.java @@ -41,7 +41,7 @@ public class GameEngine { * the command String */ public void interpret(final String inputString) { - final Input input = new Input(inputString); + final Input input = new Input(inputString.toLowerCase()); final Command command = input.getCommand(); if (command == null) { diff --git a/src/esieequest/esieequest.gwt.xml b/src/esieequest/esieequest.gwt.xml index 1a5c10c..b7dbcbf 100644 --- a/src/esieequest/esieequest.gwt.xml +++ b/src/esieequest/esieequest.gwt.xml @@ -19,6 +19,7 @@ so that your app can take advantage of the latest GWT module capabilities. + diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java index 4060367..2ab8190 100644 --- a/src/esieequest/model/Player.java +++ b/src/esieequest/model/Player.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Stack; +import net.pacien.util.IntrinsicMap; import esieequest.controller.Utils; import esieequest.model.items.Item; import esieequest.model.map.Direction; @@ -22,7 +23,7 @@ public class Player { private final Stack previousRooms; private Direction currentDirection; - private final List items; + private final IntrinsicMap items; private final int carryWeightLimit; private int nbSteps; @@ -43,9 +44,9 @@ public class Player { */ private Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { this.currentRoom = currentRoom; - this.previousRooms = new Stack(); + this.previousRooms = new Stack<>(); this.currentDirection = currentDirection; - this.items = new ArrayList(); + this.items = new IntrinsicMap<>(); this.carryWeightLimit = carryWeightLimit; this.nbSteps = 0; this.nbStepsLimit = nbStepsLimit; @@ -166,7 +167,7 @@ public class Player { * @return if the Player have the Item */ public boolean hasItem(final Item item) { - return this.items.contains(item); + return this.items.containsValue(item); } /** @@ -178,7 +179,7 @@ public class Player { * @return if the Player have the Item */ public boolean hasItem(final String itemName) { - return this.getItem(itemName) != null; + return this.items.containsKey(itemName); } /** @@ -186,7 +187,7 @@ public class Player { */ public int getItemsWeight() { int totalWeight = 0; - for (final Item item : this.items) { + for (final Item item : this.items.values()) { totalWeight += item.getWeight(); } return totalWeight; @@ -199,7 +200,7 @@ public class Player { * the Item to add */ public void addItem(final Item item) { - this.items.add(item); + this.items.put(item); } /** @@ -222,28 +223,13 @@ public class Player { this.removeItem(this.getItem(itemName)); } - /** - * Lists all the Player's Item-s names. - * - * @return the list of all the names of the Item-s - */ - public List listItemsNames() { - final ArrayList itemsNamesList = new ArrayList(); - - for (final Item item : this.items) { - itemsNamesList.add(item.getName()); - } - - return itemsNamesList; - } - /** * Lists all the Player's Item-s names in a String. * * @return the list of the Item-s in a String */ public String listItemsNamesString() { - return Utils.listToString(this.listItemsNames(), Text.INVENTORY_PREFIX.getText(), Text.ITEMS_NO_ITEM.getText(), Text.INVENTORY_SUFFIX.getText()); + return Utils.listToString(new ArrayList(this.items.keySet()), Text.INVENTORY_PREFIX.getText(), Text.ITEMS_NO_ITEM.getText(), Text.INVENTORY_SUFFIX.getText()); } /** @@ -262,12 +248,7 @@ public class Player { * @return the Item */ public Item getItem(final String itemName) { - for (final Item item : this.items) { - if (item.getName().toLowerCase().equals(itemName.toLowerCase())) { - return item; - } - } - return null; + return this.items.get(itemName); } /** diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java index 2a0aa2c..491b3ef 100644 --- a/src/esieequest/model/items/Item.java +++ b/src/esieequest/model/items/Item.java @@ -1,9 +1,10 @@ package esieequest.model.items; +import net.pacien.util.Mappable; import esieequest.model.Game; import esieequest.view.Viewable; -public enum Item { +public enum Item implements Mappable { // @formatter:off @@ -64,4 +65,9 @@ public enum Item { this.item.use(game, view); } + @Override + public Object getKey() { + return this.item.getName().toLowerCase(); + } + } diff --git a/src/net/pacien/util/IntrinsicMap.java b/src/net/pacien/util/IntrinsicMap.java new file mode 100644 index 0000000..a68dcbe --- /dev/null +++ b/src/net/pacien/util/IntrinsicMap.java @@ -0,0 +1,59 @@ +/** + * + */ +package net.pacien.util; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author pacien + * + */ +public class IntrinsicMap extends HashMap { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * + */ + public IntrinsicMap() { + super(); + } + + /** + * @param initialCapacity + */ + public IntrinsicMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * @param m + */ + public IntrinsicMap(Map m) { + super(m); + } + + /** + * @param initialCapacity + * @param loadFactor + */ + public IntrinsicMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + @SuppressWarnings("unchecked") + public V put(V value) { + return super.put((K) value.getKey(), value); + } + + @Override + public V put(K key, V value) { + return this.put(value); + } + +} diff --git a/src/net/pacien/util/Mappable.java b/src/net/pacien/util/Mappable.java new file mode 100644 index 0000000..b5bbf06 --- /dev/null +++ b/src/net/pacien/util/Mappable.java @@ -0,0 +1,7 @@ +package net.pacien.util; + +public interface Mappable { + + public Object getKey(); + +} diff --git a/src/net/pacien/util/pacienutils.gwt.xml b/src/net/pacien/util/pacienutils.gwt.xml new file mode 100644 index 0000000..d2a88de --- /dev/null +++ b/src/net/pacien/util/pacienutils.gwt.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/net/pacien/util/package-info.java b/src/net/pacien/util/package-info.java new file mode 100644 index 0000000..924b56f --- /dev/null +++ b/src/net/pacien/util/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author pacien + * + */ +package net.pacien.util; \ No newline at end of file -- cgit v1.2.3 From 51b8172ae18b9e354e3a97fd26f61b46287e1dcf Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 3 May 2014 20:45:20 +0200 Subject: Add placeholder image generation for GUI view --- .../controller/commands/BackCommand.java | 3 +- src/esieequest/controller/commands/GoCommand.java | 4 +-- src/esieequest/controller/commands/NewCommand.java | 1 + .../controller/commands/TurnCommand.java | 4 +-- src/esieequest/view/Viewable.java | 15 ++++------ src/esieequest/view/app/UserInterface.java | 33 +++++++++++++--------- src/esieequest/view/text/TextInterface.java | 8 ++---- src/esieequest/view/web/WebInterface.java | 9 ++---- 8 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java index 627df59..299bda9 100644 --- a/src/esieequest/controller/commands/BackCommand.java +++ b/src/esieequest/controller/commands/BackCommand.java @@ -14,7 +14,8 @@ public class BackCommand implements Executable { public void execute(final String argument, final Game game, final Viewable view) { game.getPlayer().goToPreviousRoom(); - view.updateRoom(game.getPlayer().getCurrentRoom()); + + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); } diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index ccb974b..9ebdf49 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -39,8 +39,8 @@ public class GoCommand implements Executable { return; } - view.updateRoom(game.getPlayer().getCurrentRoom()); - + view.updateLocation(game.getPlayer().getCurrentRoom(), direction, game.getPlayer().getCurrentSide()); + // handle challenge mode if (game.getPlayer().walk()) { view.echo(Text.CHALLENGE_FAILED.getText()); diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java index 3c23882..dcb4f8f 100644 --- a/src/esieequest/controller/commands/NewCommand.java +++ b/src/esieequest/controller/commands/NewCommand.java @@ -21,6 +21,7 @@ public class NewCommand implements Executable { game.getPlayer().setCurrentRoom(Room.AMPHITHEATER_SEAT); view.enable(); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); view.echo(Text.WELCOME.getText()); } diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java index a03fbab..4f6eb4c 100644 --- a/src/esieequest/controller/commands/TurnCommand.java +++ b/src/esieequest/controller/commands/TurnCommand.java @@ -30,8 +30,8 @@ public class TurnCommand implements Executable { final Direction newDirection = currentDirection.rotate(orientation); game.getPlayer().setCurrentDirection(newDirection); - view.updateSide(game.getPlayer().getCurrentSide()); - + view.updateLocation(game.getPlayer().getCurrentRoom(), newDirection, game.getPlayer().getCurrentSide()); + } } diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index 6fc8592..5d2675f 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -5,6 +5,7 @@ import java.util.HashMap; import esieequest.controller.GameEngine; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -47,20 +48,16 @@ public interface Viewable { public void disable(); /** - * Updates the view to match the current room. + * Updates the view to match the current location. * * @param room - * the room to display - */ - public void updateRoom(Room room); - - /** - * Updates the view to match a side of a room. - * + * the room + * @param direction + * the current direction * @param side * the side of a room */ - public void updateSide(Side side); + public void updateLocation(Room room, Direction direction, Side side); /** * Updates the view to match the current quest. diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index ba6d786..66a0af1 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -3,8 +3,10 @@ package esieequest.view.app; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Font; +import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; import java.net.URL; import java.util.HashMap; @@ -21,6 +23,7 @@ import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -52,6 +55,7 @@ abstract class UserInterface implements Viewable, ActionListener { public UserInterface() { this.buildUI(); this.inputField.addActionListener(this); + this.setActionListener(this); this.setControlsState(false); this.inputField.setEnabled(true); } @@ -270,15 +274,21 @@ abstract class UserInterface implements Viewable, ActionListener { } /** - * Updates the room illustration. + * Updates the room's illustration. + * + * Placeholder generation from http://stackoverflow.com/a/17802477/1348634 */ - private void updateIllustration(final String locationImageName) { - String imageName = locationImageName; - if (imageName == null) { - imageName = "res/img/placeholder.jpg"; + private void updateIllustration(final String imageName) { + final URL imageURL = this.getClass().getClassLoader().getResource(imageName + ".jpg"); + final StretchIcon imageIcon; + if (imageURL == null) { + final BufferedImage bufferedImage = new BufferedImage(240, 135, BufferedImage.TYPE_BYTE_BINARY); + final Graphics graphics = bufferedImage.getGraphics(); + graphics.drawString(imageName, 5, 10 + 5); + imageIcon = new StretchIcon(bufferedImage, true); + } else { + imageIcon = new StretchIcon(imageURL, true); } - final URL imageURL = this.getClass().getClassLoader().getResource(imageName); - final StretchIcon imageIcon = new StretchIcon(imageURL, true); this.imageLabel.setIcon(imageIcon); } @@ -314,14 +324,9 @@ abstract class UserInterface implements Viewable, ActionListener { } @Override - public void updateRoom(final Room room) { - // this.updateIllustration(room.getImageName()); + public void updateLocation(final Room room, final Direction direction, final Side side) { this.echo(room.getInformations()); - } - - @Override - public void updateSide(final Side side) { - // this.updateIllustration(side.getImageName()); + this.updateIllustration(room.name() + "_" + direction.name()); } @Override diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index c94eb1a..8f37c53 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -6,6 +6,7 @@ import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Room; import esieequest.model.map.Side; import esieequest.view.Viewable; @@ -82,15 +83,10 @@ abstract class TextInterface implements Viewable { } @Override - public void updateRoom(final Room room) { + public void updateLocation(Room room, Direction direction, Side side) { this.echo(room.getInformations()); } - @Override - public void updateSide(final Side side) { - // TODO Auto-generated method stub - } - @Override public void updateQuest(final Quest quest) { this.echo("Current quest: " + quest.getTi