diff options
-rw-r--r-- | src/esieequest/Command.java | 37 | ||||
-rw-r--r-- | src/esieequest/Game.java | 37 | ||||
-rwxr-xr-x | src/esieequest/Main.java | 5 | ||||
-rw-r--r-- | src/esieequest/Room.java | 12 | ||||
-rw-r--r-- | src/esieequest/package-info.java | 5 |
5 files changed, 94 insertions, 2 deletions
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; | |||
3 | /** | 3 | /** |
4 | * A text command that triggers an action in the game. | 4 | * A text command that triggers an action in the game. |
5 | * | 5 | * |
6 | * This class holds information about a command that was issued by the user. A | ||
7 | * command currently consists of two strings: a command word and a second word | ||
8 | * (for example, if the command was "take map", then the two strings obviously | ||
9 | * are "take" and "map"). | ||
10 | * | ||
11 | * The way this is used is: Commands are already checked for being valid command | ||
12 | * words. If the user entered an invalid command (a word that is not known) then | ||
13 | * the command word is <null>. | ||
14 | * | ||
15 | * If the command had only one word, then the second word is <null>. | ||
16 | * | ||
6 | * @author Pacien TRAN-GIRARD | 17 | * @author Pacien TRAN-GIRARD |
7 | * @author Benoit LUBRANO DI SBARAGLIONE | 18 | * @author Benoit LUBRANO DI SBARAGLIONE |
8 | * | 19 | * |
@@ -12,23 +23,49 @@ public class Command { | |||
12 | private String aCommandWord; | 23 | private String aCommandWord; |
13 | private String aSecondWord; | 24 | private String aSecondWord; |
14 | 25 | ||
26 | /** | ||
27 | * Create a command object. First and second word must be supplied, but | ||
28 | * either one (or both) can be null. | ||
29 | * | ||
30 | * @param firstWord | ||
31 | * The first word of the command. Null if the command was not | ||
32 | * recognised. | ||
33 | * @param secondWord | ||
34 | * The second word of the command. | ||
35 | */ | ||
15 | public Command(final String pCommandWord, final String pSecondWord) { | 36 | public Command(final String pCommandWord, final String pSecondWord) { |
16 | this.aCommandWord = pCommandWord; | 37 | this.aCommandWord = pCommandWord; |
17 | this.aSecondWord = pSecondWord; | 38 | this.aSecondWord = pSecondWord; |
18 | } | 39 | } |
19 | 40 | ||
41 | /** | ||
42 | * Return the command word (the first word) of this command. If the command | ||
43 | * was not understood, the result is null. | ||
44 | * | ||
45 | * @return The command word. | ||
46 | */ | ||
20 | public String getCommandWord() { | 47 | public String getCommandWord() { |
21 | return this.aCommandWord; | 48 | return this.aCommandWord; |
22 | } | 49 | } |
23 | 50 | ||
51 | /** | ||
52 | * @return The second word of this command. Returns null if there was no | ||
53 | * second word. | ||
54 | */ | ||
24 | public String getSecondWord() { | 55 | public String getSecondWord() { |
25 | return this.aSecondWord; | 56 | return this.aSecondWord; |
26 | } | 57 | } |
27 | 58 | ||
59 | /** | ||
60 | * @return true if this command was not understood. | ||
61 | */ | ||
28 | public boolean isUnknown() { | 62 | public boolean isUnknown() { |
29 | return this.aCommandWord == null; | 63 | return this.aCommandWord == null; |
30 | } | 64 | } |
31 | 65 | ||
66 | /** | ||
67 | * @return true if the command has a second word. | ||
68 | */ | ||
32 | public boolean hasSecondWord() { | 69 | public boolean hasSecondWord() { |
33 | return this.aSecondWord != null; | 70 | return this.aSecondWord != null; |
34 | } | 71 | } |
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; | |||
3 | /** | 3 | /** |
4 | * The game engine. | 4 | * The game engine. |
5 | * | 5 | * |
6 | * This class creates and initializes all the others: it creates all rooms, | ||
7 | * creates the parser and starts the game. It also evaluates and executes the | ||
8 | * commands that the parser returns. | ||
9 | * | ||
6 | * @author Pacien TRAN-GIRARD | 10 | * @author Pacien TRAN-GIRARD |
7 | * @author Benoit LUBRANO DI SBARAGLIONE | 11 | * @author Benoit LUBRANO DI SBARAGLIONE |
8 | * | 12 | * |
@@ -12,6 +16,9 @@ public class Game { | |||
12 | private Room aCurrentRoom; | 16 | private Room aCurrentRoom; |
13 | private Parser aParser; | 17 | private Parser aParser; |
14 | 18 | ||
19 | /** | ||
20 | * Create the game and initialize its internal map. | ||
21 | */ | ||
15 | public Game() { | 22 | public Game() { |
16 | this.createRooms(); | 23 | this.createRooms(); |
17 | this.printWelcome(); | 24 | this.printWelcome(); |
@@ -19,6 +26,9 @@ public class Game { | |||
19 | this.play(); | 26 | this.play(); |
20 | } | 27 | } |
21 | 28 | ||
29 | /** | ||
30 | * Main play routine. Loops until end of play. | ||
31 | */ | ||
22 | private void play() { | 32 | private void play() { |
23 | aParser = new Parser(); | 33 | aParser = new Parser(); |
24 | boolean vFinished = false; | 34 | boolean vFinished = false; |
@@ -30,6 +40,9 @@ public class Game { | |||
30 | System.out.println("Thank you for playing. Good bye."); | 40 | System.out.println("Thank you for playing. Good bye."); |
31 | } | 41 | } |
32 | 42 | ||
43 | /** | ||
44 | * Create all the rooms and link their exits together. | ||
45 | */ | ||
33 | private void createRooms() { | 46 | private void createRooms() { |
34 | // create rooms | 47 | // create rooms |
35 | Room vAmphitheaterSeat = new Room("in the amphitheater"); | 48 | Room vAmphitheaterSeat = new Room("in the amphitheater"); |
@@ -162,6 +175,10 @@ public class Game { | |||
162 | this.aCurrentRoom = vAmphitheaterSeat; | 175 | this.aCurrentRoom = vAmphitheaterSeat; |
163 | } | 176 | } |
164 | 177 | ||
178 | /** | ||
179 | * Try to go in one direction. If there is an exit, enter the new room, | ||
180 | * otherwise print an error message. | ||
181 | */ | ||
165 | public void goRoom(final Command pCommand) { | 182 | public void goRoom(final Command pCommand) { |
166 | if (!pCommand.hasSecondWord()) { | 183 | if (!pCommand.hasSecondWord()) { |
167 | System.out.println("Go where?"); | 184 | System.out.println("Go where?"); |
@@ -183,6 +200,9 @@ public class Game { | |||
183 | System.out.println(this.aCurrentRoom.getLongDescription()); | 200 | System.out.println(this.aCurrentRoom.getLongDescription()); |
184 | } | 201 | } |
185 | 202 | ||
203 | /** | ||
204 | * Print out the opening message for the player. | ||
205 | */ | ||
186 | private void printWelcome() { | 206 | private void printWelcome() { |
187 | System.out.println("Welcome to ESIEEquest"); | 207 | System.out.println("Welcome to ESIEEquest"); |
188 | System.out.println("ESIEEquest is a new, incredibly surprising adventure game."); | 208 | System.out.println("ESIEEquest is a new, incredibly surprising adventure game."); |
@@ -190,6 +210,10 @@ public class Game { | |||
190 | System.out.println(""); | 210 | System.out.println(""); |
191 | } | 211 | } |
192 | 212 | ||
213 | /** | ||
214 | * Print out some help information. Here we print some stupid, cryptic | ||
215 | * message and a list of the command words. | ||
216 | */ | ||
193 | private void printHelp() { | 217 | private void printHelp() { |
194 | System.out.println("You are lost. You are alone. "); | 218 | System.out.println("You are lost. You are alone. "); |
195 | System.out.println("You wander around at the university."); | 219 | System.out.println("You wander around at the university."); |
@@ -198,6 +222,12 @@ public class Game { | |||
198 | System.out.println(" go quit help"); | 222 | System.out.println(" go quit help"); |
199 | } | 223 | } |
200 | 224 | ||
225 | /** | ||
226 | * "Quit" was entered. Check the rest of the command to see whether we | ||
227 | * really quit the game. | ||
228 | * | ||
229 | * @return true, if this command quits the game, false otherwise. | ||
230 | */ | ||
201 | private boolean quit(final Command pCommand) { | 231 | private boolean quit(final Command pCommand) { |
202 | if (pCommand.hasSecondWord()) { | 232 | if (pCommand.hasSecondWord()) { |
203 | System.out.println("Quit what?"); | 233 | System.out.println("Quit what?"); |
@@ -206,6 +236,13 @@ public class Game { | |||
206 | return true; | 236 | return true; |
207 | } | 237 | } |
208 | 238 | ||
239 | /** | ||
240 | * Given a command, process (that is: execute) the command. | ||
241 | * | ||
242 | * @param command | ||
243 | * The command to be processed. | ||
244 | * @return true If the command ends the game, false otherwise. | ||
245 | */ | ||
209 | private boolean processCommand(final Command pCommand) { | 246 | private boolean processCommand(final Command pCommand) { |
210 | if (pCommand.getCommandWord() != null) { | 247 | if (pCommand.getCommandWord() != null) { |
211 | switch (pCommand.getCommandWord()) { | 248 | 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 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * The Main class | ||
5 | * | ||
6 | * This class instantiates the game and makes it possible to run it via the | ||
7 | * command line. | ||
8 | * | ||
4 | * @author Pacien TRAN-GIRARD | 9 | * @author Pacien TRAN-GIRARD |
5 | * @author Benoit LUBRANO DI SBARAGLIONE | 10 | * @author Benoit LUBRANO DI SBARAGLIONE |
6 | * | 11 | * |
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; | |||
6 | /** | 6 | /** |
7 | * A room. | 7 | * A room. |
8 | * | 8 | * |
9 | * A "Room" represents one location in the scenery of the game. It is connected | ||
10 | * to other rooms via exits. The exits are labelled north, east, south, west. | ||
11 | * For each direction, the room stores a reference to the neighboring room, or | ||
12 | * null if there is no exit in that direction. | ||
13 | * | ||
9 | * @author Pacien TRAN-GIRARD | 14 | * @author Pacien TRAN-GIRARD |