From 614965104e47724f55c17dd88cb97eb109e477f4 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 20 May 2014 19:51:11 +0200 Subject: Implement playable scenario --- .../controller/commands/TalkCommand.java | 2 +- src/esieequest/model/Game.java | 2 +- src/esieequest/model/characters/Athanase.java | 76 +++++++++++++++++----- src/esieequest/model/characters/Character.java | 6 +- .../model/characters/SimpleCharacter.java | 4 +- src/esieequest/model/characters/Sumobot.java | 6 +- src/esieequest/model/events/Quest.java | 4 +- src/esieequest/model/events/Scene.java | 4 +- src/esieequest/model/items/Banana.java | 25 +++++++ src/esieequest/model/items/Beamer.java | 2 +- src/esieequest/model/items/Disk.java | 55 ++++++++++++++++ src/esieequest/model/items/Item.java | 6 +- src/esieequest/model/items/Note.java | 2 +- src/esieequest/model/items/PortableConsole.java | 42 ++++++++++++ src/esieequest/model/items/SimpleItem.java | 14 +++- src/esieequest/model/items/Transponder.java | 25 ------- 16 files changed, 216 insertions(+), 59 deletions(-) create mode 100644 src/esieequest/model/items/Banana.java create mode 100644 src/esieequest/model/items/Disk.java create mode 100644 src/esieequest/model/items/PortableConsole.java delete mode 100644 src/esieequest/model/items/Transponder.java diff --git a/src/esieequest/controller/commands/TalkCommand.java b/src/esieequest/controller/commands/TalkCommand.java index 228f954..39c4932 100644 --- a/src/esieequest/controller/commands/TalkCommand.java +++ b/src/esieequest/controller/commands/TalkCommand.java @@ -19,7 +19,7 @@ public class TalkCommand implements Executable { return; } - view.echo(game.getPlayer().getCurrentSide().getCharacter().talk()); + game.getPlayer().getCurrentSide().getCharacter().talk(game, view); } diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 27237bf..2a6a31b 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java @@ -176,7 +176,7 @@ public class Game implements SerialisableObject { // scenario this.i(Room.AMPHITHEATER_STAGE, Direction.SOUTH, Item.NOTE); this.i(Room.CAFETERIA, Direction.WEST, Item.BANANA); - this.i(Room.ESIEESPACE, Direction.NORTH, Item.TRANSPONDER); + this.i(Room.ESIEESPACE, Direction.NORTH, Item.PORTABLE_CONSOLE); this.i(Room.CLUBNIX, Direction.NORTH, Item.DISK); } diff --git a/src/esieequest/model/characters/Athanase.java b/src/esieequest/model/characters/Athanase.java index b4527c8..698b7ae 100644 --- a/src/esieequest/model/characters/Athanase.java +++ b/src/esieequest/model/characters/Athanase.java @@ -1,8 +1,10 @@ package esieequest.model.characters; -import net.pacien.util.CleanJSONObject; - -import org.json.simple.JSONObject; +import esieequest.model.Game; +import esieequest.model.events.Quest; +import esieequest.model.items.Inventory; +import esieequest.model.items.Item; +import esieequest.view.Viewable; /** * Athanase the mathgorilla. @@ -12,27 +14,69 @@ import org.json.simple.JSONObject; public class Athanase extends SimpleCharacter { /** - * Creates Athanase. + * Instantiates Athanase. */ public Athanase() { super("Athanase"); } @Override - public String talk() { - // TODO: require items - return "Who are you? Where did Leila go? I'm so hungry..."; - } + public void talk(final Game game, final Viewable view) { + final Quest currentQuest = game.getPlayer().getCurrentQuest(); + final Inventory playersInventory = game.getPlayer().getInventory(); + switch (currentQuest) { - @Override - public JSONObject serialise() { - // TODO: save state (received items) - return new CleanJSONObject(); - } + case WHAT_HAPPENED: + view.echo("Who are you? Where did Leila go? Somethin happened... But... Can't think... I'm hungry... So hungry..."); + game.getPlayer().setCurrentQuest(Quest.FEED_ATHANASE); + view.updateQuest(Quest.FEED_ATHANASE); + break; + + case FEED_ATHANASE: + if (playersInventory.hasItem(Item.BANANA)) { + playersInventory.removeItem(Item.BANANA); + view.updateInventory(playersInventory); + view.echo("Ooooh! You have a banana! *nomz* WAIT!... It tastes like... an EMERGENCY BANANA! That means... Hmmm..." + + "\n" + + "They turned it ON... Their stupid machine... It was not ready. It was a beta... Obviously it crashed... WITH THE ENTIRE UNIVERSE" + + "\n" + "I think we have to restart everything..."); + game.getPlayer().setCurrentQuest(Quest.FIND_DISK); + view.updateQuest(Quest.FIND_DISK); + } else { + view.echo("ME=HUNGRY => ¬(ME CAN HELP YOU)"); + } + break; + + case FIND_DISK: + if (playersInventory.hasItem(Item.DISK)) { + view.echo("Fantastic! You have the bootloader disk! Now we need a remote console to connect to the Universe... They have a portable one at the Esieespace..."); + game.getPlayer().setCurrentQuest(Quest.FIND_CONSOLE); + view.updateQuest(Quest.FIND_CONSOLE); + } else { + view.echo("Hopefully the Club*nix guys made an emergency boot disk, just in case... FIND IT and bring it!"); + } + break; + + case FIND_CONSOLE: + if (playersInventory.hasItem(Item.PORTABLE_CONSOLE)) { + view.echo("Yaaaay! You found it! We have the software, we have the hardware... I think we are ready for the complete reboot."); + game.getPlayer().setCurrentQuest(Quest.INSTALL_CONSOLE); + view.updateQuest(Quest.INSTALL_CONSOLE); + } else { + view.echo("We need the Portable Remote Console to connect to the Universe... Find it at the Esieespace HQ."); + } + break; + + case INSTALL_CONSOLE: + if (playersInventory.hasItem(Item.PORTABLE_CONSOLE)) { + view.echo("The Universe is far away... Well... Not exactly... Sort of... Complicated. Find an antenna or something that may act as an amplifier and connect the Portable Console to contact the Universe."); + } else { + view.echo("Well... You have installed the console? Have you turned it ON and inserted the disk? Because you should."); + } + break; + + } - @Override - public void deserialise(final JSONObject o) { - return; } } diff --git a/src/esieequest/model/characters/Character.java b/src/esieequest/model/characters/Character.java index c46c5bf..452226d 100644 --- a/src/esieequest/model/characters/Character.java +++ b/src/esieequest/model/characters/Character.java @@ -5,8 +5,10 @@ import org.json.simple.JSONObject; import esieequest.controller.utils.EnumUtils; import esieequest.controller.utils.SerialisableObject; +import esieequest.model.Game; import esieequest.model.map.Direction; import esieequest.model.map.Room; +import esieequest.view.Viewable; public enum Character implements SerialisableObject { @@ -32,8 +34,8 @@ public enum Character implements SerialisableObject { return this.character.getName(); } - public String talk() { - return this.character.talk(); + public void talk(final Game game, final Viewable view) { + this.character.talk(game, view); } /** diff --git a/src/esieequest/model/characters/SimpleCharacter.java b/src/esieequest/model/characters/SimpleCharacter.java index b855089..baaf650 100644 --- a/src/esieequest/model/characters/SimpleCharacter.java +++ b/src/esieequest/model/characters/SimpleCharacter.java @@ -6,6 +6,8 @@ import net.pacien.util.CleanJSONObject; import org.json.simple.JSONObject; import esieequest.controller.utils.SerialisableObject; +import esieequest.model.Game; +import esieequest.view.Viewable; /** * A character that can talk with the player. @@ -32,7 +34,7 @@ public abstract class SimpleCharacter implements SerialisableObject { * * @return what the Character says */ - public abstract String talk(); + public abstract void talk(final Game game, final Viewable view); @Override public JSONObject serialise() { diff --git a/src/esieequest/model/characters/Sumobot.java b/src/esieequest/model/characters/Sumobot.java index c779ad8..fb4e7b3 100644 --- a/src/esieequest/model/characters/Sumobot.java +++ b/src/esieequest/model/characters/Sumobot.java @@ -3,8 +3,10 @@ package esieequest.model.characters; import java.util.HashSet; import java.util.Random; +import esieequest.model.Game; import esieequest.model.map.Direction; import esieequest.model.map.Room; +import esieequest.view.Viewable; /** * A Sumobot from ESIEEspace who says random sentences and moves randomly. @@ -39,10 +41,10 @@ public class Sumobot extends MovingCharacter { } @Override - public String talk() { + public void talk(final Game game, final Viewable view) { this.setCanMove(true); final int randomIndex = this.randomGenerator.nextInt(this.messages.size()); - return (String) this.messages.toArray()[randomIndex]; + view.echo((String) this.messages.toArray()[randomIndex]); } } diff --git a/src/esieequest/model/events/Quest.java b/src/esieequest/model/events/Quest.java index 84bc80b..4644d68 100644 --- a/src/esieequest/model/events/Quest.java +++ b/src/esieequest/model/events/Quest.java @@ -15,8 +15,8 @@ public enum Quest { //FIND_ATHANASE("Find Athanase"), FEED_ATHANASE("Feed Athanase"), FIND_DISK("Find the Disk"), - FIND_TRANSPONDER("Find the Transponder"), - ACTIVATE_TRANSPONDER("Activate the Transponder"), + FIND_CONSOLE("Find the Portable Console"), + INSTALL_CONSOLE("Install the Console"), ; diff --git a/src/esieequest/model/events/Scene.java b/src/esieequest/model/events/Scene.java index 91ae7c2..d67cc0b 100644 --- a/src/esieequest/model/events/Scene.java +++ b/src/esieequest/model/events/Scene.java @@ -14,8 +14,8 @@ public enum Scene { // @formatter:off INTRO("THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY!", "...", 90000), - TRANSPONDER_ACTIVATED("Stalemate Resolved.", "...", 2500), - END("Good work getting this far, future-starter!", "...", 2500), + RUN_CONSOLE("Stalemate Resolved.", "...", 13000), + END("Good work getting this far, future-starter!", "...", 95000), ; diff --git a/src/esieequest/model/items/Banana.java b/src/esieequest/model/items/Banana.java new file mode 100644 index 0000000..ef6771b --- /dev/null +++ b/src/esieequest/model/items/Banana.java @@ -0,0 +1,25 @@ +package esieequest.model.items; + +import esieequest.model.Game; +import esieequest.view.Viewable; + +/** + * A Banana that can be eaten only by Athanase. + * + * @author Pacien TRAN-GIRARD + */ +public class Banana extends SimpleItem { + + /** + * Instantiates the Emergency Banana. + */ + public Banana() { + super("Emergency Banana"); + } + + @Override + public void use(final Game game, final Viewable view) { + view.echo("Better keep it for later..."); + } + +} diff --git a/src/esieequest/model/items/Beamer.java b/src/esieequest/model/items/Beamer.java index 053be18..87d94da 100644 --- a/src/esieequest/model/items/Beamer.java +++ b/src/esieequest/model/items/Beamer.java @@ -28,7 +28,7 @@ public class Beamer extends SimpleItem { * the description of the Beamer */ public Beamer(final String description) { - super(description, true); + super(description); } @Override diff --git a/src/esieequest/model/items/Disk.java b/src/esieequest/model/items/Disk.java new file mode 100644 index 0000000..e83ac8c --- /dev/null +++ b/src/esieequest/model/items/Disk.java @@ -0,0 +1,55 @@ +package esieequest.model.items; + +import esieequest.controller.Callback; +import esieequest.model.Game; +import esieequest.model.events.Scene; +import esieequest.model.map.Direction; +import esieequest.model.map.Room; +import esieequest.view.Viewable; + +/** + * A Disk that can be used in conjunction with an installed PortableConsole. + * + * @author Pacien TRAN-GIRARD + */ +public class Disk extends SimpleItem { + + public Disk() { + super("Bootloader disk"); + } + + @Override + public void use(final Game game, final Viewable view) { + final boolean onRoundabout = game.getPlayer().getCurrentRoom().equals( + Room.ENTRANCE_ROUNDABOUT); + final boolean pointingSouth = game.getPlayer().getCurrentDirection() + .equals(Direction.SOUTH); + final boolean deviceInstalled = game.getPlayer().getCurrentSide().getInventory().hasItem( + Item.PORTABLE_CONSOLE); + + if (onRoundabout && pointingSouth && deviceInstalled) { + game.getPlayer().getInventory().removeItem(Item.DISK); + game.getPlayer().getCurrentSide().getInventory().putItem(Item.DISK); + + view.disable(); + + Scene.RUN_CONSOLE.setCallback(new Callback() { + @Override + public void call() { + Scene.END.setCallback(new Callback() { + @Override + public void call() { + view.echo("Congratulations. The simple fact that you are standing here reading this sentence means you made a glorious contribution to science!"); + } + }); + view.playScene(Scene.END); + } + }); + + view.playScene(Scene.RUN_CONSOLE); + } else { + view.echo("Can't use this item here."); + } + } + +} diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java index 434d9b2..a592249 100644 --- a/src/esieequest/model/items/Item.java +++ b/src/esieequest/model/items/Item.java @@ -26,9 +26,9 @@ public enum Item implements Mappable, SerialisableObject { // scenario NOTE(new Note("Note", Text.NOTE_ATHANASE.toString())), - BANANA(new SimpleItem("Banana", 0, false)), - TRANSPONDER(new Transponder()), - DISK(new SimpleItem("Bootloader disk", 0, false)), + BANANA(new Banana()), + PORTABLE_CONSOLE(new PortableConsole()), + DISK(new Disk()), ; diff --git a/src/esieequest/model/items/Note.java b/src/esieequest/model/items/Note.java index 28c2f53..43235bd 100644 --- a/src/esieequest/model/items/Note.java +++ b/src/esieequest/model/items/Note.java @@ -22,7 +22,7 @@ public class Note extends SimpleItem { * the content of the note */ public Note(final String name, final String text) { - super(name, 0, false); + super(name); this.text = text; } diff --git a/src/esieequest/model/items/PortableConsole.java b/src/esieequest/model/items/PortableConsole.java new file mode 100644 index 0000000..ce1ff57 --- /dev/null +++ b/src/esieequest/model/items/PortableConsole.java @@ -0,0 +1,42 @@ +package esieequest.model.items; + +import esieequest.model.Game; +import esieequest.model.map.Direction; +import esieequest.model.map.Room; +import esieequest.view.Viewable; + +/** + * The transponder. + * + * @author Pacien TRAN-GIRARD + */ +public class PortableConsole extends SimpleItem { + + /** + * Creates a Transponder. + */ + public PortableConsole() { + super("Portable Remote Console"); + } + + @Override + public void use(final Game game, final Viewable view) { + final boolean onRoundabout = game.getPlayer().getCurrentRoom().equals( + Room.ENTRANCE_ROUNDABOUT); + final boolean pointingSouth = game.getPlayer().getCurrentDirection() + .equals(Direction.SOUTH); + + if (onRoundabout && pointingSouth) { + game.getPlayer().getInventory().removeItem(Item.PORTABLE_CONSOLE); + game.getPlayer().getCurrentSide().getInventory().putItem(Item.PORTABLE_CONSOLE); + + view.updateInventory(game.getPlayer().getInventory()); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() + .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() + .canGoBack()); + } else { + view.echo("Can't use this item here."); + } + } + +} diff --git a/src/esieequest/model/items/SimpleItem.java b/src/esieequest/model/items/SimpleItem.java index 7eb99e3..84bdb6c 100644 --- a/src/esieequest/model/items/SimpleItem.java +++ b/src/esieequest/model/items/SimpleItem.java @@ -26,7 +26,7 @@ public class SimpleItem implements SerialisableObject { private final boolean droppable; /** - * Creates an item with the given characteristics. + * Creates a SimpleItem with the given characteristics. * * @param name * the name of the item @@ -42,7 +42,7 @@ public class SimpleItem implements SerialisableObject { } /** - * Creates an item with no weight. + * Creates a SimpleItem with no weight. * * @param name * the name of the item @@ -53,6 +53,16 @@ public class SimpleItem implements SerialisableObject { this(name, 0, droppable); } + /** + * Creates a non-droppable SimpleItem with no weight. + * + * @param name + * the name of the item + */ + public SimpleItem(final String name) { + this(name, false); + } + /** * Performs actions when the player uses the Item. * diff --git a/src/esieequest/model/items/Transponder.java b/src/esieequest/model/items/Transponder.java deleted file mode 100644 index 7ed7ecc..0000000 --- a/src/esieequest/model/items/Transponder.java +++ /dev/null @@ -1,25 +0,0 @@ -package esieequest.model.items; - -import esieequest.model.Game; -import esieequest.view.Viewable; - -/** - * The transponder. - * - * @author Pacien TRAN-GIRARD - */ -public class Transponder extends SimpleItem { - - /** - * Creates a Transponder. - */ - public Transponder() { - super("Transponder", 0, false); - } - - @Override - public void use(final Game game, final Viewable view) { - // TODO: only usable with the bootloader on the roundabout - } - -} -- cgit v1.2.3