aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/esieequest/CommandWords.java36
-rw-r--r--src/esieequest/Game.java244
-rw-r--r--src/esieequest/Parser.java42
-rw-r--r--src/esieequest/Room.java27
4 files changed, 184 insertions, 165 deletions
diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java
index 3d8855d..e2d50f5 100644
--- a/src/esieequest/CommandWords.java
+++ b/src/esieequest/CommandWords.java
@@ -1,25 +1,23 @@
1package esieequest; 1package esieequest;
2 2
3/** 3/**
4 * This class is part of the "World of Zuul" application. "World of Zuul" is a
5 * very simple, text based adventure game.
6 *
7 * This class holds an enumeration table of all command words known to the game. 4 * This class holds an enumeration table of all command words known to the game.
8 * It is used to recognise commands as they are typed in. 5 * It is used to recognize commands as they are typed in.
6 *
7 * @author Pacien TRAN-GIRARD
8 * @author Benoit LUBRANO DI SBARAGLIONE
9 * 9 *
10 * @author Michael Kolling and David J. Barnes + D.Bureau 10 * @version February 2014
11 * @version 2008.03.30 + 2013.09.15
12 */ 11 */
13public class CommandWords { 12public class CommandWords {
14 // a constant array that holds all valid command words
15 private static final String[] sValidCommands = { "go", "quit", "help", "look", "eat" }; 13 private static final String[] sValidCommands = { "go", "quit", "help", "look", "eat" };
16 14
17 /** 15 /**
18 * Constructor - initialise the command words. 16 * Constructor - initialize the command words.
19 */ 17 */
20 public CommandWords() { 18 public CommandWords() {
21 // nothing to do at the moment... 19
22 } // CommandWords() 20 }
23 21
24 /** 22 /**
25 * Check whether a given String is a valid command word. 23 * Check whether a given String is a valid command word.
@@ -30,8 +28,18 @@ public class CommandWords {
30 for (int i = 0; i < sValidCommands.length; i++) { 28 for (int i = 0; i < sValidCommands.length; i++) {
31 if (sValidCommands[i].equals(pString)) 29 if (sValidCommands[i].equals(pString))
32 return true; 30 return true;
33 } // for 31 }
34 // if we get here, the string was not found in the commands
35 return false; 32 return false;
36 } // isCommand() 33 }
37} // CommandWords 34
35 /**
36 * Print all valid commands to System.out.
37 */
38 public String getCommandList() {
39 StringBuilder vStrBuilder = new StringBuilder();
40 for (String vCommand : sValidCommands) {
41 vStrBuilder.append(" ").append(vCommand);
42 }
43 return vStrBuilder.toString();
44 }
45}
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java
index 350fa15..43db8f7 100644
--- a/src/esieequest/Game.java
+++ b/src/esieequest/Game.java
@@ -1,5 +1,7 @@
1package esieequest; 1package esieequest;
2 2
3import java.util.HashMap;
4
3/** 5/**
4 * The game engine. 6 * The game engine.
5 * 7 *
@@ -13,6 +15,7 @@ package esieequest;
13 * @version February 2014 15 * @version February 2014
14 */ 16 */
15public class Game { 17public class Game {
18 private HashMap<String, Room> aRooms;
16 private Room aCurrentRoom; 19 private Room aCurrentRoom;
17 private Parser aParser; 20 private Parser aParser;
18 21
@@ -20,9 +23,9 @@ public class Game {
20 * Create the game and initialize its internal map. 23 * Create the game and initialize its internal map.
21 */ 24 */
22 public Game() { 25 public Game() {
26 this.aRooms = new HashMap<String, Room>();
23 this.createRooms(); 27 this.createRooms();
24 this.printWelcome(); 28 this.aParser = new Parser();
25 this.printLocationInfo();
26 this.play(); 29 this.play();
27 } 30 }
28 31
@@ -30,7 +33,7 @@ public class Game {
30 * Main play routine. Loops until end of play. 33 * Main play routine. Loops until end of play.
31 */ 34 */
32 private void play() { 35 private void play() {
33 aParser = new Parser(); 36 this.printWelcome();
34 boolean vFinished = false; 37 boolean vFinished = false;
35 while (!vFinished) { 38 while (!vFinished) {
36 Command vCommand = this.aParser.getCommand(); 39 Command vCommand = this.aParser.getCommand();
@@ -45,134 +48,134 @@ public class Game {
45 */ 48 */
46 private void createRooms() { 49 private void createRooms() {
47 // create rooms 50 // create rooms
48 Room vAmphitheaterSeat = new Room("in the amphitheater"); 51 this.aRooms.put("AmphitheaterSeat", new Room("in the amphitheater"));
49 Room vAmphitheaterStage = new Room("on the amphitheater stage"); 52 this.aRooms.put("AmphitheaterStage", new Room("on the amphitheater stage"));
50 53
51 Room vCafeteriaStreet = new Room("in the main corridor, in front of the cafeteria"); 54 this.aRooms.put("CafeteriaStreet", new Room("in the main corridor, in front of the cafeteria"));
52 Room vCafeteria = new Room("at the cafeteria"); 55 this.aRooms.put("Cafeteria", new Room("at the cafeteria"));
53 56
54 Room vEsieespaceStreet = new Room("in the main corridor, in front of the ESIEEspace HQ"); 57 this.aRooms.put("EsieespaceStreet", new Room("in the main corridor, in front of the ESIEEspace HQ"));
55 Room vEsieespaceFront = new Room("in front of the ESIEEspace HQ"); 58 this.aRooms.put("EsieespaceFront", new Room("in front of the ESIEEspace HQ"));
56 Room vEsieespaceEntrance = new Room("at the ESIEEspace HQ entrance"); 59 this.aRooms.put("EsieespaceEntrance", new Room("at the ESIEEspace HQ entrance"));
57 Room vEsieespace = new Room("in the ESIEEspace HQ"); 60 this.aRooms.put("Esieespace", new Room("in the ESIEEspace HQ"));
58 61
59 Room vClubnixStreet = new Room("in the main corridor, in front of the Club*Nix"); 62 this.aRooms.put("ClubnixStreet", new Room("in the main corridor, in front of the Club*Nix"));
60 Room vClubnixFront = new Room("in front of the Club*Nix"); 63 this.aRooms.put("ClubnixFront", new Room("in front of the Club*Nix"));
61 Room vClubnixEntrance = new Room("at the Club*Nix entrance"); 64 this.aRooms.put("ClubnixEntrance", new Room("at the Club*Nix entrance"));
62 Room vClubnix = new Room("in the Club*Nix"); 65 this.aRooms.put("Clubnix", new Room("in the Club*Nix"));
63 66
64 Room vEntranceStreet = new Room("in the main corridor, at the reception"); 67 this.aRooms.put("EntranceStreet", new Room("in the main corridor, at the reception"));
65 Room vEntranceStairs = new Room("on the main entrance stairs"); 68 this.aRooms.put("EntranceStairs", new Room("on the main entrance stairs"));
66 Room vEntranceRoundabout = new Room("on the roundabout"); 69 this.aRooms.put("EntranceRoundabout", new Room("on the roundabout"));
67 70
68 Room vWingStreet = new Room("in font of wing #3"); 71 this.aRooms.put("WingStreet", new Room("in font of wing #3"));
69 Room vWingCorridorOne = new Room("in the corridor in wing #3, on the ground floor"); 72 this.aRooms.put("WingCorridorOne", new Room("in the corridor in wing #3, on the ground floor"));
70 Room vWingStairsOne = new Room("in the stairwell on the ground floor"); 73 this.aRooms.put("WingStairsOne", new Room("in the stairwell on the ground floor"));
71 Room vWingStairsTwo = new Room("in the stairwell on the first floor"); 74 this.aRooms.put("WingStairsTwo", new Room("in the stairwell on the first floor"));
72 Room vWingCorridorTwo = new Room("in the corridor in wind #3, on the first floor"); 75 this.aRooms.put("WingCorridorTwo", new Room("in the corridor in wind #3, on the first floor"));
73 Room vWingCorridorTwoOffice = new Room("in front of the office #3254"); 76 this.aRooms.put("WingCorridorTwoOffice", new Room("in front of the office #3254"));
74 Room vWingOffice = new Room("in the office #3254"); 77 this.aRooms.put("WingOffice", new Room("in the office #3254"));
75 78
76 Room vOffscriptEat = new Room("somewhere implementing hunger"); 79 this.aRooms.put("OffscriptEat", new Room("somewhere implementing hunger"));
77 Room vOffscriptEatPantry = new Room("in the pantry"); 80 this.aRooms.put("OffscriptEatPantry", new Room("in the pantry"));
78 Room vOffscriptTake = new Room("somewhere implementing weight"); 81 this.aRooms.put("OffscriptTake", new Room("somewhere implementing weight"));
79 Room vOffscriptTakeStorageroom = new Room("in a storage room"); 82 this.aRooms.put("OffscriptTakeStorageroom", new Room("in a storage room"));
80 Room vOffscriptTimeout = new Room("somewhere implementing time"); 83 this.aRooms.put("OffscriptTimeout", new Room("somewhere implementing time"));
81 Room vOffscriptTimeoutCountdownroom = new Room("in a dangerous room"); 84 this.aRooms.put("OffscriptTimeoutCountdownroom", new Room("in a dangerous room"));
82 Room vOffscriptTrapdoor = new Room("somewhere implementing a trap"); 85 this.aRooms.put("OffscriptTrapdoor", new Room("somewhere implementing a trap"));
83 Room vOffscriptTrapdoorDeadend = new Room("trapped"); 86 this.aRooms.put("OffscriptTrapdoorDeadend", new Room("trapped"));
84 Room vOffscriptBeamer = new Room("somewhere implementing teleportation"); 87 this.aRooms.put("OffscriptBeamer", new Room("somewhere implementing teleportation"));
85 Room vOffscriptBeamerAnchor = new Room("on a checkpoint"); 88 this.aRooms.put("OffscriptBeamerAnchor", new Room("on a checkpoint"));
86 Room vOffscriptLock = new Room("somewhere implementing a doorlock"); 89 this.aRooms.put("OffscriptLock", new Room("somewhere implementing a doorlock"));
87 Room vOffscriptLockLockedroom = new Room("in a locked room that is not anymore"); 90 this.aRooms.put("OffscriptLockLockedroom", new Room("in a locked room that is not anymore"));
88 Room vOffscriptAlea = new Room("somewhere implementing alea"); 91 this.aRooms.put("OffscriptAlea", new Room("somewhere implementing alea"));
89 Room vOffscriptAleaRoomrandomizer = new Room("in a weird room that will transport you somewhere else"); 92 this.aRooms.put("OffscriptAleaRoomrandomizer", new Room("in a weird room that will transport you somewhere else"));
90 Room vOffscriptMovingcharacter = new Room("somewhere implementing a moving character"); 93 this.aRooms.put("OffscriptMovingcharacter", new Room("somewhere implementing a moving character"));
91 Room vOffscriptMovingcharacterMo = new Room("in M-O's room"); 94 this.aRooms.put("OffscriptMovingcharacterMo", new Room("in M-O's room"));
92 95
93 // connect rooms (N, W, S, E) 96 // connect rooms
94 vAmphitheaterSeat.setExit("north", vAmphitheaterStage); 97 this.aRooms.get("AmphitheaterSeat").setExit("north", this.aRooms.get("AmphitheaterStage"));
95 vAmphitheaterStage.setExit("west", vCafeteria); 98 this.aRooms.get("AmphitheaterStage").setExit("west", this.aRooms.get("Cafeteria"));
96 99
97 vCafeteriaStreet.setExit("south", vCafeteria); 100 this.aRooms.get("CafeteriaStreet").setExit("south", this.aRooms.get("Cafeteria"));
98 vCafeteriaStreet.setExit("east", vEsieespaceStreet); 101 this.aRooms.get("CafeteriaStreet").setExit("east", this.aRooms.get("EsieespaceStreet"));
99