1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
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
*
* @version February 2014
*/
public class Game {
private Room aCurrentRoom;
private Parser aParser;
/**
* Create the game and initialize its internal map.
*/
public Game() {
this.createRooms();
this.printWelcome();
this.printLocationInfo();
this.play();
}
/**
* Main play routine. Loops until end of play.
*/
private void play() {
aParser = new Parser();
boolean vFinished = false;
while (!vFinished) {
Command vCommand = this.aParser.getCommand();
vFinished = this.processCommand(vCommand);
}
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");
Room vAmphitheaterStage = 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");
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");
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");
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");
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");
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");
// connect rooms (N, W, S, E)
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("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);
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;
}
/**
* 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?");
return;
}
Room vNextRoom = aCurrentRoom.getExit(pCommand.getSecondWord());
if (vNextRoom == null) {
System.out.println("There is no door!");
return;
}
this.aCurrentRoom = vNextRoom;
this.printLocationInfo();
}
private void printLocationInfo() {
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.");
System.out.println("Type 'help' if you need help.");
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.");
System.out.println("");
System.out.println("Your command words are:");
System.out.println(" go quit help");
}
private void look() {
System.out.println(aCurrentRoom.getLongDescription());
}
/**
* "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?");
return false;
}
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()) {
case "go":
this.goRoom(pCommand);
return false;
case "look":
this.look();
return false;
case "help":
this.printHelp();
return false;
case "quit":
return this.quit(pCommand);
}
}
System.out.println("I don't know what you mean...");
return false;
}
}
|