From 7f70290e780f9a9ae0c98d198c8695449a20026c Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 18 May 2014 12:59:46 +0200 Subject: Add quest draft --- src/esieequest/model/Game.java | 4 +- src/esieequest/model/Player.java | 11 ++++- src/esieequest/model/Text.java | 3 ++ src/esieequest/model/events/Quest.java | 31 ++++++++------ src/esieequest/view/Viewable.java | 20 ++++----- src/esieequest/view/app/UserInterface.java | 66 ++++++++++++++--------------- src/esieequest/view/text/TextInterface.java | 9 ++-- src/esieequest/view/web/WebInterface.java | 10 ++--- 8 files changed, 87 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 9b572e7..94f0a59 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java @@ -14,6 +14,7 @@ import esieequest.model.doors.HiddenDoor; import esieequest.model.doors.LockedDoor; import esieequest.model.doors.TransporterDoor; import esieequest.model.doors.TrapDoor; +import esieequest.model.events.Quest; import esieequest.model.items.Item; import esieequest.model.map.Direction; import esieequest.model.map.Room; @@ -30,6 +31,7 @@ public class Game implements SerialisableObject { public static final int CHALLENGE_STEPS_LIMIT = 50; public static final Direction DEFAULT_DIRECTION = Direction.NORTH; public static final Room DEFAULT_ROOM = Room.AMPHITHEATER_SEAT; + public static final Quest DEFAULT_QUEST = Quest.WHAT_HAPPENED; private static final String CHALLENGE_LABEL = "L"; private final boolean challenge; @@ -67,7 +69,7 @@ public class Game implements SerialisableObject { Room.createAllSides(); this.connectRooms(); - this.setPlayer(new Player(Game.DEFAULT_ROOM, Game.DEFAULT_DIRECTION, Game.DEFAULT_INVENTORY_LIMIT, challengeMode ? Game.CHALLENGE_STEPS_LIMIT : Game.DEFAULT_STEPS_LIMIT)); + this.setPlayer(new Player(Game.DEFAULT_QUEST, Game.DEFAULT_ROOM, Game.DEFAULT_DIRECTION, Game.DEFAULT_INVENTORY_LIMIT, challengeMode ? Game.CHALLENGE_STEPS_LIMIT : Game.DEFAULT_STEPS_LIMIT)); if (populate) { this.addItems(); diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java index a0066dc..ea8af35 100644 --- a/src/esieequest/model/Player.java +++ b/src/esieequest/model/Player.java @@ -11,6 +11,7 @@ import org.json.simple.JSONObject; import esieequest.controller.utils.EnumUtils; import esieequest.controller.utils.SerialisableObject; +import esieequest.model.events.Quest; import esieequest.model.items.Inventory; import esieequest.model.map.Direction; import esieequest.model.map.Room; @@ -24,6 +25,11 @@ import esieequest.model.map.Side; */ public class Player implements SerialisableObject { + private static final String CURRENT_QUEST_LABEL = "Q"; + @Getter + @Setter + private Quest currentQuest; + private static final String CURRENT_ROOM_LABEL = "R"; @Getter @Setter @@ -64,7 +70,8 @@ public class Player implements SerialisableObject { * @param nbStepsLimit * the maximum number of steps */ - public Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { + public Player(final Quest currentQuest, final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { + this.currentQuest = currentQuest; this.currentRoom = currentRoom; this.previousRooms = new Stack<>(); this.currentDirection = currentDirection; @@ -122,6 +129,7 @@ public class Player implements SerialisableObject { public JSONObject serialise() { final CleanJSONObject o = new CleanJSONObject(); + o.put(Player.CURRENT_QUEST_LABEL, this.currentQuest.name()); o.put(Player.CURRENT_ROOM_LABEL, this.currentRoom.name()); o.put(Player.PREVIOUS_ROOMS_LABEL, EnumUtils.nameAll(this.previousRooms.toArray(new Room[0]))); @@ -139,6 +147,7 @@ public class Player implements SerialisableObject { @Override public void deserialise(final JSONObject o) { + this.currentQuest = Quest.valueOf((String) o.get(Player.CURRENT_QUEST_LABEL)); this.currentRoom = Room.valueOf((String) o.get(Player.CURRENT_ROOM_LABEL)); this.previousRooms.clear(); diff --git a/src/esieequest/model/Text.java b/src/esieequest/model/Text.java index 84253b3..a72ff4a 100644 --- a/src/esieequest/model/Text.java +++ b/src/esieequest/model/Text.java @@ -25,6 +25,8 @@ public enum Text { BEAMER_ROOM_MEMORISED("The coordinates of the current location have been memorised: "), BEAMER_TELEPORTED("Zap! You have reached your destination. The device's memory has been cleared."), + CURRENT_QUEST_PREFIX("Current quest: "), + // objects NOTE_PREFIX("It is written: "), NOTE_ATHANASE("In case of logical trouble: find Athanase, office #3254."), @@ -59,6 +61,7 @@ public enum Text { // formatting LIST_SEPARATOR(", "), + FILENAME_SEPARATOR("_"), NEW_LINE("\n"), SPACE(" "), diff --git a/src/esieequest/model/events/Quest.java b/src/esieequest/model/events/Quest.java index 30c4aa0..54cbb4a 100644 --- a/src/esieequest/model/events/Quest.java +++ b/src/esieequest/model/events/Quest.java @@ -1,26 +1,31 @@ package esieequest.model.events; +import lombok.Getter; + /** * A quest that can be completed in the game. * * @author Pacien TRAN-GIRARD */ -public class Quest { +public enum Quest { - private String title; + // @formatter:off + + WHAT_HAPPENED("What happened?!?!"), + FIND_ATHANASE("Find Athanase"), + FEED_ATHAnASE("Feed Athanase"), + FIND_DISK("Find the Disk"), + FIND_TRANSPONDER("Find the Transponder"), + ACTIVATE_TRANSPONDER("Activate the Transponder"), + + ; + + // @formatter:on - /** - * @return the title - */ - public String getTitle() { - return this.title; - } + @Getter + private String title; - /** - * @param title - * the title to set - */ - public void setTitle(final String title) { + Quest(final String title) { this.title = title; } diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index 0b23b8c..d4da79b 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -32,6 +32,11 @@ public interface Viewable { */ public void enable(); + /** + * Disables the user interface. + */ + public void disable(); + /** * Displays a message. * @@ -41,9 +46,12 @@ public interface Viewable { public void echo(final String message); /** - * Disables the user interface. + * Updates the view to match the current quest. + * + * @param quest + * the current quest to display */ - public void disable(); + public void updateQuest(final Quest quest); /** * Updates the view to match the current location. @@ -57,14 +65,6 @@ public interface Viewable { */ public void updateLocation(final Room room, final Direction direction, final Side side); - /** - * Updates the view to match the current quest. - * - * @param quest - * the current quest to display - */ - public void updateQuest(final Quest quest); - /** * Updates the view to display the items contained in the inventory * diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index fffe440..f25a233 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -311,6 +311,35 @@ abstract class UserInterface implements Viewable, ActionListener { this.imageLabel.setIcon(imageIcon); } + /** + * Opens the inventory (switches to the inventory tab). + */ + private void openInventory() { + this.consolePanel.setVisible(false); + this.inventoryPanel.setVisible(true); + // this.inventoryButton.addStyleName("button-activated"); + } + + /** + * Closes the inventory (switches to the console tab). + */ + private void closeInventory() { + this.inventoryPanel.setVisible(false); + this.consolePanel.setVisible(true); + // this.inventoryButton.removeStyleName("button-activated"); + } + + /** + * Toggles the inventory tab. + */ + private void toggleInventory() { + if (this.inventoryPanel.isVisible()) { + this.closeInventory(); + } else { + this.openInventory(); + } + } + /** * Translates the received ActionEvent into the corresponding game command * and forwards it to the game engine. @@ -348,44 +377,15 @@ abstract class UserInterface implements Viewable, ActionListener { this.clearInputField(); } - @Override - public void updateLocation(final Room room, final Direction direction, final Side side) { - this.echo(room.getInformations()); - this.setIllustration(room.name() + "_" + direction.name()); - } - @Override public void updateQuest(final Quest quest) { this.setQuestLabel(quest.getTitle()); } - /** - * Opens the inventory (switches to the inventory tab). - */ - private void openInventory() { - this.consolePanel.setVisible(false); - this.inventoryPanel.setVisible(true); - // this.inventoryButton.addStyleName("button-activated"); - } - - /** - * Closes the inventory (switches to the console tab). - */ - private void closeInventory() { - this.inventoryPanel.setVisible(false); - this.consolePanel.setVisible(true); - // this.inventoryButton.removeStyleName("button-activated"); - } - - /** - * Toggles the inventory tab. - */ - private void toggleInventory() { - if (this.inventoryPanel.isVisible()) { - this.closeInventory(); - } else { - this.openInventory(); - } + @Override + public void updateLocation(final Room room, final Direction direction, final Side side) { + this.echo(room.getInformations()); + this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.getText() + direction.name()); } @Override diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index a59bca4..7f282b1 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -2,6 +2,7 @@ package esieequest.view.text; import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; +import esieequest.model.Text; import esieequest.model.events.Quest; import esieequest.model.items.Inventory; import esieequest.model.map.Direction; @@ -81,13 +82,13 @@ abstract class TextInterface implements Viewable { } @Override - public void updateLocation(final Room room, final Direction direction, final Side side) { - this.echo(room.getInformations()); + public void updateQuest(final Quest quest) { + this.echo(Text.CURRENT_QUEST_PREFIX.getText() + quest.getTitle()); } @Override - public void updateQuest(final Quest quest) { - this.echo("Current quest: " + quest.getTitle()); + public void updateLocation(final Room room, final Direction direction, final Side side) { + this.echo(room.getInformations()); } @Override diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 7174180..28f1bd2 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -296,14 +296,14 @@ class WebInterface extends Composite implements Viewable { } @Override - public void updateLocation(final Room room, final Direction direction, final Side side) { - this.setIllustration(room.name() + "_" + direction.name()); - this.echo(room.getInformations()); + public void updateQuest(final Quest quest) { + this.setQuestLabel(quest.getTitle()); } @Override - public void updateQuest(final Quest quest) { - this.setQuestLabel(quest.getTitle()); + public void updateLocation(final Room room, final Direction direction, final Side side) { + this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.getText() + direction.name()); + this.echo(room.getInformations()); } @Override -- cgit v1.2.3