From f64f1ffb0057f0096dcd9d3d8c0349545f00d246 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 23:30:50 +0100 Subject: Use an HashMap to store Rooms --- src/esieequest/Game.java | 230 ++++++++++++++++++++++++----------------------- 1 file changed, 117 insertions(+), 113 deletions(-) diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index cae7559..43db8f7 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -1,5 +1,7 @@ package esieequest; +import java.util.HashMap; + /** * The game engine. * @@ -13,6 +15,7 @@ package esieequest; * @version February 2014 */ public class Game { + private HashMap aRooms; private Room aCurrentRoom; private Parser aParser; @@ -20,6 +23,7 @@ public class Game { * Create the game and initialize its internal map. */ public Game() { + this.aRooms = new HashMap(); this.createRooms(); this.aParser = new Parser(); this.play(); @@ -44,134 +48,134 @@ public class Game { */ private void createRooms() { // create rooms - Room vAmphitheaterSeat = new Room("in the amphitheater"); - Room vAmphitheaterStage = new Room("on the amphitheater stage"); + this.aRooms.put("AmphitheaterSeat", new Room("in the amphitheater")); + this.aRooms.put("AmphitheaterStage", new Room("on the amphitheater stage")); - Room vCafeteriaStreet = new Room("in the main corridor, in front of the cafeteria"); - Room vCafeteria = new Room("at the cafeteria"); + this.aRooms.put("CafeteriaStreet", new Room("in the main corridor, in front of the cafeteria")); + this.aRooms.put("Cafeteria", new Room("at the cafeteria")); - Room vEsieespaceStreet = new Room("in the main corridor, in front of the ESIEEspace HQ"); - Room vEsieespaceFront = new Room("in front of the ESIEEspace HQ"); - Room vEsieespaceEntrance = new Room("at the ESIEEspace HQ entrance"); - Room vEsieespace = new Room("in the ESIEEspace HQ"); + 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")); - Room vClubnixStreet = new Room("in the main corridor, in front of the Club*Nix"); - Room vClubnixFront = new Room("in front of the Club*Nix"); - Room vClubnixEntrance = new Room("at the Club*Nix entrance"); - Room vClubnix = new Room("in the Club*Nix"); + 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")); - Room vEntranceStreet = new Room("in the main corridor, at the reception"); - Room vEntranceStairs = new Room("on the main entrance stairs"); - Room vEntranceRoundabout = new Room("on the roundabout"); + 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")); - Room vWingStreet = new Room("in font of wing #3"); - Room vWingCorridorOne = new Room("in the corridor in wing #3, on the ground floor"); - Room vWingStairsOne = new Room("in the stairwell on the ground floor"); - Room vWingStairsTwo = new Room("in the stairwell on the first floor"); - Room vWingCorridorTwo = new Room("in the corridor in wind #3, on the first floor"); - Room vWingCorridorTwoOffice = new Room("in front of the office #3254"); - Room vWingOffice = new Room("in the office #3254"); + 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")); - Room vOffscriptEat = new Room("somewhere implementing hunger"); - Room vOffscriptEatPantry = new Room("in the pantry"); - Room vOffscriptTake = new Room("somewhere implementing weight"); - Room vOffscriptTakeStorageroom = new Room("in a storage room"); - Room vOffscriptTimeout = new Room("somewhere implementing time"); - Room vOffscriptTimeoutCountdownroom = new Room("in a dangerous room"); - Room vOffscriptTrapdoor = new Room("somewhere implementing a trap"); - Room vOffscriptTrapdoorDeadend = new Room("trapped"); - Room vOffscriptBeamer = new Room("somewhere implementing teleportation"); - Room vOffscriptBeamerAnchor = new Room("on a checkpoint"); - Room vOffscriptLock = new Room("somewhere implementing a doorlock"); - Room vOffscriptLockLockedroom = new Room("in a locked room that is not anymore"); - Room vOffscriptAlea = new Room("somewhere implementing alea"); - Room vOffscriptAleaRoomrandomizer = new Room("in a weird room that will transport you somewhere else"); - Room vOffscriptMovingcharacter = new Room("somewhere implementing a moving character"); - Room vOffscriptMovingcharacterMo = new Room("in M-O's room"); + 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 (N, W, S, E) - vAmphitheaterSeat.setExit("north", vAmphitheaterStage); - vAmphitheaterStage.setExit("west", vCafeteria); + // connect rooms + this.aRooms.get("AmphitheaterSeat").setExit("north", this.aRooms.get("AmphitheaterStage")); + this.aRooms.get("AmphitheaterStage").setExit("west", this.aRooms.get("Cafeteria")); - vCafeteriaStreet.setExit("south", vCafeteria); - vCafeteriaStreet.setExit("east", vEsieespaceStreet); - vCafeteria.setExit("north", vCafeteriaStreet); - vCafeteria.setExit("east", vAmphitheaterStage); + 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")); - 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); + 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")); - 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); + 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")); - vEntranceStreet.setExit("west", vEsieespaceStreet); - vEntranceStreet.setExit("south", vEntranceStairs); - vEntranceStreet.setExit("east", vWingStreet); - vEntranceStairs.setExit("north", vEntranceStreet); - vEntranceStairs.setExit("south", vEntranceRoundabout); - vEntranceRoundabout.setExit("north", vEntranceStairs); + 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")); - 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("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); - vWingCorridorTwoOffice.setExit("east", vWingOffice); - vWingOffice.setExit("west", vWingCorridorTwoOffice); + 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")); - 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); + 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 = vAmphitheaterSeat; + this.aCurrentRoom = this.aRooms.get("AmphitheaterSeat"); } /** -- cgit v1.2.3