From bd639caa0bbf010c415d197b93d0f30a6cb8f1e4 Mon Sep 17 00:00:00 2001
From: Pacien TRAN-GIRARD
Date: Thu, 27 Feb 2014 14:53:05 +0100
Subject: Code refactoring to match MVC
---
.../wordpress/tipsforjava/swing/StretchIcon.java | 372 +++++++++++++++++++++
src/esieequest/Command.java | 70 ----
src/esieequest/CommandWords.java | 45 ---
src/esieequest/Game.java | 29 --
src/esieequest/GameEngine.java | 271 ---------------
src/esieequest/Main.java | 44 ++-
src/esieequest/Parser.java | 60 ----
src/esieequest/Room.java | 111 ------
src/esieequest/UserInterface.java | 151 ---------
src/esieequest/controller/GameEngine.java | 51 +++
src/esieequest/controller/Interpreter.java | 68 ++++
src/esieequest/controller/Parser.java | 31 ++
src/esieequest/controller/Performer.java | 73 ++++
src/esieequest/controller/package-info.java | 8 +
src/esieequest/model/Game.java | 223 ++++++++++++
src/esieequest/model/Room.java | 109 ++++++
src/esieequest/model/command/Command.java | 35 ++
src/esieequest/model/command/CommandWord.java | 43 +++
src/esieequest/model/command/package-info.java | 8 +
src/esieequest/model/package-info.java | 8 +
src/esieequest/package-info.java | 10 +-
src/esieequest/view/Applet.java | 27 ++
src/esieequest/view/Console.java | 61 ++++
src/esieequest/view/UserInterface.java | 247 ++++++++++++++
src/esieequest/view/View.java | 23 ++
src/esieequest/view/Window.java | 35 ++
src/esieequest/view/package-info.java | 8 +
.../nikiroo/utils/gui/JBackgroundPanel.java | 308 +++++++++++++++++
28 files changed, 1784 insertions(+), 745 deletions(-)
create mode 100644 src/com/wordpress/tipsforjava/swing/StretchIcon.java
delete mode 100644 src/esieequest/Command.java
delete mode 100644 src/esieequest/CommandWords.java
delete mode 100644 src/esieequest/Game.java
delete mode 100644 src/esieequest/GameEngine.java
delete mode 100644 src/esieequest/Parser.java
delete mode 100644 src/esieequest/Room.java
delete mode 100644 src/esieequest/UserInterface.java
create mode 100644 src/esieequest/controller/GameEngine.java
create mode 100644 src/esieequest/controller/Interpreter.java
create mode 100644 src/esieequest/controller/Parser.java
create mode 100644 src/esieequest/controller/Performer.java
create mode 100644 src/esieequest/controller/package-info.java
create mode 100644 src/esieequest/model/Game.java
create mode 100644 src/esieequest/model/Room.java
create mode 100644 src/esieequest/model/command/Command.java
create mode 100644 src/esieequest/model/command/CommandWord.java
create mode 100644 src/esieequest/model/command/package-info.java
create mode 100644 src/esieequest/model/package-info.java
create mode 100644 src/esieequest/view/Applet.java
create mode 100644 src/esieequest/view/Console.java
create mode 100644 src/esieequest/view/UserInterface.java
create mode 100644 src/esieequest/view/View.java
create mode 100644 src/esieequest/view/Window.java
create mode 100644 src/esieequest/view/package-info.java
create mode 100644 src/net/homelinux/nikiroo/utils/gui/JBackgroundPanel.java
(limited to 'src')
diff --git a/src/com/wordpress/tipsforjava/swing/StretchIcon.java b/src/com/wordpress/tipsforjava/swing/StretchIcon.java
new file mode 100644
index 0000000..667f1cd
--- /dev/null
+++ b/src/com/wordpress/tipsforjava/swing/StretchIcon.java
@@ -0,0 +1,372 @@
+/**
+ * @(#)StretchIcon.java 1.0 03/27/12
+ */
+package com.wordpress.tipsforjava.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.image.ImageObserver;
+import java.net.URL;
+import javax.swing.ImageIcon;
+
+/**
+ * An Icon
that scales its image to fill the component area,
+ * excluding any border or insets, optionally maintaining the image's aspect
+ * ratio by padding and centering the scaled image horizontally or vertically.
+ *
+ * The class is a drop-in replacement for ImageIcon
.
+ *
+ * As the size of the Icon is determined by the size of the component in which
+ * it is displayed, StretchIcon
must only be used in conjunction
+ * with a component and layout that does not depend on the size of the
+ * component's Icon.
+ *
+ * @version 1.0 03/22/12
+ * @author Darryl
+ */
+public class StretchIcon extends ImageIcon {
+
+ /**
+ * Determines whether the aspect ratio of the image is maintained. Set to
+ * false
to distort the image to fill the component.
+ */
+ protected boolean proportionate = true;
+
+ /**
+ * Creates a StretchIcon
from an array of bytes.
+ *
+ * @param imageData
+ * an array of pixels in an image format supported by the AWT
+ * Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
+ *
+ * @see ImageIcon#ImageIcon(byte[])
+ */
+ public StretchIcon(byte[] imageData) {
+ super(imageData);
+ }
+
+ /**
+ * Creates a StretchIcon
from an array of bytes with the
+ * specified behavior.
+ *
+ * @param imageData
+ * an array of pixels in an image format supported by the AWT
+ * Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(byte[])
+ */
+ public StretchIcon(byte[] imageData, boolean proportionate) {
+ super(imageData);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon
from an array of bytes.
+ *
+ * @param imageData
+ * an array of pixels in an image format supported by the AWT
+ * Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
+ * @param description
+ * a brief textual description of the image
+ *
+ * @see ImageIcon#ImageIcon(byte[], java.lang.String)
+ */
+ public StretchIcon(byte[] imageData, String description) {
+ super(imageData, description);
+ }
+
+ /**
+ * Creates a StretchIcon
from an array of bytes with the
+ * specified behavior.
+ *
+ * @see ImageIcon#ImageIcon(byte[])
+ * @param imageData
+ * an array of pixels in an image format supported by the AWT
+ * Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
+ * @param description
+ * a brief textual description of the image
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(byte[], java.lang.String)
+ */
+ public StretchIcon(byte[] imageData, String description, boolean proportionate) {
+ super(imageData, description);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon from the image.
+ *
+ * @param image
+ * the image
+ *
+ * @see ImageIcon#ImageIcon(java.awt.Image)
+ */
+ public StretchIcon(Image image) {
+ super(image);
+ }
+
+ /**
+ * Creates a StretchIcon from the image with the specifiec behavior.
+ *
+ * @param image
+ * the image
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(java.awt.Image)
+ */
+ public StretchIcon(Image image, boolean proportionate) {
+ super(image);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon from the image.
+ *
+ * @param image
+ * the image
+ * @param description
+ * a brief textual description of the image
+ *
+ * @see ImageIcon#ImageIcon(java.awt.Image, java.lang.String)
+ */
+ public StretchIcon(Image image, String description) {
+ super(image, description);
+ }
+
+ /**
+ * Creates a StretchIcon from the image with the specified behavior.
+ *
+ * @param image
+ * the image
+ * @param description
+ * a brief textual description of the image
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(java.awt.Image, java.lang.String)
+ */
+ public StretchIcon(Image image, String description, boolean proportionate) {
+ super(image, description);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon from the specified file.
+ *
+ * @param filename
+ * a String specifying a filename or path
+ *
+ * @see ImageIcon#ImageIcon(java.lang.String)
+ */
+ public StretchIcon(String filename) {
+ super(filename);
+ }
+
+ /**
+ * Creates a StretchIcon from the specified file with the specified
+ * behavior.
+ *
+ * @param filename
+ * a String specifying a filename or path
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(java.lang.String)
+ */
+ public StretchIcon(String filename, boolean proportionate) {
+ super(filename);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon from the specified file.
+ *
+ * @param filename
+ * a String specifying a filename or path
+ * @param description
+ * a brief textual description of the image
+ *
+ * @see ImageIcon#ImageIcon(java.lang.String, java.lang.String)
+ */
+ public StretchIcon(String filename, String description) {
+ super(filename, description);
+ }
+
+ /**
+ * Creates a StretchIcon from the specified file with the specified
+ * behavior.
+ *
+ * @param filename
+ * a String specifying a filename or path
+ * @param description
+ * a brief textual description of the image
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(java.awt.Image, java.lang.String)
+ */
+ public StretchIcon(String filename, String description, boolean proportionate) {
+ super(filename, description);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon from the specified URL.
+ *
+ * @param location
+ * the URL for the image
+ *
+ * @see ImageIcon#ImageIcon(java.net.URL)
+ */
+ public StretchIcon(URL location) {
+ super(location);
+ }
+
+ /**
+ * Creates a StretchIcon from the specified URL with the specified behavior.
+ *
+ * @param location
+ * the URL for the image
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(java.net.URL)
+ */
+ public StretchIcon(URL location, boolean proportionate) {
+ super(location);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Creates a StretchIcon from the specified URL.
+ *
+ * @param location
+ * the URL for the image
+ * @param description
+ * a brief textual description of the image
+ *
+ * @see ImageIcon#ImageIcon(java.net.URL, java.lang.String)
+ */
+ public StretchIcon(URL location, String description) {
+ super(location, description);
+ }
+
+ /**
+ * Creates a StretchIcon from the specified URL with the specified behavior.
+ *
+ * @param location
+ * the URL for the image
+ * @param description
+ * a brief textual description of the image
+ * @param proportionate
+ * true
to retain the image's aspect ratio,
+ * false
to allow distortion of the image to fill
+ * the component.
+ *
+ * @see ImageIcon#ImageIcon(java.net.URL, java.lang.String)
+ */
+ public StretchIcon(URL location, String description, boolean proportionate) {
+ super(location, description);
+ this.proportionate = proportionate;
+ }
+
+ /**
+ * Paints the icon. The image is reduced or magnified to fit the component
+ * to which it is painted.
+ *
+ * If the proportion has not been specified, or has been specified as
+ * true
, the aspect ratio of the image will be preserved by
+ * padding and centering the image horizontally or vertically. Otherwise the
+ * image may be distorted to fill the component it is painted to.
+ *
+ * If this icon has no image observer,this method uses the c
+ * component as the observer.
+ *
+ * @param c
+ * the component to which the Icon is painted. This is used as
+ * the observer if this icon has no image observer
+ * @param g
+ * the graphics context
+ * @param x
+ * not used.
+ * @param y
+ * not used.
+ *
+ * @see ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
+ */
+ @Override
+ public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
+ if (getImage() == null) {
+ return;
+ }
+ Insets insets = ((Container) c).getInsets();
+ x = insets.left;
+ y = insets.top;
+
+ int w = c.getWidth() - x - insets.right;
+ int h = c.getHeight() - y - insets.bottom;
+ Image image = getImage();
+
+ if (proportionate) {
+ int iw = image.getWidth(c);
+ int ih = image.getHeight(c);
+
+ if (iw * h < ih * w) {
+ iw = (h * iw) / ih;
+ x += (w - iw) / 2;
+ w = iw;
+ } else {
+ ih = (w * ih) / iw;
+ y += (h - ih) / 2;
+ h = ih;
+ }
+ }
+
+ ImageObserver io = getImageObserver();
+ g.drawImage(image, x, y, w, h, io == null ? c : io);
+ }
+
+ /**
+ * Overridden to return 0. The size of this Icon is determined by the size
+ * of the component.
+ *
+ * @return 0
+ */
+ @Override
+ public int getIconWidth() {
+ return 0;
+ }
+
+ /**
+ * Overridden to return 0. The size of this Icon is determined by the size
+ * of the component.
+ *
+ * @return 0
+ */
+ @Override
+ public int getIconHeight() {
+ return 0;
+ }
+}
\ No newline at end of file
diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java
deleted file mode 100644
index 14c3d32..0000000
--- a/src/esieequest/Command.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package esieequest;
-
-/**
- * This class holds information about a command that was issued by the user. A
- * command currently consists of two strings: a command word and a second word
- * (for example, if the command was "take map", then the two strings obviously
- * are "take" and "map").
- *
- * The way this is used is: Commands are already checked for being valid command
- * words. If the user entered an invalid command (a word that is not known) then
- * the command word is .
- *
- * If the command had only one word, then the second word is .
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class Command {
- private String aCommandWord;
- private String aSecondWord;
-
- /**
- * Create a command object. First and second word must be supplied, but
- * either one (or both) can be null.
- *
- * @param firstWord
- * The first word of the command. Null if the command was not
- * recognised.
- * @param secondWord
- * The second word of the command.
- */
- public Command(final String pFirstWord, final String pSecondWord) {
- this.aCommandWord = pFirstWord;
- this.aSecondWord = pSecondWord;
- }
-
- /**
- * Return the command word (the first word) of this command. If the command
- * was not understood, the result is null.
- *
- * @return The command word.
- */
- public String getCommandWord() {
- return this.aCommandWord;
- }
-
- /**
- * @return The second word of this command. Returns null if there was no
- * second word.
- */
- public String getSecondWord() {
- return this.aSecondWord;
- }
-
- /**
- * @return true if this command was not understood.
- */
- public boolean isUnknown() {
- return this.aCommandWord == null;
- }
-
- /**
- * @return true if the command has a second word.
- */
- public boolean hasSecondWord() {
- return this.aSecondWord != null;
- }
-}
diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java
deleted file mode 100644
index e2d50f5..0000000
--- a/src/esieequest/CommandWords.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package esieequest;
-
-/**
- * This class holds an enumeration table of all command words known to the game.
- * It is used to recognize commands as they are typed in.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class CommandWords {
- private static final String[] sValidCommands = { "go", "quit", "help", "look", "eat" };
-
- /**
- * Constructor - initialize the command words.
- */
- public CommandWords() {
-
- }
-
- /**
- * Check whether a given String is a valid command word.
- *
- * @return true if a given string is a valid command, false if it isn't.
- */
- public boolean isCommand(final String pString) {
- for (int i = 0; i < sValidCommands.length; i++) {
- if (sValidCommands[i].equals(pString))
- return true;
- }
- return false;
- }
-
- /**
- * Print all valid commands to System.out.
- */
- public String getCommandList() {
- StringBuilder vStrBuilder = new StringBuilder();
- for (String vCommand : sValidCommands) {
- vStrBuilder.append(" ").append(vCommand);
- }
- return vStrBuilder.toString();
- }
-}
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java
deleted file mode 100644
index a35cfb4..0000000
--- a/src/esieequest/Game.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package esieequest;
-
-import javax.swing.JApplet;
-
-/**
- * The game engine.
- *
- * This class creates and initializes all the others: it creates all rooms,
- * creates the parser and starts the game. It also evaluates and executes the
- * commands that the parser returns.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class Game extends JApplet {
- private UserInterface aGui;
- private GameEngine aEngine;
-
- /**
- * Create the game and initialise its internal map.
- */
- public Game() {
- this.aEngine = new GameEngine();
- this.aGui = new UserInterface(this.aEngine);
- this.aEngine.setGUI(this.aGui);
- }
-}
diff --git a/src/esieequest/GameEngine.java b/src/esieequest/GameEngine.java
deleted file mode 100644
index c20c70c..0000000
--- a/src/esieequest/GameEngine.java
+++ /dev/null
@@ -1,271 +0,0 @@
-package esieequest;
-
-import java.util.HashMap;
-
-/**
- * This class creates all rooms, creates the parser and starts the game. It also
- * evaluates and executes the commands that the parser returns.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class GameEngine {
- private HashMap aRooms;
- private Room aCurrentRoom;
- private Parser aParser;
- private UserInterface aGui;
-
- /**
- * Create the game and initialize its internal map.
- */
- public GameEngine() {
- this.aRooms = new HashMap();
- this.aParser = new Parser();
- this.createRooms();
- }
-
- public void setGUI(UserInterface pUserInterface) {
- this.aGui = pUserInterface;
- this.printWelcome();
- }
-
- /**
- * Create all the rooms and link their exits together.
- */
- private void createRooms() {
- // create rooms
- this.aRooms.put("AmphitheaterSeat", new Room("in the amphitheater"));
- this.aRooms.put("AmphitheaterStage", new Room("on the amphitheater stage"));
-
- this.aRooms.put("CafeteriaStreet", new Room("in the main corridor, in front of the cafeteria"));
- this.aRooms.put("Cafeteria", new Room("at the cafeteria"));
-
- this.aRooms.put("EsieespaceStreet", new Room("in the main corridor, in front of the ESIEEspace HQ"));
- this.aRooms.put("EsieespaceFront", new Room("in front of the ESIEEspace HQ"));
- this.aRooms.put("EsieespaceEntrance", new Room("at the ESIEEspace HQ entrance"));
- this.aRooms.put("Esieespace", new Room("in the ESIEEspace HQ"));
-
- this.aRooms.put("ClubnixStreet", new Room("in the main corridor, in front of the Club*Nix"));
- this.aRooms.put("ClubnixFront", new Room("in front of the Club*Nix"));
- this.aRooms.put("ClubnixEntrance", new Room("at the Club*Nix entrance"));
- this.aRooms.put("Clubnix", new Room("in the Club*Nix"));
-
- this.aRooms.put("EntranceStreet", new Room("in the main corridor, at the reception"));
- this.aRooms.put("EntranceStairs", new Room("on the main entrance stairs"));
- this.aRooms.put("EntranceRoundabout", new Room("on the roundabout"));
-
- this.aRooms.put("WingStreet", new Room("in font of wing #3"));
- this.aRooms.put("WingCorridorOne", new Room("in the corridor in wing #3, on the ground floor"));
- this.aRooms.put("WingStairsOne", new Room("in the stairwell on the ground floor"));
- this.aRooms.put("WingStairsTwo", new Room("in the stairwell on the first floor"));
- this.aRooms.put("WingCorridorTwo", new Room("in the corridor in wind #3, on the first floor"));
- this.aRooms.put("WingCorridorTwoOffice", new Room("in front of the office #3254"));
- this.aRooms.put("WingOffice", new Room("in the office #3254"));
-
- this.aRooms.put("OffscriptEat", new Room("somewhere implementing hunger"));
- this.aRooms.put("OffscriptEatPantry", new Room("in the pantry"));
- this.aRooms.put("OffscriptTake", new Room("somewhere implementing weight"));
- this.aRooms.put("OffscriptTakeStorageroom", new Room("in a storage room"));
- this.aRooms.put("OffscriptTimeout", new Room("somewhere implementing time"));
- this.aRooms.put("OffscriptTimeoutCountdownroom", new Room("in a dangerous room"));
- this.aRooms.put("OffscriptTrapdoor", new Room("somewhere implementing a trap"));
- this.aRooms.put("OffscriptTrapdoorDeadend", new Room("trapped"));
- this.aRooms.put("OffscriptBeamer", new Room("somewhere implementing teleportation"));
- this.aRooms.put("OffscriptBeamerAnchor", new Room("on a checkpoint"));
- this.aRooms.put("OffscriptLock", new Room("somewhere implementing a doorlock"));
- this.aRooms.put("OffscriptLockLockedroom", new Room("in a locked room that is not anymore"));
- this.aRooms.put("OffscriptAlea", new Room("somewhere implementing alea"));
- this.aRooms.put("OffscriptAleaRoomrandomizer", new Room("in a weird room that will transport you somewhere else"));
- this.aRooms.put("OffscriptMovingcharacter", new Room("somewhere implementing a moving character"));
- this.aRooms.put("OffscriptMovingcharacterMo", new Room("in M-O's room"));
-
- // connect rooms
- this.aRooms.get("AmphitheaterSeat").setExit("north", this.aRooms.get("AmphitheaterStage"));
- this.aRooms.get("AmphitheaterStage").setExit("west", this.aRooms.get("Cafeteria"));
-
- this.aRooms.get("CafeteriaStreet").setExit("south", this.aRooms.get("Cafeteria"));
- this.aRooms.get("CafeteriaStreet").setExit("east", this.aRooms.get("EsieespaceStreet"));
- this.aRooms.get("Cafeteria").setExit("north", this.aRooms.get("CafeteriaStreet"));
- this.aRooms.get("Cafeteria").setExit("east", this.aRooms.get("AmphitheaterStage"));
-
- this.aRooms.get("EsieespaceStreet").setExit("west", this.aRooms.get("Cafeteria"));
- this.aRooms.get("EsieespaceStreet").setExit("south", this.aRooms.get("EsieespaceFront"));
- this.aRooms.get("EsieespaceStreet").setExit("east", this.aRooms.get("EntranceStreet"));
- this.aRooms.get("EsieespaceFront").setExit("north", this.aRooms.get("EsieespaceStreet"));
- this.aRooms.get("EsieespaceFront").setExit("east", this.aRooms.get("EsieespaceEntrance"));
- this.aRooms.get("EsieespaceEntrance").setExit("north", this.aRooms.get("Esieespace"));
- this.aRooms.get("EsieespaceEntrance").setExit("west", this.aRooms.get("EsieespaceFront"));
- this.aRooms.get("Esieespace").setExit("south", this.aRooms.get("EsieespaceEntrance"));
-
- this.aRooms.get("ClubnixStreet").setExit("west", this.aRooms.get("WingStreet"));
- this.aRooms.get("ClubnixStreet").setExit("south", this.aRooms.get("ClubnixFront"));
- this.aRooms.get("ClubnixFront").setExit("north", this.aRooms.get("ClubnixStreet"));
- this.aRooms.get("ClubnixFront").setExit("east", this.aRooms.get("ClubnixEntrance"));
- this.aRooms.get("ClubnixEntrance").setExit("north", this.aRooms.get("Clubnix"));
- this.aRooms.get("ClubnixEntrance").setExit("west", this.aRooms.get("ClubnixFront"));
- this.aRooms.get("Clubnix").setExit("south", this.aRooms.get("ClubnixEntrance"));
-
- this.aRooms.get("EntranceStreet").setExit("west", this.aRooms.get("EsieespaceStreet"));
- this.aRooms.get("EntranceStreet").setExit("south", this.aRooms.get("EntranceStairs"));
- this.aRooms.get("EntranceStreet").setExit("east", this.aRooms.get("WingStreet"));
- this.aRooms.get("EntranceStairs").setExit("north", this.aRooms.get("EntranceStreet"));
- this.aRooms.get("EntranceStairs").setExit("south", this.aRooms.get("EntranceRoundabout"));
- this.aRooms.get("EntranceRoundabout").setExit("north", this.aRooms.get("EntranceStairs"));
-
- this.aRooms.get("WingStreet").setExit("north", this.aRooms.get("WingCorridorOne"));
- this.aRooms.get("WingStreet").setExit("west", this.aRooms.get("EntranceStreet"));
- this.aRooms.get("WingStreet").setExit("east", this.aRooms.get("ClubnixStreet"));
- this.aRooms.get("WingCorridorOne").setExit("west", this.aRooms.get("WingStairsOne"));
- this.aRooms.get("WingCorridorOne").setExit("south", this.aRooms.get("WingStreet"));
- this.aRooms.get("WingCorridorOne").setExit("east", this.aRooms.get("OffscriptEat"));
- this.aRooms.get("WingStairsOne").setExit("south", this.aRooms.get("WingStairsTwo"));
- this.aRooms.get("WingStairsOne").setExit("up", this.aRooms.get("WingStairsTwo"));
- this.aRooms.get("WingStairsOne").setExit("east", this.aRooms.get("WingCorridorOne"));
- this.aRooms.get("WingStairsTwo").setExit("south", this.aRooms.get("WingStairsOne"));
- this.aRooms.get("WingStairsTwo").setExit("down", this.aRooms.get("WingStairsOne"));
- this.aRooms.get("WingStairsTwo").setExit("east", this.aRooms.get("WingCorridorTwo"));
- this.aRooms.get("WingCorridorTwo").setExit("north", this.aRooms.get("WingCorridorTwoOffice"));
- this.aRooms.get("WingCorridorTwoOffice").setExit("south", this.aRooms.get("WingCorridorTwo"));
- this.aRooms.get("WingCorridorTwoOffice").setExit("east", this.aRooms.get("WingOffice"));
- this.aRooms.get("WingOffice").setExit("west", this.aRooms.get("WingCorridorTwoOffice"));
-
- this.aRooms.get("OffscriptEat").setExit("north", this.aRooms.get("OffscriptEatPantry"));
- this.aRooms.get("OffscriptEat").setExit("west", this.aRooms.get("WingCorridorOne"));
- this.aRooms.get("OffscriptEat").setExit("east", this.aRooms.get("OffscriptTake"));
- this.aRooms.get("OffscriptEatPantry").setExit("south", this.aRooms.get("OffscriptEat"));
- this.aRooms.get("OffscriptTake").setExit("north", this.aRooms.get("OffscriptTakeStorageroom"));
- this.aRooms.get("OffscriptTake").setExit("west", this.aRooms.get("OffscriptEat"));
- this.aRooms.get("OffscriptTake").setExit("east", this.aRooms.get("OffscriptTimeout"));
- this.aRooms.get("OffscriptTakeStorageroom").setExit("south", this.aRooms.get("OffscriptTake"));
- this.aRooms.get("OffscriptTimeout").setExit("north", this.aRooms.get("OffscriptTimeoutCountdownroom"));
- this.aRooms.get("OffscriptTimeout").setExit("west", this.aRooms.get("OffscriptTakeStorageroom"));
- this.aRooms.get("OffscriptTimeout").setExit("east", this.aRooms.get("OffscriptTrapdoor"));
- this.aRooms.get("OffscriptTimeoutCountdownroom").setExit("south", this.aRooms.get("OffscriptTimeout"));
- this.aRooms.get("OffscriptTrapdoor").setExit("north", this.aRooms.get("OffscriptTrapdoorDeadend"));
- this.aRooms.get("OffscriptTrapdoor").setExit("west", this.aRooms.get("OffscriptTimeout"));
- this.aRooms.get("OffscriptTrapdoor").setExit("east", this.aRooms.get("OffscriptBeamer"));
- this.aRooms.get("OffscriptTrapdoorDeadend").setExit("south", this.aRooms.get("OffscriptTrapdoor"));
- this.aRooms.get("OffscriptBeamer").setExit("north", this.aRooms.get("OffscriptBeamerAnchor"));
- this.aRooms.get("OffscriptBeamer").setExit("west", this.aRooms.get("OffscriptTrapdoor"));
- this.aRooms.get("OffscriptBeamer").setExit("east", this.aRooms.get("OffscriptLock"));
- this.aRooms.get("OffscriptBeamerAnchor").setExit("south", this.aRooms.get("OffscriptBeamer"));
- this.aRooms.get("OffscriptLock").setExit("north", this.aRooms.get("OffscriptLockLockedroom"));
- this.aRooms.get("OffscriptLock").setExit("west", this.aRooms.get("OffscriptBeamer"));
- this.aRooms.get("OffscriptLock").setExit("east", this.aRooms.get("OffscriptAlea"));
- this.aRooms.get("OffscriptLockLockedroom").setExit("south", this.aRooms.get("OffscriptLock"));
- this.aRooms.get("OffscriptAlea").setExit("north", this.aRooms.get("OffscriptAleaRoomrandomizer"));
- this.aRooms.get("OffscriptAlea").setExit("west", this.aRooms.get("OffscriptLock"));
- this.aRooms.get("OffscriptAlea").setExit("east", this.aRooms.get("OffscriptMovingcharacter"));
- this.aRooms.get("OffscriptAleaRoomrandomizer").setExit("south", this.aRooms.get("OffscriptAlea"));
- this.aRooms.get("OffscriptMovingcharacter").setExit("north", this.aRooms.get("OffscriptMovingcharacterMo"));
- this.aRooms.get("OffscriptMovingcharacter").setExit("west", this.aRooms.get("OffscriptAlea"));
-
- // set the starting room
- this.aCurrentRoom = this.aRooms.get("AmphitheaterSeat");
- }
-
- /**
- * Try to go in one direction. If there is an exit, enter the new room,
- * otherwise print an error message.
- */
- public void goRoom(final Command pCommand) {
- if (!pCommand.hasSecondWord()) {
- this.aGui.println("Go where?");
- return;
- }
-
- Room vNextRoom = aCurrentRoom.getExit(pCommand.getSecondWord());
-
- if (vNextRoom == null) {
- this.aGui.println("There is no door!");
- return;
- }
-
- this.aCurrentRoom = vNextRoom;
- this.aGui.println(this.aCurrentRoom.getLongDescription());
-
- if (this.aCurrentRoom.getImageName() != null) {
- this.aGui.showImage(this.aCurrentRoom.getImageName());
- }
- }
-
- /**
- * Print out the opening message for the player.
- */
- private void printWelcome() {
- this.aGui.println("Welcome to ESIEEquest");
- this.aGui.println("ESIEEquest is a new, incredibly surprising adventure game.");
- this.aGui.println("Type 'help' if you need help.");
- this.aGui.println("");
- this.look();
- this.aGui.showImage(this.aCurrentRoom.getImageName());
- }
-
- /**
- * Print out some help information. Here we print some stupid, cryptic
- * message and a list of the command words.
- */
- private void printHelp() {
- this.aGui.println("You are lost. You are alone. ");
- this.aGui.println("You wander around at the university.");
- this.aGui.println("");
- this.aGui.println("Your command words are:");
- this.aGui.println(this.aParser.showCommands());
- }
-
- private void look() {
- this.aGui.println(this.aCurrentRoom.getLongDescription());
- }
-
- private void eat() {
- this.aGui.println("You have eaten now and you are not hungry any more.");
- }
-
- /**
- * "Quit" was entered.F
- */
- private void endGame() {
- this.aGui.println("Thank you for playing. Good bye.");
- this.aGui.enable(false);
- this.aGui.killFrame();
- }
-
- /**
- * Given a command, process (that is: execute) the command.
- *
- * @param command
- * The command to be processed.
- * @return true If the command ends the game, false otherwise.
- */
- private void processCommand(final Command pCommand) {
- if (pCommand.getCommandWord() != null) {
- switch (pCommand.getCommandWord()) {
- case "go":
- this.goRoom(pCommand);
- return;
- case "look":
- this.look();
- return;
- case "eat":
- this.eat();
- return;
- case "help":
- this.printHelp();
- return;
- case "quit":
- this.endGame();
- return;
- }
- }
- this.aGui.println("I don't know what you mean...");
- return;
- }
-
- public void interpretCommand(final String pCommandLine) {
- this.aGui.println(pCommandLine);
- Command vCommand = this.aParser.getCommand(pCommandLine);
- this.processCommand(vCommand);
- }
-}
diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java
index 8cbea80..add0fb1 100755
--- a/src/esieequest/Main.java
+++ b/src/esieequest/Main.java
@@ -1,20 +1,52 @@
package esieequest;
+import javax.swing.JApplet;
+
+import esieequest.controller.GameEngine;
+import esieequest.model.Game;
+import esieequest.view.Applet;
+import esieequest.view.Console;
+import esieequest.view.View;
+import esieequest.view.Window;
+
/**
- * The Main class
- *
* This class instantiates the game and makes it possible to run it via the
- * command line.
+ * command line, as a graphical application in a window or as an applet.
*
* @author Pacien TRAN-GIRARD
* @author Benoit LUBRANO DI SBARAGLIONE
*
* @version February 2014
*/
-public class Main {
+public class Main extends JApplet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1726402114771940798L;
+
+ public void init() {
+ // applet
+ Game vGame = new Game();
+ Applet vApplet = new Applet(vGame, this);
+ vGame.addObserver(vApplet);
+ GameEngine vGameEngine = new GameEngine(vGame, vApplet);
+ }
+
+ public static void main(final String[] pArgs) {
+ // cli or standalone
+ Game vGame = new Game();
+ View vView;
+
+ if (pArgs.length != 0) {
+ vView = new Console(vGame);
+
+ } else {
+ vView = new Window(vGame);
+ }
- public static void main(String[] args) {
- Game game1 = new Game();
+ vGame.addObserver(vView);
+ GameEngine vGameEngine = new GameEngine(vGame, vView);
}
}
diff --git a/src/esieequest/Parser.java b/src/esieequest/Parser.java
deleted file mode 100644
index a061abf..0000000
--- a/src/esieequest/Parser.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package esieequest;
-
-import java.util.Scanner;
-import java.util.StringTokenizer;
-
-/**
- * This parser reads user input and tries to interpret it as an "Adventure"
- * command. Every time it is called it reads a line from the terminal and tries
- * to interpret the line as a two word command. It returns the command as an
- * object of class Command.
- *
- * The parser has a set of known command words. It checks user input against the
- * known commands, and if the input is not one of the known commands, it returns
- * a command object that is marked as an unknown command.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class Parser {
- private CommandWords aValidCommands;
-
- /**
- * Create a parser to read from the terminal window.
- */
- public Parser() {
- this.aValidCommands = new CommandWords();
- }
-
- /**
- * @return The next command from the user.
- */
- public Command getCommand(String pInputLine) {
- String vWord1 = null;
- String vWord2 = null;
-
- StringTokenizer vTokenizer = new StringTokenizer(pInputLine);
-
- if (vTokenizer.hasMoreTokens()) {
- vWord1 = vTokenizer.nextToken();
- if (vTokenizer.hasMoreTokens()) {
- vWord2 = vTokenizer.nextToken();
- }
- }
-
- if (this.aValidCommands.isCommand(vWord1)) {
- return new Command(vWord1, vWord2);
- } else {
- return new Command(null, vWord2);
- }
- }
-
- /**
- * Print out a list of valid command words.
- */
- public String showCommands() {
- return this.aValidCommands.getCommandList();
- }
-}
diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java
deleted file mode 100644
index 096463e..0000000
--- a/src/esieequest/Room.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package esieequest;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A room.
- *
- * A "Room" represents one location in the scenery of the game. It is connected
- * to other rooms via exits. The exits are labeled north, east, south, west. For
- * each direction, the room stores a reference to the neighboring room, or null
- * if there is no exit in that direction.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class Room {
-
- private String aDescription;
- private HashMap aExits;
- private String aImageName;
-
- /**
- * Create a room described "description". Initially, it has no exits.
- * "description" is something like "a kitchen" or "an open court yard".
- *
- * @param description
- * The room's description.
- * @param image
- * name The room's image
- */
- public Room(final String pDescription, final String pImageName) {
- this.aDescription = pDescription;
- this.aExits = new HashMap();
- this.aImageName = pImageName;
- }
-
- public Room(final String pDescription) {
- this(pDescription, null);
- }
-
- /**
- * Return the description of the room (the one that was defined in the
- * constructor).
- */
- public String getShortDescription() {
- return this.aDescription;
- }
-
- /**
- * Return a long description of this room, of the form:
- *
- * You are in the kitchen.
- *
- * Exits: north west
- *
- * @return A description of the room, including exits.
- */
- public String getLongDescription() {
- String vLongDescription = "You are now " + this.aDescription + ".\n";
- vLongDescription += getExitString();
- return vLongDescription;
- }
-
- /**
- * Define an exit from this room.
- *
- * @param direction
- * The direction of the exit.
- * @param neighbor
- * The room in the given direction.
- */
- public void setExit(String direction, Room neighbor) {
- this.aExits.put(direction, neighbor);
- }
-
- /**
- * Return the room that is reached if we go from this room in direction
- * "direction". If there is no room in that direction, return null.
- */
- public Room getExit(String pDirection) {
- return this.aExits.get(pDirection);
- }
-
- /**
- * Return a description of the room's exits, for example
- * "Exits: north west".
- *
- * @return A description of the available exits.
- */
- public String getExitString() {
- StringBuilder vStrBuilder = new StringBuilder("Available exits:");
- Set vKeys = this.aExits.keySet();
- for (Iterator vIter = vKeys.iterator(); vIter.hasNext();) {
- vStrBuilder.append(" ").append(vIter.next());
- }
- vStrBuilder.append(".");
- return vStrBuilder.toString();
- }
-
- /**
- * Return a string describing the room's image name
- */
- public String getImageName() {
- return this.aImageName;
- }
-
-}
diff --git a/src/esieequest/UserInterface.java b/src/esieequest/UserInterface.java
deleted file mode 100644
index 0168b33..0000000
--- a/src/esieequest/UserInterface.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package esieequest;
-
-import javax.swing.*;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.io.IOException;
-import java.net.URL;
-import java.awt.image.*;
-
-/**
- * This class implements a simple graphical user interface with a text entry
- * area, a text output area and an optional aImage.
- *
- * @author Pacien TRAN-GIRARD
- * @author Benoit LUBRANO DI SBARAGLIONE
- *
- * @version February 2014
- */
-public class UserInterface implements ActionListener {
- private GameEngine aEngine;
- private JFrame aMyFrame;
- private JTextField aEntryField;
- private JTextArea aLog;
- private JLabel aImage;
-
- /**
- * Construct a UserInterface. As a parameter, a Game Engine (an object
- * processing and executing the game commands) is needed.
- *
- * @param gameEngine
- * The GameEngine object implementing the game logic.
- */
- public UserInterface(GameEngine pGameEngine) {
- this.aEngine = pGameEngine;
- this.createGUI();
- }
-
- /**
- * Print out some text into the text area.
- */
- public void print(String pText) {
- this.aLog.append(pText);
- this.aLog.setCaretPosition(this.aLog.getDocument().getLength());
- }
-
- /**
- * Print out some text into the text area, followed by a line break.
- */
- public void println(String pText) {
- this.print(pText + "\n");
- }
-
- /**
- * Show an image file in the interface.
- */
- public void showImage(String pImageName) {
- URL vImageURL = null;
- if (pImageName == null) {
- try {
- vImageURL = new URL("http://lxp.fr/i2JK1xE5Lr");
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- vImageURL = this.getClass().getClassLoader().getResource(pImageName);
- }
- ImageIcon vIcon = new ImageIcon(vImageURL);
- this.aImage.setIcon(vIcon);
- this.aMyFrame.pack();
- }
-
- /**
- * Enable or disable input in the input field.
- */
- public void enable(boolean pOn) {
- this.aEntryField.setEditable(pOn);
- if (!pOn) {
- this.aEntryField.getCaret().setBlinkRate(0);
- }
- }
-
- /**
- * Set up graphical user interface.
- */
- private void createGUI() {
- this.aMyFrame = new JFrame("ESIEEquest");
- this.aEntryField = new JTextField(34);
-
- this.aLog = new JTextArea();
- this.aLog.setEditable(false);
- JScrollPane vListScroller = new JScrollPane(this.aLog);
- vListScroller.setPreferredSize(new Dimension(200, 200));
- vListScroller.setMinimumSize(new Dimension(100, 100));
-
- JPanel vPanel = new JPanel();
- this.aImage = new JLabel();
-
- JButton vButtonHelp = new JButton("?");
- vButtonHelp.setActionCommand("help");
-
- vPanel.setLayout(new BorderLayout());
- vPanel.add(this.aImage, BorderLayout.NORTH);
- vPanel.add(vListScroller, BorderLayout.CENTER);
- vPanel.add(this.aEntryField, BorderLayout.SOUTH);
- vPanel.add(vButtonHelp, BorderLayout.WEST);
-
- this.aMyFrame.getContentPane().add(vPanel, BorderLayout.CENTER);
-
- // add some event listeners to some components
- this.aEntryField.addActionListener(this);
- vButtonHelp.addActionListener(this);
-
- this.aMyFrame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent pEvent) {
- System.exit(0);
- }
- });
-
- this.aMyFrame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- killFrame();
- }
- });
-
- this.aMyFrame.pack();
- this.aMyFrame.setVisible(true);
- this.aEntryField.requestFocus();
- }
-
- /**
- * Actionlistener interface for entry textfield.
- */
- public void actionPerformed(ActionEvent pEvent) {
- processCommand(pEvent.getActionCommand());
- }
-
- /**
- * A command has been entered. Read the command and do whatever is necessary
- * to process it.
- */
- private void processCommand(final String pInput) {
- this.aEntryField.setText("");
- this.aEngine.interpretCommand(pInput);
- }
-
- public void killFrame() {
- this.aMyFrame.setVisible(false);
- this.aMyFrame.dispose();
- }
-}
diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java
new file mode 100644
index 0000000..72de63a
--- /dev/null
+++ b/src/esieequest/controller/GameEngine.java
@@ -0,0 +1,51 @@
+package esieequest.controller;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import esieequest.model.Game;
+import esieequest.view.View;
+
+/**
+ * This class creates all rooms, creates the parser and starts the game. It also
+ * evaluates and executes the commands that the parser returns.
+ *
+ * @author Pacien TRAN-GIRARD
+ * @author Benoit LUBRANO DI SBARAGLIONE
+ *
+ * @version February 2014
+ */
+public class GameEngine implements ActionListener {
+
+ private Game aGame;
+ private View aView;
+
+ private Interpreter aInterpreter;
+
+ public GameEngine(final Game pGame, final View pView) {
+ this.aGame = pGame;
+ this.aView = pView;
+
+ this.aInterpreter = new Interpreter(this.aGame, this.aView);
+
+ this.aView.setActionListener(this);
+
+ this.startGame();
+ this.startView();
+ }
+
+ private void startGame() {
+ this.aGame.setRunning(true);
+ this.aInterpreter.interpret("new");
+ }
+
+ private void startView() {
+ this.aView.start();
+ }
+
+ @Override
+ public void actionPerformed(final ActionEvent pActionEvent) {
+ this.aInterpreter.interpret(pActionEvent.getActionCommand());
+ }
+
+}
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
new file mode 100644
index 0000000..1e2937b
--- /dev/null
+++ b/src/esieequest/controller/Interpreter.java
@@ -0,0 +1,68 @@
+/**
+ *
+ */
+package esieequest.controller;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.StringTokenizer;
+
+import esieequest.model.Game;
+import esieequest.model.command.Command;
+import esieequest.view.View;
+
+/**
+ * @author pacien
+ *
+ */
+public class Interpreter {
+
+ private Performer aPerformer;
+ private Parser aParser;
+
+ public Interpreter(final Game pGame, final View pView) {
+ this.aPerformer = new Performer(pGame, pView);
+ this.aParser = new Parser();
+ }
+
+ public void interpret(String pCommandString) {
+ Command vCommand = this.aParser.getCommand(pCommandString);
+ this.dispatch(vCommand);
+ }
+
+ public void dispatch(final Command pCommand) {
+ if (pCommand.getAction() != null) {
+ switch (pCommand.getAction()) {
+ case "new":
+ this.aPerformer.newGame();
+ return;
+ case "load":
+ this.aPerformer.loadGame();
+ return;
+ case "save":
+ this.aPerformer.saveGame();
+ return;
+ case "sound":
+ this.aPerformer.toggleSound();
+ return;
+ case "go":
+ this.aPerformer.goTo(pCommand.getOption());
+ return;
+ case "look":
+ this.aPerformer.look();
+ return;
+ case "eat":
+ this.aPerformer.eat();
+ return;
+ case "help":
+ this.aPerformer.showHelp();
+ return;
+ case "quit":
+ this.aPerformer.quitGame();
+ return;
+ }
+ }
+ this.aPerformer.showMessage("Unknown command.");
+ return;
+ }
+}
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java
new file mode 100644
index 0000000..bd36041
--- /dev/null
+++ b/src/esieequest/controller/Parser.java
@@ -0,0 +1,31 @@
+package esieequest.controller;
+
+import java.util.StringTokenizer;
+
+import esieequest.model.command.Command;
+
+public class Parser {
+
+ public Parser() {
+ }
+
+ public Command getCommand(final String pCommandString) {
+ StringTokenizer vTokenizer = new StringTokenizer(pCommandString);
+
+ String vAction = null;
+ String vOption = null;
+
+ if (vTokenizer.hasMoreTokens()) {
+ vAction = vTokenizer.nextToken();
+ if (vTokenizer.hasMoreTokens()) {
+ vOption = vTokenizer.nextToken();
+ }
+ }
+ return new Command(vAction, vOption);
+ }
+
+ private void validateCommand() {
+
+ }
+
+}
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
new file mode 100644
index 0000000..db52c4f
--- /dev/null
+++ b/src/esieequest/controller/Performer.java
@@ -0,0 +1,73 @@
+/**
+ *
+ */
+package esieequest.controller;
+
+import esieequest.model.Game;
+import esieequest.model.Room;
+import esieequest.view.View;
+
+/**
+ * @author pacien
+ *
+ */
+public class Performer {
+
+ private Game aGame;
+ private View aView;
+
+ public Performer(final Game pGame, final View pView) {
+ this.aGame = pGame;
+ this.aView = pView;
+ }
+
+ public void showMessage(final String pString) {
+ this.aView.showMessage(pString);
+ }
+
+ public void newGame() {
+ // this.loadGame(default game);
+ this.aView
+ .showMessage(this.aGame.getWelcomeMessage() + "\n" + this.aGame.getLocationInfo());
+ }
+
+ public void loadGame() {
+ this.aView.showMessage("Not implemented.");
+ }
+
+ public void saveGame() {
+ this.aView.showMessage("Not implemented.");
+ }
+
+ public void toggleSound() {
+ this.aView.showMessage("Not implemented.");
+ }
+
+ public void quitGame() {
+ this.aView.showMessage(this.aGame.getQuitMessage());
+ this.aGame.setRunning(false);
+ }
+
+ public void showHelp() {
+ this.aView.showMessage(this.aGame.getHelpMessage());
+ }
+
+ public void goTo(final String pDirection) {
+ Room vNextRoom = this.aGame.getRoomExit(pDirection);
+ if (vNextRoom != null) {
+ this.aGame.goToRoom(vNextRoom);
+ this.aView.showMessage(this.aGame.getLocationInfo());
+ } else {
+ this.aView.showMessage(this.aGame.getNoExitMessage());
+ }
+ }
+
+ public void look() {
+ this.aView.showMessage(this.aGame.getLocationInfo());
+ }
+
+ public void eat() {
+ this.aView.showMessage(this.aGame.getEatMessage());
+ }
+
+}
diff --git a/src/esieequest/controller/package-info.java b/src/esieequest/controller/package-info.java
new file mode 100644
index 0000000..4d6616c
--- /dev/null
+++ b/src/esieequest/controller/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author pacien
+ *
+ */
+package esieequest.controller;
\ No newline at end of file
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
new file mode 100644
index 0000000..ed7c3df
--- /dev/null
+++ b/src/esieequest/model/Game.java
@@ -0,0 +1,223 @@
+package esieequest.model;
+
+import java.util.Observable;
+import java.util.HashMap;
+
+/**
+ *
+ * @author Pacien TRAN-GIRARD
+ * @author Benoit LUBRANO DI SBARAGLIONE
+ *
+ * @version February 2014
+ */
+public class Game extends Observable {
+
+ private boolean aRunning;
+ private HashMap aRooms;
+ private Room aCurrentRoom;
+
+ public Game() {
+ this.aRunning = false;
+ this.aRooms = new HashMap();
+ this.aCurrentRoom = null;
+
+ this.createRooms();
+ this.linkRooms();
+ this.goToRoom("AmphitheaterSeat");
+ }
+
+ private void createRoom(final String pName, final String pDescription) {
+ this.aRooms.put(pName, new Room(pDescription));
+ }
+
+ private void setRoomExit(final String pRoomName, final String pDirection,
+ final String pExitRoomName) {
+ this.aRooms.get(pRoomName).setExit(pDirection, this.aRooms.get(pExitRoomName));
+ }
+
+ private void createRooms() {
+ this.createRoom("AmphitheaterSeat", "in the amphitheater");
+ this.createRoom("AmphitheaterStage", "on the amphitheater stage");
+
+ this.createRoom("CafeteriaStreet", "in the main corridor, in front of the cafeteria");
+ this.createRoom("Cafeteria", "at the cafeteria");
+
+ this.createRoom("EsieespaceStreet", "in the main corridor, in front of the ESIEEspace HQ");
+ this.createRoom("EsieespaceFront", "in front of the ESIEEspace HQ");
+ this.createRoom("EsieespaceEntrance", "at the ESIEEspace HQ entrance");
+ this.createRoom("Esieespace", "in the ESIEEspace HQ");
+
+ this.createRoom("ClubnixStreet", "in the main corridor, in front of the Club*Nix");
+ this.createRoom("ClubnixFront", "in front of the Club*Nix");
+ this.createRoom("ClubnixEntrance", "at the Club*Nix entrance");
+ this.createRoom("Clubnix", "in the Club*Nix");
+
+ this.createRoom("EntranceStreet", "in the main corridor, at the reception");
+ this.createRoom("EntranceStairs", "on the main entrance stairs");
+ this.createRoom("EntranceRoundabout", "on the roundabout");
+
+ this.createRoom("WingStreet", "in font of wing #3");
+ this.createRoom("WingCorridorOne", "in the corridor in wing #3, on the ground floor");
+ this.createRoom("WingStairsOne", "in the stairwell on the ground floor");
+ this.createRoom("WingStairsTwo", "in the stairwell on the first floor");
+ this.createRoom("WingCorridorTwo", "in the corridor in wind #3, on the first floor");
+ this.createRoom("WingCorridorTwoOffice", "in front of the office #3254");
+ this.createRoom("WingOffice", "in the office #3254");
+
+ this.createRoom("OffscriptEat", "somewhere implementing hunger");
+ this.createRoom("OffscriptEatPantry", "in the pantry");
+ this.createRoom("OffscriptTake", "somewhere implementing weight");
+ this.createRoom("OffscriptTakeStorageroom", "in a storage room");
+ this.createRoom("OffscriptTimeout", "somewhere implementing time");
+ this.createRoom("OffscriptTimeoutCountdownroom", "in a dangerous room");
+ this.createRoom("OffscriptTrapdoor", "somewhere implementing a trap");
+ this.createRoom("OffscriptTrapdoorDeadend", "trapped");
+ this.createRoom("OffscriptBeamer", "somewhere implementing teleportation");
+ this.createRoom("OffscriptBeamerAnchor", "on a checkpoint");
+ this.createRoom("OffscriptLock", "somewhere implementing a doorlock");
+ this.createRoom("OffscriptLockLockedroom", "in a locked room that is not anymore");
+ this.createRoom("OffscriptAlea", "somewhere implementing alea");
+ this.createRoom("OffscriptAleaRoomrandomizer",
+ "in a weird room that will transport you somewhere else");
+ this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character");
+ this.createRoom("OffscriptMovingcharacterMo", "in M-O's room");
+
+ }
+
+ private void linkRooms() {
+ this.setRoomExit("AmphitheaterSeat", "north", "AmphitheaterStage");
+ this.setRoomExit("AmphitheaterStage", "west", "Cafeteria");
+
+ this.setRoomExit("CafeteriaStreet", "south", "Cafeteria");
+ this.setRoomExit("CafeteriaStreet", "east", "EsieespaceStreet");
+ this.setRoomExit("Cafeteria", "north", "CafeteriaStreet");
+ this.setRoomExit("Cafeteria", "east", "AmphitheaterStage");
+
+ this.setRoomExit("EsieespaceStreet", "west", "Cafeteria");
+ this.setRoomExit("EsieespaceStreet", "south", "EsieespaceFront");
+ this.setRoomExit("EsieespaceStreet", "east", "EntranceStreet");
+ this.setRoomExit("EsieespaceFront", "north", "EsieespaceStreet");
+ this.setRoomExit("EsieespaceFront", "east", "EsieespaceEntrance");
+ this.setRoomExit("EsieespaceEntrance", "north", "Esieespace");
+ this.setRoomExit("EsieespaceEntrance", "west", "EsieespaceFront");
+ this.setRoomExit("Esieespace", "south", "EsieespaceEntrance");
+
+ this.setRoomExit("ClubnixStreet", "west", "WingStreet");
+ this.setRoomExit("ClubnixStreet", "south", "ClubnixFront");
+ this.setRoomExit("ClubnixFront", "north", "ClubnixStreet");
+ this.setRoomExit("ClubnixFront", "east", "ClubnixEntrance");
+ this.setRoomExit("ClubnixEntrance", "north", "Clubnix");
+ this.setRoomExit("ClubnixEntrance", "west", "ClubnixFront");
+ this.setRoomExit("Clubnix", "south", "ClubnixEntrance");
+
+ this.setRoomExit("EntranceStreet", "west", "EsieespaceStreet");
+ this.setRoomExit("EntranceStreet", "south", "EntranceStairs");
+ this.setRoomExit("EntranceStreet", "east", "WingStreet");
+ this.setRoomExit("EntranceStairs", "north", "EntranceStreet");
+ this.setRoomExit("EntranceStairs", "south", "EntranceRoundabout");
+ this.setRoomExit("EntranceRoundabout", "north", "EntranceStairs");
+
+ this.setRoomExit("WingStreet", "north", "WingCorridorOne");
+ this.setRoomExit("WingStreet", "west", "EntranceStreet");
+ this.setRoomExit("WingStreet", "east", "ClubnixStreet");
+ this.setRoomExit("WingCorridorOne", "west", "WingStairsOne");
+ this.setRoomExit("WingCorridorOne", "south", "WingStreet");
+ this.setRoomExit("WingCorridorOne", "east", "OffscriptEat");
+ this.setRoomExit("WingStairsOne", "south", "WingStairsTwo");
+ this.setRoomExit("WingStairsOne", "up", "WingStairsTwo");
+ this.setRoomExit("WingStairsOne", "east", "WingCorridorOne");
+ this.setRoomExit("WingStairsTwo", "south", "WingStairsOne");
+ this.setRoomExit("WingStairsTwo", "down", "WingStairsOne");
+ this.setRoomExit("WingStairsTwo", "east", "WingCorridorTwo");
+ this.setRoomExit("WingCorridorTwo", "north", "WingCorridorTwoOffice");
+ this.setRoomExit("WingCorridorTwoOffice", "south", "WingCorridorTwo");
+ this.setRoomExit("WingCorridorTwoOffice", "east", "WingOffice");
+ this.setRoomExit("WingOffice", "west", "WingCorridorTwoOffice");
+
+ this.setRoomExit("OffscriptEat", "north", "OffscriptEatPantry");
+ this.setRoomExit("OffscriptEat", "west", "WingCorridorOne");
+ this.setRoomExit("OffscriptEat", "east", "OffscriptTake");
+ this.setRoomExit("OffscriptEatPantry", "south", "OffscriptEat");
+ this.setRoomExit("OffscriptTake", "north", "OffscriptTakeStorageroom");
+ this.setRoomExit("OffscriptTake", "west", "OffscriptEat");
+ this.setRoomExit("OffscriptTake", "east", "OffscriptTimeout");
+ this.setRoomExit("OffscriptTakeStorageroom", "south", "OffscriptTake");
+ this.setRoomExit("OffscriptTimeout", "north", "OffscriptTimeoutCountdownroom");
+ this.setRoomExit("OffscriptTimeout", "west", "OffscriptTakeStorageroom");
+ this.setRoomExit("OffscriptTimeout", "east", "OffscriptTrapdoor");
+ this.setRoomExit("OffscriptTimeoutCountdownroom", "south", "OffscriptTimeout");
+ this.setRoomExit("OffscriptTrapdoor", "north", "OffscriptTrapdoorDeadend");
+ this.setRoomExit("OffscriptTrapdoor", "west", "OffscriptTimeout");
+ this.setRoomExit("OffscriptTrapdoor", "east", "OffscriptBeamer");
+ this.setRoomExit("OffscriptTrapdoorDeadend", "south", "OffscriptTrapdoor");
+ this.setRoomExit("OffscriptBeamer", "north", "OffscriptBeamerAnchor");
+ this.setRoomExit("OffscriptBeamer", "west", "OffscriptTrapdoor");
+ this.setRoomExit("OffscriptBeamer", "east", "OffscriptLock");
+ this.setRoomExit("OffscriptBeamerAnchor", "south", "OffscriptBeamer");
+ this.setRoomExit("OffscriptLock", "north", "OffscriptLockLockedroom");
+ this.setRoomExit("OffscriptLock", "west", "OffscriptBeamer");
+ this.setRoomExit("OffscriptLock", "east", "OffscriptAlea");
+ this.setRoomExit("OffscriptLockLockedroom", "south", "OffscriptLock");
+ this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRoomrandomizer");
+ this.setRoomExit("OffscriptAlea", "west", "OffscriptLock");
+ this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter");
+ this.setRoomExit("OffscriptAleaRoomrandomizer", "south", "OffscriptAlea");
+ this.setRoomExit("OffscriptMovingcharacter", "north", "OffscriptMovingcharacterMo");
+ this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea");
+ }
+
+ public void setRunning(final boolean pState) {
+ this.aRunning = pState;
+ this.setChanged();
+ this.notifyObservers("state");
+ }
+
+ public boolean isRunning() {
+ return this.aRunning;
+ }
+
+ public void goToRoom(final Room pRoom) {
+ this.aCurrentRoom = pRoom;
+ this.setChanged();
+ this.notifyObservers("room");
+ }
+
+ public void goToRoom(final String pRoomName) {
+ this.aCurrentRoom = this.aRooms.get(pRoomName);
+ this.setChanged();
+ this.notifyObservers("room");
+ }
+
+ public Room getRoomExit(final String pDirection) {
+ return this.aCurrentRoom.getExit(pDirection);
+ }
+
+ public String getLocationInfo() {
+ return this.aCurrentRoom.getLongDescription();
+ }
+
+ public String getLocationImageName() {
+ return this.aCurrentRoom.getImageName();
+ }
+
+ public String getEatMessage() {
+ return "oNommNommNomm...";
+ }
+
+ public String getWelcomeMessage() {
+ return "Welcome to ESIEEquest! ESIEEquest is a new, amazingly boring adventure game.";
+ }
+
+ public String getHelpMessage() {
+ return "Everybody else disappeared. You are alone. You wander around at the ESIEE.";
+ }
+
+ public String getQuitMessage() {
+ return "Thank you for wasting your time. Good bye.";
+ }
+
+ public String getNoExitMessage() {
+ return "There is no exit.";
+ }
+
+}
diff --git a/src/esieequest/model/Room.java b/src/esieequest/model/Room.java
new file mode 100644
index 0000000..2564b91
--- /dev/null
+++ b/src/esieequest/model/Room.java
@@ -0,0 +1,109 @@
+package esieequest.model;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A room.
+ *
+ * A "Room" represents one location in the scenery of the game. It is connected
+ * to other rooms via exits. The exits are labeled north, east, south, west. For
+ * each direction, the room stores a reference to the neighboring room, or null
+ * if there is no exit in that direction.
+ *
+ * @author Pacien TRAN-GIRARD
+ * @author Benoit LUBRANO DI SBARAGLIONE
+ *
+ * @version February 2014
+ */
+public class Room {
+
+ private String aDescription;
+ private String aImageName;
+ private HashMap aExits;
+
+ /**
+ * Create a room described "description". Initially, it has no exits.
+ * "description" is something like "a kitchen" or "an open court yard".
+ *
+ * @param description
+ * The room's description.
+ * @param image
+ * name The room's image
+ */
+ public Room(final String pDescription, final String pImageName) {
+ this.aDescription = pDescription;
+ this.aImageName = pImageName;
+ this.aExits = new HashMap();
+ }
+
+ public Room(final String pDescription) {
+ this(pDescription, null);
+ }
+
+ /**
+ * Return the description of the room (the one that was defined in the
+ * constructor).
+ */
+ public String getShortDescription() {
+ return this.aDescription;
+ }
+
+ /**
+ * Return a long description of this room, of the form:
+ *
+ * You are in the kitchen.
+ *
+ * Exits: north west
+ *
+ * @return A description of the room, including exits.
+ */
+ public String getLongDescription() {
+ return "You are " + this.aDescription + ".\n" + getExitString();
+ }
+
+ /**
+ * Return a string describing the room's image name
+ */
+ public String getImageName() {
+ return this.aImageName;
+ }
+
+ /**
+ * Return the room that is reached if we go from this room in direction
+ * "direction". If there is no room in that direction, return null.
+ */
+ public Room getExit(String pDirection) {
+ return this.aExits.get(pDirection);
+ }
+
+ /**
+ * Return a description of the room's exits, for example
+ * "Exits: north west".
+ *
+ * @return A description of the available exits.
+ */
+ public String getExitString() {
+ StringBuilder vStrBuilder = new StringBuilder("Available exits:");
+ Set vKeys = this.aExits.keySet();
+ for (Iterator vIter = vKeys.iterator(); vIter.hasNext();) {
+ vStrBuilder.append(" ").append(vIter.next());
+ }
+ vStrBuilder.append(".");
+ return vStrBuilder.toString();
+ }
+
+ /**
+ * Define an exit from this room.
+ *
+ * @param direction
+ * The direction of the exit.
+ * @param neighbor
+ * The room in the given direction.
+ */
+ public void setExit(String direction, Room neighbor) {
+ this.aExits.put(direction, neighbor);
+ }
+
+}
diff --git a/src/esieequest/model/command/Command.java b/src/esieequest/model/command/Command.java
new file mode 100644
index 0000000..a0a26fb
--- /dev/null
+++ b/src/esieequest/model/command/Command.java
@@ -0,0 +1,35 @@
+package esieequest.model.command;
+
+public class Command {
+
+ private String aAction;
+ private String aOption;
+
+ public Command(final String pAction, final String pOption) {
+ this.aAction = pAction;
+ this.aOption = pOption;
+ }
+
+ /**
+ * @return the Action
+ */
+ public String getAction() {
+ return this.aAction;
+ }
+
+ public boolean isUnknown() {
+ return this.aAction == null;
+ }
+
+ /**
+ * @return the Option
+ */
+ public String getOption() {
+ return this.aOption;
+ }
+
+ public boolean hasOption() {
+ return this.aOption != null;
+ }
+
+}
diff --git a/src/esieequest/model/command/CommandWord.java b/src/esieequest/model/command/CommandWord.java
new file mode 100644
index 0000000..e8bc7ad
--- /dev/null
+++ b/src/esieequest/model/command/CommandWord.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package esieequest.model.command;
+
+/**
+ * @author pacien
+ *
+ */
+public enum CommandWord {
+ // "" = no option
+ // new String[] { "" } = any option
+ NEW("new", new String[] { "" }), LOAD("load", new String[] { "" }), SAVE("save",
+ new String[] { "" }), SOUND("sound", new String[] { "" }), HELP("help",
+ new String[] { "" }), QUIT("quit", new String[] { "" }), LOOK("look",
+ new String[] { "" }), EAT("eat", new String[] { "" }), FORWARD("forward",
+ new String[] { "" }), BACK("back", new String[] { "" }), GO("go", new String[] {
+ "north", "south", "east", "west", "up", "down" }), TURN("turn", new String[] { "left",
+ "right" }), DO("do", new String[] { "" }), TAKE("take", new String[] { "" }), TALK(
+ "talk", new String[] { "" }), INVENTORY("inventory", new String[] { "" }), USE("use",
+ null), UNKNOWN("?", new String[] { "" });
+
+ private String aAction;
+ private String[] aValidOptions;
+
+ CommandWord(final String pAction, final String[] pValidOptions) {
+ this.aAction = pAction;
+ this.aValidOptions = pValidOptions;
+ }
+
+ public String toString() {
+ return this.aAction;
+ }
+
+ public String getAction() {
+ return this.aAction;
+ }
+
+ public String[] getValidOptions() {
+ return this.aValidOptions;
+ }
+
+}
diff --git a/src/esieequest/model/command/package-info.java b/src/esieequest/model/command/package-info.java
new file mode 100644
index 0000000..38be480
--- /dev/null
+++ b/src/esieequest/model/command/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author