From e52a34789c7f64bbf1bb49dfcb2415dbc7d8ca12 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 15:23:54 +0100 Subject: Rename printRoomInfo to printLocationInfo --- src/esieequest/Game.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 89b7318..7da57e9 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -15,7 +15,7 @@ public class Game { public Game() { this.createRooms(); this.printWelcome(); - this.printRoomInfo(); + this.printLocationInfo(); this.play(); } @@ -157,10 +157,10 @@ public class Game { } this.aCurrentRoom = vNextRoom; - this.printRoomInfo(); + this.printLocationInfo(); } - private void printRoomInfo() { + private void printLocationInfo() { System.out.println("You are now " + this.aCurrentRoom.getDescription() + "."); System.out.print("Available exits:"); -- cgit v1.2.3 From 53c427ff3289bd31ba62898162fa68b0834f4719 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 15:59:03 +0100 Subject: Make exit attributes private --- src/esieequest/Game.java | 19 +------------------ src/esieequest/Room.java | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 7da57e9..95eaa4a 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -132,24 +132,7 @@ public class Game { return; } - Room vNextRoom; - switch (pCommand.getSecondWord()) { - case "north": - vNextRoom = this.aCurrentRoom.aNorthExit; - break; - case "south": - vNextRoom = this.aCurrentRoom.aSouthExit; - break; - case "east": - vNextRoom = this.aCurrentRoom.aEastExit; - break; - case "west": - vNextRoom = this.aCurrentRoom.aWestExit; - break; - default: - System.out.println("Go where ?"); - return; - } + Room vNextRoom = aCurrentRoom.getExit(pCommand.getSecondWord()); if (vNextRoom == null) { System.out.println("There is no door!"); diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 0a16e33..d9235cf 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -11,10 +11,10 @@ package esieequest; public class Room { private String aDescription; - public Room aNorthExit; - public Room aSouthExit; - public Room aEastExit; - public Room aWestExit; + private Room aNorthExit; + private Room aSouthExit; + private Room aEastExit; + private Room aWestExit; public Room(final String pDescription) { this.aDescription = pDescription; @@ -33,4 +33,18 @@ public class Room { this.aEastExit = pEastExit; this.aWestExit = pWestExit; } + + public Room getExit(String pDirection) { + switch (pDirection) { + case "north": + return this.aNorthExit; + case "south": + return this.aSouthExit; + case "east": + return this.aEastExit; + case "west": + return this.aWestExit; + } + return null; + } } -- cgit v1.2.3 From ca65af2e2be2e10347fe9ca057fec231d25d404d Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 16:08:45 +0100 Subject: Implement getExitString() --- src/esieequest/Game.java | 16 +--------------- src/esieequest/Room.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 95eaa4a..a00d901 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -145,21 +145,7 @@ public class Game { private void printLocationInfo() { System.out.println("You are now " + this.aCurrentRoom.getDescription() + "."); - - System.out.print("Available exits:"); - if (this.aCurrentRoom.aNorthExit != null) { - System.out.print(" North"); - } - if (this.aCurrentRoom.aSouthExit != null) { - System.out.print(" South"); - } - if (this.aCurrentRoom.aEastExit != null) { - System.out.print(" East"); - } - if (this.aCurrentRoom.aWestExit != null) { - System.out.print(" West"); - } - System.out.println("."); + System.out.println(this.aCurrentRoom.getExitString()); } private void printWelcome() { diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index d9235cf..5b4dcfa 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -47,4 +47,28 @@ public class Room { } return null; } + + /** + * Return a description of the room’s exits, for example, + * "Exits: north west". + * + * @return A description of the available exits. + */ + public String getExitString() { + String vExitsString = "Available exits:"; + if (this.aNorthExit != null) { + vExitsString += " North"; + } + if (this.aSouthExit != null) { + vExitsString += " South"; + } + if (this.aEastExit != null) { + vExitsString += " East"; + } + if (this.aWestExit != null) { + vExitsString += " West"; + } + vExitsString += "."; + return vExitsString; + } } -- cgit v1.2.3 From c9d890b9b71efddf4b9b39354c78b5bff3dffac6 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 16:45:19 +0100 Subject: Use HashMap to store exits --- src/esieequest/Game.java | 120 ++++++++++++++++++++++++++++++----------------- src/esieequest/Room.java | 54 +++++++++++---------- 2 files changed, 105 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index a00d901..a0e0cd2 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -78,49 +78,83 @@ public class Game { Room vOffscriptMovingcharacterMo = new Room("in M-O's room"); // connect rooms (N, W, S, E) - vAmphitheaterSeat.setExits(vAmphitheaterStage, null, null, null); - vAmphitheaterStage.setExits(null, vCafeteria, null, null); - - vCafeteriaStreet.setExits(null, null, vCafeteria, vEsieespaceStreet); - vCafeteria.setExits(vCafeteriaStreet, null, null, vAmphitheaterStage); - - vEsieespaceStreet.setExits(null, vCafeteria, vEsieespaceFront, vEntranceStreet); - vEsieespaceFront.setExits(vEsieespaceStreet, null, null, vEsieespaceEntrance); - vEsieespaceEntrance.setExits(vEsieespace, vEsieespaceFront, null, null); - vEsieespace.setExits(null, null, vEsieespaceEntrance, null); - - vClubnixStreet.setExits(null, vWingStreet, vClubnixFront, null); - vClubnixFront.setExits(vClubnixStreet, null, null, vClubnixEntrance); - vClubnixEntrance.setExits(vClubnix, vClubnixFront, null, null); - vClubnix.setExits(null, null, vClubnixEntrance, null); - - vEntranceStreet.setExits(null, vEsieespaceStreet, vEntranceStairs, vWingStreet); - vEntranceStairs.setExits(vEntranceStreet, null, vEntranceRoundabout, null); - vEntranceRoundabout.setExits(vEntranceStairs, null, null, null); - - vWingStreet.setExits(vWingCorridorOne, vEntranceStreet, null, vClubnixStreet); - vWingCorridorOne.setExits(null, vWingStairsOne, vWingStreet, vOffscriptEat); - vWingStairsOne.setExits(null, null, vWingStairsTwo, vWingCorridorOne); - vWingStairsTwo.setExits(null, null, vWingStairsOne, vWingCorridorTwo); - vWingCorridorTwo.setExits(vWingCorridorTwoOffice, null, null, null); - vWingCorridorTwoOffice.setExits(null, null, vWingCorridorTwo, vWingOffice); - vWingOffice.setExits(null, vWingCorridorTwoOffice, null, null); - - vOffscriptEat.setExits(vOffscriptEatPantry, vWingCorridorOne, null, vOffscriptTake); - vOffscriptEatPantry.setExits(null, null, vOffscriptEat, null); - vOffscriptTake.setExits(vOffscriptTakeStorageroom, vOffscriptEat, null, vOffscriptTimeout); - vOffscriptTakeStorageroom.setExits(null, null, vOffscriptTake, null); - vOffscriptTimeout.setExits(vOffscriptTimeoutCountdownroom, vOffscriptTakeStorageroom, null, vOffscriptTrapdoor); - vOffscriptTimeoutCountdownroom.setExits(null, null, vOffscriptTimeout, null); - vOffscriptTrapdoor.setExits(vOffscriptTrapdoorDeadend, vOffscriptTimeout, null, vOffscriptBeamer); - vOffscriptTrapdoorDeadend.setExits(null, null, vOffscriptTrapdoor, null); - vOffscriptBeamer.setExits(vOffscriptBeamerAnchor, vOffscriptTrapdoor, null, vOffscriptLock); - vOffscriptBeamerAnchor.setExits(null, null, vOffscriptBeamer, null); - vOffscriptLock.setExits(vOffscriptLockLockedroom, vOffscriptBeamer, null, vOffscriptAlea); - vOffscriptLockLockedroom.setExits(null, null, vOffscriptLock, null); - vOffscriptAlea.setExits(vOffscriptAleaRoomrandomizer, vOffscriptLock, null, vOffscriptMovingcharacter); - vOffscriptAleaRoomrandomizer.setExits(null, null, vOffscriptAlea, null); - vOffscriptMovingcharacter.setExits(vOffscriptMovingcharacterMo, vOffscriptAlea, null, null); + vAmphitheaterSeat.setExit("north", vAmphitheaterStage); + vAmphitheaterStage.setExit("west", vCafeteria); + + vCafeteriaStreet.setExit("south", vCafeteria); + vCafeteriaStreet.setExit("east", vEsieespaceStreet); + vCafeteria.setExit("north", vCafeteriaStreet); + vCafeteria.setExit("east", vAmphitheaterStage); + + vEsieespaceStreet.setExit("west", vCafeteria); + vEsieespaceStreet.setExit("south", vEsieespaceFront); + vEsieespaceStreet.setExit("east", vEntranceStreet); + vEsieespaceFront.setExit("north", vEsieespaceStreet); + vEsieespaceFront.setExit("east", vEsieespaceEntrance); + vEsieespaceEntrance.setExit("north", vEsieespace); + vEsieespaceEntrance.setExit("west", vEsieespaceFront); + vEsieespace.setExit("south", vEsieespaceEntrance); + + vClubnixStreet.setExit("west", vWingStreet); + vClubnixStreet.setExit("south", vClubnixFront); + vClubnixFront.setExit("north", vClubnixStreet); + vClubnixFront.setExit("east", vClubnixEntrance); + vClubnixEntrance.setExit("north", vClubnix); + vClubnixEntrance.setExit("west", vClubnixFront); + vClubnix.setExit("south", vClubnixEntrance); + + vEntranceStreet.setExit("west", vEsieespaceStreet); + vEntranceStreet.setExit("south", vEntranceStairs); + vEntranceStreet.setExit("east", vWingStreet); + vEntranceStairs.setExit("north", vEntranceStreet); + vEntranceStairs.setExit("south", vEntranceRoundabout); + vEntranceRoundabout.setExit("north", vEntranceStairs); + + vWingStreet.setExit("north", vWingCorridorOne); + vWingStreet.setExit("west", vEntranceStreet); + vWingStreet.setExit("east", vClubnixStreet); + vWingCorridorOne.setExit("west", vWingStairsOne); + vWingCorridorOne.setExit("south", vWingStreet); + vWingCorridorOne.setExit("east", vOffscriptEat); + vWingStairsOne.setExit("south", vWingStairsTwo); + vWingStairsOne.setExit("east", vWingCorridorOne); + vWingStairsTwo.setExit("south", vWingStairsOne); + vWingStairsTwo.setExit("east", vWingCorridorTwo); + vWingCorridorTwo.setExit("north", vWingCorridorTwoOffice); + vWingCorridorTwoOffice.setExit("south", vWingCorridorTwo); + vWingCorridorTwoOffice.setExit("east", vWingOffice); + vWingOffice.setExit("west", vWingCorridorTwoOffice); + + vOffscriptEat.setExit("north", vOffscriptEatPantry); + vOffscriptEat.setExit("west", vWingCorridorOne); + vOffscriptEat.setExit("east", vOffscriptTake); + vOffscriptEatPantry.setExit("south", vOffscriptEat); + vOffscriptTake.setExit("north", vOffscriptTakeStorageroom); + vOffscriptTake.setExit("west", vOffscriptEat); + vOffscriptTake.setExit("east", vOffscriptTimeout); + vOffscriptTakeStorageroom.setExit("south", vOffscriptTake); + vOffscriptTimeout.setExit("north", vOffscriptTimeoutCountdownroom); + vOffscriptTimeout.setExit("west", vOffscriptTakeStorageroom); + vOffscriptTimeout.setExit("east", vOffscriptTrapdoor); + vOffscriptTimeoutCountdownroom.setExit("south", vOffscriptTimeout); + vOffscriptTrapdoor.setExit("north", vOffscriptTrapdoorDeadend); + vOffscriptTrapdoor.setExit("west", vOffscriptTimeout); + vOffscriptTrapdoor.setExit("east", vOffscriptBeamer); + vOffscriptTrapdoorDeadend.setExit("south", vOffscriptTrapdoor); + vOffscriptBeamer.setExit("north", vOffscriptBeamerAnchor); + vOffscriptBeamer.setExit("west", vOffscriptTrapdoor); + vOffscriptBeamer.setExit("east", vOffscriptLock); + vOffscriptBeamerAnchor.setExit("south", vOffscriptBeamer); + vOffscriptLock.setExit("north", vOffscriptLockLockedroom); + vOffscriptLock.setExit("west", vOffscriptBeamer); + vOffscriptLock.setExit("east", vOffscriptAlea); + vOffscriptLockLockedroom.setExit("south", vOffscriptLock); + vOffscriptAlea.setExit("north", vOffscriptAleaRoomrandomizer); + vOffscriptAlea.setExit("west", vOffscriptLock); + vOffscriptAlea.setExit("east", vOffscriptMovingcharacter); + vOffscriptAleaRoomrandomizer.setExit("south", vOffscriptAlea); + vOffscriptMovingcharacter.setExit("north", vOffscriptMovingcharacterMo); + vOffscriptMovingcharacter.setExit("west", vOffscriptAlea); // set the starting room this.aCurrentRoom = vAmphitheaterSeat; diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 5b4dcfa..780f76a 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -1,5 +1,7 @@ package esieequest; +import java.util.HashMap; + /** * A room. * @@ -9,15 +11,18 @@ package esieequest; * @version February 2014 */ public class Room { - private String aDescription; - private Room aNorthExit; - private Room aSouthExit; - private Room aEastExit; - private Room aWestExit; + private String aDescription; + private HashMap aExits; + /** + * Create a room described "description "Initially, it has no exits. + * "description" is something like "a kitchen" or "an open courtyard". + */ public Room(final String pDescription) { this.aDescription = pDescription; + this.aExits = new HashMap(); + } public String getDescription() { @@ -25,27 +30,23 @@ public class Room { } /** - * Defines the four exits (other rooms) of this room. + * Define an exit from this room. + * + * @param direction + * The direction of the exit. + * @param neighbor + * The room in the given direction. */ - public void setExits(final Room pNorthExit, final Room pWestExit, final Room pSouthExit, final Room pEastExit) { - this.aNorthExit = pNorthExit; - this.aSouthExit = pSouthExit; - this.aEastExit = pEastExit; - this.aWestExit = pWestExit; + 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) { - switch (pDirection) { - case "north": - return this.aNorthExit; - case "south": - return this.aSouthExit; - case "east": - return this.aEastExit; - case "west": - return this.aWestExit; - } - return null; + return this.aExits.get(pDirection); } /** @@ -56,19 +57,20 @@ public class Room { */ public String getExitString() { String vExitsString = "Available exits:"; - if (this.aNorthExit != null) { + if (this.aExits.get("north") != null) { vExitsString += " North"; } - if (this.aSouthExit != null) { + if (this.aExits.get("south") != null) { vExitsString += " South"; } - if (this.aEastExit != null) { + if (this.aExits.get("east") != null) { vExitsString += " East"; } - if (this.aWestExit != null) { + if (this.aExits.get("west") != null) { vExitsString += " West"; } vExitsString += "."; return vExitsString; } + } -- cgit v1.2.3 From 4145a5e8ce6cc4a7be3e51fcef71ca004b2ba463 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 17:10:01 +0100 Subject: Add a vertical direction --- src/esieequest/Game.java | 2 ++ src/esieequest/Room.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index a0e0cd2..1be4d15 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -117,8 +117,10 @@ public class Game { vWingCorridorOne.setExit("south", vWingStreet); vWingCorridorOne.setExit("east", vOffscriptEat); vWingStairsOne.setExit("south", vWingStairsTwo); + vWingStairsOne.setExit("up", vWingStairsTwo); vWingStairsOne.setExit("east", vWingCorridorOne); vWingStairsTwo.setExit("south", vWingStairsOne); + vWingStairsTwo.setExit("down", vWingStairsOne); vWingStairsTwo.setExit("east", vWingCorridorTwo); vWingCorridorTwo.setExit("north", vWingCorridorTwoOffice); vWingCorridorTwoOffice.setExit("south", vWingCorridorTwo); diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 780f76a..1b23afa 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -58,16 +58,22 @@ public class Room { public String getExitString() { String vExitsString = "Available exits:"; if (this.aExits.get("north") != null) { - vExitsString += " North"; + vExitsString += " north"; } if (this.aExits.get("south") != null) { - vExitsString += " South"; + vExitsString += " south"; } if (this.aExits.get("east") != null) { - vExitsString += " East"; + vExitsString += " east"; } if (this.aExits.get("west") != null) { - vExitsString += " West"; + vExitsString += " west"; + } + if (this.aExits.get("up") != null) { + vExitsString += " up"; + } + if (this.aExits.get("down") != null) { + vExitsString += " down"; } vExitsString += "."; return vExitsString; -- cgit v1.2.3 From e510b08d0925629dba304177099ccd3a81585ba9 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 17:52:57 +0100 Subject: Make getExitString() more flexible and add getLongDescription() --- src/esieequest/Game.java | 3 +-- src/esieequest/Room.java | 44 +++++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 1be4d15..bad0106 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -180,8 +180,7 @@ public class Game { } private void printLocationInfo() { - System.out.println("You are now " + this.aCurrentRoom.getDescription() + "."); - System.out.println(this.aCurrentRoom.getExitString()); + System.out.println(this.aCurrentRoom.getLongDescription()); } private void printWelcome() { diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 1b23afa..9d7f071 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -1,6 +1,7 @@ package esieequest; import java.util.HashMap; +import java.util.Set; /** * A room. @@ -25,8 +26,19 @@ public class Room { } - public String getDescription() { - 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; } /** @@ -50,33 +62,19 @@ public class Room { } /** - * Return a description of the room’s exits, for example, + * Return a description of the room’s exits, for example * "Exits: north west". * * @return A description of the available exits. */ public String getExitString() { - String vExitsString = "Available exits:"; - if (this.aExits.get("north") != null) { - vExitsString += " north"; - } - if (this.aExits.get("south") != null) { - vExitsString += " south"; - } - if (this.aExits.get("east") != null) { - vExitsString += " east"; - } - if (this.aExits.get("west") != null) { - vExitsString += " west"; - } - if (this.aExits.get("up") != null) { - vExitsString += " up"; - } - if (this.aExits.get("down") != null) { - vExitsString += " down"; + String vExitString = "Available exits:"; + Set keys = this.aExits.keySet(); + for (String exit : keys) { + vExitString += " " + exit; } - vExitsString += "."; - return vExitsString; + vExitString += "."; + return vExitString; } } -- cgit v1.2.3 From 1b4b8c7e5bbe05f05f6cfc7aa16ad0570af4f2ca Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 19:41:18 +0100 Subject: Complete Javadoc comments --- src/esieequest/Command.java | 37 +++++++++++++++++++++++++++++++++++++ src/esieequest/Game.java | 37 +++++++++++++++++++++++++++++++++++++ src/esieequest/Main.java | 5 +++++ src/esieequest/Room.java | 12 ++++++++++-- src/esieequest/package-info.java | 5 +++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/esieequest/package-info.java (limited to 'src') diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java index de6b853..fd05930 100644 --- a/src/esieequest/Command.java +++ b/src/esieequest/Command.java @@ -3,6 +3,17 @@ package esieequest; /** * A text command that triggers an action in the game. * + * 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 * @@ -12,23 +23,49 @@ 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 pCommandWord, final String pSecondWord) { this.aCommandWord = pCommandWord; 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/Game.java b/src/esieequest/Game.java index bad0106..638c9b8 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -3,6 +3,10 @@ package esieequest; /** * 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 * @@ -12,6 +16,9 @@ public class Game { private Room aCurrentRoom; private Parser aParser; + /** + * Create the game and initialize its internal map. + */ public Game() { this.createRooms(); this.printWelcome(); @@ -19,6 +26,9 @@ public class Game { this.play(); } + /** + * Main play routine. Loops until end of play. + */ private void play() { aParser = new Parser(); boolean vFinished = false; @@ -30,6 +40,9 @@ public class Game { System.out.println("Thank you for playing. Good bye."); } + /** + * Create all the rooms and link their exits together. + */ private void createRooms() { // create rooms Room vAmphitheaterSeat = new Room("in the amphitheater"); @@ -162,6 +175,10 @@ public class Game { this.aCurrentRoom = vAmphitheaterSeat; } + /** + * 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()) { System.out.println("Go where?"); @@ -183,6 +200,9 @@ public class Game { System.out.println(this.aCurrentRoom.getLongDescription()); } + /** + * Print out the opening message for the player. + */ private void printWelcome() { System.out.println("Welcome to ESIEEquest"); System.out.println("ESIEEquest is a new, incredibly surprising adventure game."); @@ -190,6 +210,10 @@ public class Game { System.out.println(""); } + /** + * Print out some help information. Here we print some stupid, cryptic + * message and a list of the command words. + */ private void printHelp() { System.out.println("You are lost. You are alone. "); System.out.println("You wander around at the university."); @@ -198,6 +222,12 @@ public class Game { System.out.println(" go quit help"); } + /** + * "Quit" was entered. Check the rest of the command to see whether we + * really quit the game. + * + * @return true, if this command quits the game, false otherwise. + */ private boolean quit(final Command pCommand) { if (pCommand.hasSecondWord()) { System.out.println("Quit what?"); @@ -206,6 +236,13 @@ public class Game { return true; } + /** + * 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 boolean processCommand(final Command pCommand) { if (pCommand.getCommandWord() != null) { switch (pCommand.getCommandWord()) { diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index 88e66c2..8cbea80 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java @@ -1,6 +1,11 @@ package esieequest; /** + * The Main class + * + * This class instantiates the game and makes it possible to run it via the + * command line. + * * @author Pacien TRAN-GIRARD * @author Benoit LUBRANO DI SBARAGLIONE * diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 9d7f071..32adc90 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -6,6 +6,11 @@ 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 labelled 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 * @@ -17,8 +22,11 @@ public class Room { private HashMap aExits; /** - * Create a room described "description "Initially, it has no exits. - * "description" is something like "a kitchen" or "an open courtyard". + * 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. */ public Room(final String pDescription) { this.aDescription = pDescription; diff --git a/src/esieequest/package-info.java b/src/esieequest/package-info.java new file mode 100644 index 0000000..a5a042f --- /dev/null +++ b/src/esieequest/package-info.java @@ -0,0 +1,5 @@ +/** + * "ESIEEquest" is a very simple, text based adventure game. + */ +package esieequest; + -- cgit v1.2.3