aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-02-22 21:33:10 +0000
committerPacien TRAN-GIRARD2014-02-22 21:33:10 +0000
commit425eb18d5c5ace5d20c0514150fdc2be3870437e (patch)
tree093298bd9e33106a8f5768231065fcc28513c3a2
parent943c60abf4a867b2e932db42e5f9cec85a1fb89c (diff)
parent7364c562adb8a5c2ababe5b6ca50100751965603 (diff)
downloadesieequest-425eb18d5c5ace5d20c0514150fdc2be3870437e.tar.gz
Merge branch 'zuul-bad' into 'master'
Zuul Bad
-rw-r--r--src/esieequest/Command.java35
-rw-r--r--src/esieequest/CommandWords.java37
-rw-r--r--src/esieequest/Game.java221
-rwxr-xr-xsrc/esieequest/Main.java22
-rw-r--r--src/esieequest/Parser.java63
-rw-r--r--src/esieequest/Room.java36
6 files changed, 397 insertions, 17 deletions
diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java
new file mode 100644
index 0000000..de6b853
--- /dev/null
+++ b/src/esieequest/Command.java
@@ -0,0 +1,35 @@
1package esieequest;
2
3/**
4 * A text command that triggers an action in the game.
5 *
6 * @author Pacien TRAN-GIRARD
7 * @author Benoit LUBRANO DI SBARAGLIONE
8 *
9 * @version February 2014
10 */
11public class Command {
12 private String aCommandWord;
13 private String aSecondWord;
14
15 public Command(final String pCommandWord, final String pSecondWord) {
16 this.aCommandWord = pCommandWord;
17 this.aSecondWord = pSecondWord;
18 }
19
20 public String getCommandWord() {
21 return this.aCommandWord;
22 }
23
24 public String getSecondWord() {
25 return this.aSecondWord;
26 }
27
28 public boolean isUnknown() {
29 return this.aCommandWord == null;
30 }
31
32 public boolean hasSecondWord() {
33 return this.aSecondWord != null;
34 }
35}
diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java
new file mode 100644
index 0000000..3a77015
--- /dev/null
+++ b/src/esieequest/CommandWords.java
@@ -0,0 +1,37 @@
1package esieequest;
2
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.
8 * It is used to recognise commands as they are typed in.
9 *
10 * @author Michael Kolling and David J. Barnes + D.Bureau
11 * @version 2008.03.30 + 2013.09.15
12 */
13public class CommandWords {
14 // a constant array that holds all valid command words
15 private static final String[] sValidCommands = { "go", "quit", "help" };
16
17 /**
18 * Constructor - initialise the command words.
19 */
20 public CommandWords() {
21 // nothing to do at the moment...
22 } // CommandWords()
23
24 /**
25 * Check whether a given String is a valid command word.
26 *
27 * @return true if a given string is a valid command, false if it isn't.
28 */
29 public boolean isCommand(final String pString) {
30 for (int i = 0; i < sValidCommands.length; i++) {
31 if (sValidCommands[i].equals(pString))
32 return true;
33 } // for
34 // if we get here, the string was not found in the commands
35 return false;
36 } // isCommand()
37} // CommandWords
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java
new file mode 100644
index 0000000..89b7318
--- /dev/null
+++ b/src/esieequest/Game.java
@@ -0,0 +1,221 @@
1package esieequest;
2
3/**
4 * The game engine.
5 *
6 * @author Pacien TRAN-GIRARD
7 * @author Benoit LUBRANO DI SBARAGLIONE
8 *
9 * @version February 2014
10 */
11public class Game {
12 private Room aCurrentRoom;
13 private Parser aParser;
14
15 public Game() {
16 this.createRooms();
17 this.printWelcome();
18 this.printRoomInfo();
19 this.play();
20 }
21
22 private void play() {
23 aParser = new Parser();
24 boolean vFinished = false;
25 while (!vFinished) {
26 Command vCommand = this.aParser.getCommand();
27 vFinished = this.processCommand(vCommand);
28 }
29
30 System.out.println("Thank you for playing. Good bye.");
31 }
32
33 private void createRooms() {
34 // create rooms
35 Room vAmphitheaterSeat = new Room("in the amphitheater");
36 Room vAmphitheaterStage = new Room("on the amphitheater stage");
37
38 Room vCafeteriaStreet = new Room("in the main corridor, in front of the cafeteria");
39 Room vCafeteria = new Room("at the cafeteria");
40
41 Room vEsieespaceStreet = new Room("in the main corridor, in front of the ESIEEspace HQ");
42 Room vEsieespaceFront = new Room("in front of the ESIEEspace HQ");
43 Room vEsieespaceEntrance = new Room("at the ESIEEspace HQ entrance");
44 Room vEsieespace = new Room("in the ESIEEspace HQ");
45
46 Room vClubnixStreet = new Room("in the main corridor, in front of the Club*Nix");
47 Room vClubnixFront = new Room("in front of the Club*Nix");
48 Room vClubnixEntrance = new Room("at the Club*Nix entrance");
49 Room vClubnix = new Room("in the Club*Nix");
50
51 Room vEntranceStreet = new Room("in the main corridor, at the reception");
52 Room vEntranceStairs = new Room("on the main entrance stairs");
53 Room vEntranceRoundabout = new Room("on the roundabout");
54
55 Room vWingStreet = new Room("in font of wing #3");
56 Room vWingCorridorOne = new Room("in the corridor in wing #3, on the ground floor");
57 Room vWingStairsOne = new Room("in the stairwell on the ground floor");
58 Room vWingStairsTwo = new Room("in the stairwell on the first floor");
59 Room vWingCorridorTwo = new Room("in the corridor in wind #3, on the first floor");
60 Room vWingCorridorTwoOffice = new Room("in front of the office #3254");
61 Room vWingOffice = new Room("in the office #3254");
62
63 Room vOffscriptEat = new Room("somewhere implementing hunger");
64 Room vOffscriptEatPantry = new Room("in the pantry");
65 Room vOffscriptTake = new Room("somewhere implementing weight");
66 Room vOffscriptTakeStorageroom = new Room("in a storage room");
67 Room vOffscriptTimeout = new Room("somewhere implementing time");
68 Room vOffscriptTimeoutCountdownroom = new Room("in a dangerous room");
69 Room vOffscriptTrapdoor = new Room("somewhere implementing a trap");
70 Room vOffscriptTrapdoorDeadend = new Room("trapped");
71 Room vOffscriptBeamer = new Room("somewhere implementing teleportation");
72 Room vOffscriptBeamerAnchor = new Room("on a checkpoint");
73 Room vOffscriptLock = new Room("somewhere implementing a doorlock");
74 Room vOffscriptLockLockedroom = new Room("in a locked room that is not anymore");
75 Room vOffscriptAlea = new Room("somewhere implementing alea");
76 Room vOffscriptAleaRoomrandomizer = new Room("in a weird room that will transport you somewhere else");
77 Room vOffscriptMovingcharacter = new Room("somewhere implementing a moving character");
78 Room vOffscriptMovingcharacterMo = new Room("in M-O's room");
79
80 // connect rooms (N, W, S, E)
81 vAmphitheaterSeat.setExits(vAmphitheaterStage, null, null, null);
82 vAmphitheaterStage.setExits(null, vCafeteria, null, null);
83
84 vCafeteriaStreet.setExits(null, null, vCafeteria, vEsieespaceStreet);
85 vCafeteria.setExits(vCafeteriaStreet, null, null, vAmphitheaterStage);
86
87 vEsieespaceStreet.setExits(null, vCafeteria, vEsieespaceFront, vEntranceStreet);
88 vEsieespaceFront.setExits(vEsieespaceStreet, null, null, vEsieespaceEntrance);
89 vEsieespaceEntrance.setExits(vEsieespace, vEsieespaceFront, null, null);
90 vEsieespace.setExits(null, null, vEsieespaceEntrance, null);
91
92 vClubnixStreet.setExits(null, vWingStreet, vClubnixFront, null);
93 vClubnixFront.setExits(vClubnixStreet, null, null, vClubnixEntrance);
94 vClubnixEntrance.setExits(vClubnix, vClubnixFront, null, null);
95 vClubnix.setExits(null, null, vClubnixEntrance, null);
96
97 vEntranceStreet.setExits(null, vEsieespaceStreet, vEntranceStairs, vWingStreet);
98 vEntranceStairs.setExits(vEntranceStreet, null, vEntranceRoundabout, null);
99 vEntranceRoundabout.setExits(vEntranceStairs, null, null, null);
100
101 vWingStreet.setExits(vWingCorridorOne, vEntranceStreet, null, vClubnixStreet);
102 vWingCorridorOne.setExits(null, vWingStairsOne, vWingStreet, vOffscriptEat);
103 vWingStairsOne.setExits(null, null, vWingStairsTwo, vWingCorridorOne);
104 vWingStairsTwo.setExits(null, null, vWingStairsOne, vWingCorridorTwo);
105 vWingCorridorTwo.setExits(vWingCorridorTwoOffice, null, null, null);
106 vWingCorridorTwoOffice.setExits(null, null, vWingCorridorTwo, vWingOffice);
107 vWingOffice.setExits(null, vWingCorridorTwoOffice, null, null);
108
109 vOffscriptEat.setExits(vOffscriptEatPantry, vWingCorridorOne, null, vOffscriptTake);
110 vOffscriptEatPantry.setExits(null, null, vOffscriptEat, null);
111 vOffscriptTake.setExits(vOffscriptTakeStorageroom, vOffscriptEat, null, vOffscriptTimeout);
112 vOffscriptTakeStorageroom.setExits(null, null, vOffscriptTake, null);
113 vOffscriptTimeout.setExits(vOffscriptTimeoutCountdownroom, vOffscriptTakeStorageroom, null, vOffscriptTrapdoor);
114 vOffscriptTimeoutCountdownroom.setExits(null, null, vOffscriptTimeout, null);
115 vOffscriptTrapdoor.setExits(vOffscriptTrapdoorDeadend, vOffscriptTimeout, null, vOffscriptBeamer);
116 vOffscriptTrapdoorDeadend.setExits(null, null, vOffscriptTrapdoor, null);
117 vOffscriptBeamer.setExits(vOffscriptBeamerAnchor, vOffscriptTrapdoor, null, vOffscriptLock);
118 vOffscriptBeamerAnchor.setExits(null, null, vOffscriptBeamer, null);
119 vOffscriptLock.setExits(vOffscriptLockLockedroom, vOffscriptBeamer, null, vOffscriptAlea);
120 vOffscriptLockLockedroom.setExits(null, null, vOffscriptLock, null);
121 vOffscriptAlea.setExits(vOffscriptAleaRoomrandomizer, vOffscriptLock, null, vOffscriptMovingcharacter);
122 vOffscriptAleaRoomrandomizer.setExits(null, null, vOffscriptAlea, null);
123 vOffscriptMovingcharacter.setExits(vOffscriptMovingcharacterMo, vOffscriptAlea, null, null);
124
125 // set the starting room
126 this.aCurrentRoom = vAmphitheaterSeat;
127 }
128
129 public void goRoom(final Command pCommand) {
130 if (!pCommand.hasSecondWord()) {
131 System.out.println("Go where?");
132 return;
133 }
134
135 Room vNextRoom;
136 switch (pCommand.getSecondWord()) {
137 case "north":
138 vNextRoom = this.aCurrentRoom.aNorthExit;
139 break;
140 case "south":
141 vNextRoom = this.aCurrentRoom.aSouthExit;
142 break;