diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/esieequest/Command.java | 37 | ||||
-rw-r--r-- | src/esieequest/Game.java | 201 | ||||
-rwxr-xr-x | src/esieequest/Main.java | 5 | ||||
-rw-r--r-- | src/esieequest/Room.java | 78 | ||||
-rw-r--r-- | src/esieequest/package-info.java | 5 |
5 files changed, 233 insertions, 93 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 89b7318..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,13 +16,19 @@ 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(); |
18 | this.printRoomInfo(); | 25 | this.printLocationInfo(); |
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"); |
@@ -78,78 +91,101 @@ public class Game { | |||
78 | Room vOffscriptMovingcharacterMo = new Room("in M-O's room"); | 91 | Room vOffscriptMovingcharacterMo = new Room("in M-O's room"); |
79 | 92 | ||
80 | // connect rooms (N, W, S, E) | 93 | // connect rooms (N, W, S, E) |
81 | vAmphitheaterSeat.setExits(vAmphitheaterStage, null, null, null); | 94 | vAmphitheaterSeat.setExit("north", vAmphitheaterStage); |
82 | vAmphitheaterStage.setExits(null, vCafeteria, null, null); | 95 | vAmphitheaterStage.setExit("west", vCafeteria); |
83 | 96 | ||
84 | vCafeteriaStreet.setExits(null, null, vCafeteria, vEsieespaceStreet); | 97 | vCafeteriaStreet.setExit("south", vCafeteria); |
85 | vCafeteria.setExits(vCafeteriaStreet, null, null, vAmphitheaterStage); | 98 | vCafeteriaStreet.setExit("east", vEsieespaceStreet); |
86 | 99 | vCafeteria.setExit("north", vCafeteriaStreet); | |
87 | vEsieespaceStreet.setExits(null, vCafeteria, vEsieespaceFront, vEntranceStreet); | 100 | vCafeteria.setExit("east", vAmphitheaterStage); |
88 | vEsieespaceFront.setExits(vEsieespaceStreet, null, null, vEsieespaceEntrance); | 101 | |
89 | vEsieespaceEntrance.setExits(vEsieespace, vEsieespaceFront, null, null); | 102 | vEsieespaceStreet.setExit("west", vCafeteria); |
90 | vEsieespace.setExits(null, null, vEsieespaceEntrance, null); | 103 | vEsieespaceStreet.setExit("south", vEsieespaceFront); |
91 | 104 | vEsieespaceStreet.setExit("east", vEntranceStreet); | |
92 | vClubnixStreet.setExits(null, vWingStreet, vClubnixFront, null); | 105 | vEsieespaceFront.setExit("north", vEsieespaceStreet); |
93 | vClubnixFront.setExits(vClubnixStreet, null, null, vClubnixEntrance); | 106 | vEsieespaceFront.setExit("east", vEsieespaceEntrance); |
94 | vClubnixEntrance.setExits(vClubnix, vClubnixFront, null, null); | 107 | vEsieespaceEntrance.setExit("north", vEsieespace); |
95 | vClubnix.setExits(null, null, vClubnixEntrance, null); | 108 | vEsieespaceEntrance.setExit("west", vEsieespaceFront); |
96 | 109 | vEsieespace.setExit("south", vEsieespaceEntrance); | |
97 | vEntranceStreet.setExits(null, vEsieespaceStreet, vEntranceStairs, vWingStreet); | 110 | |
98 | vEntranceStairs.setExits(vEntranceStreet, null, vEntranceRoundabout, null); | 111 | vClubnixStreet.setExit("west", vWingStreet); |
99 | vEntranceRoundabout.setExits(vEntranceStairs, null, null, null); | 112 | vClubnixStreet.setExit("south", vClubnixFront); |
100 | 113 | vClubnixFront.setExit("north", vClubnixStreet); | |
101 | vWingStreet.setExits(vWingCorridorOne, vEntranceStreet, null, vClubnixStreet); | 114 | vClubnixFront.setExit("east", vClubnixEntrance); |
102 | vWingCorridorOne.setExits(null, vWingStairsOne, vWingStreet, vOffscriptEat); | 115 | vClubnixEntrance.setExit("north", vClubnix); |
103 | vWingStairsOne.setExits(null, null, vWingStairsTwo, vWingCorridorOne); | 116 | vClubnixEntrance.setExit("west", vClubnixFront); |
104 | vWingStairsTwo.setExits(null, null, vWingStairsOne, vWingCorridorTwo); | 117 | vClubnix.setExit("south", vClubnixEntrance); |
105 | vWingCorridorTwo.setExits(vWingCorridorTwoOffice, null, null, null); | 118 | |
106 | vWingCorridorTwoOffice.setExits(null, null, vWingCorridorTwo, vWingOffice); | 119 | vEntranceStreet.setExit("west", vEsieespaceStreet); |
107 | vWingOffice.setExits(null, vWingCorridorTwoOffice, null, null); | 120 | vEntranceStreet.setExit("south", vEntranceStairs); |
108 | 121 | vEntranceStreet.setExit("east", vWingStreet); | |
109 | vOffscriptEat.setExits(vOffscriptEatPantry, vWingCorridorOne, null, vOffscriptTake); | 122 | vEntranceStairs.setExit("north", vEntranceStreet); |
110 | vOffscriptEatPantry.setExits(null, null, vOffscriptEat, null); | 123 | vEntranceStairs.setExit("south", vEntranceRoundabout); |
111 | vOffscriptTake.setExits(vOffscriptTakeStorageroom, vOffscriptEat, null, vOffscriptTimeout); | 124 | vEntranceRoundabout.setExit("north", vEntranceStairs); |
112 | vOffscriptTakeStorageroom.setExits(null, null, vOffscriptTake, null); | 125 | |
113 | vOffscriptTimeout.setExits(vOffscriptTimeoutCountdownroom, vOffscriptTakeStorageroom, null, vOffscriptTrapdoor); | 126 | vWingStreet.setExit("north", vWingCorridorOne); |
114 | vOffscriptTimeoutCountdownroom.setExits(null, null, vOffscriptTimeout, null); | 127 | vWingStreet.setExit("west", vEntranceStreet); |
115 | vOffscriptTrapdoor.setExits(vOffscriptTrapdoorDeadend, vOffscriptTimeout, null, vOffscriptBeamer); | 128 | vWingStreet.setExit("east", vClubnixStreet); |
116 | vOffscriptTrapdoorDeadend.setExits(null, null, vOffscriptTrapdoor, null); | 129 | vWingCorridorOne.setExit("west", vWingStairsOne); |
117 | vOffscriptBeamer.setExits(vOffscriptBeamerAnchor, vOffscriptTrapdoor, null, vOffscriptLock); | 130 | vWingCorridorOne.setExit("south", vWingStreet); |
118 | vOffscriptBeamerAnchor.setExits(null, null, vOffscriptBeamer, null); | 131 | vWingCorridorOne.setExit("east", vOffscriptEat); |
119 | vOffscriptLock.setExits(vOffscriptLockLockedroom, vOffscriptBeamer, null, vOffscriptAlea); | 132 | vWingStairsOne.setExit("south", vWingStairsTwo); |
120 | vOffscriptLockLockedroom.setExits(null, null, vOffscriptLock, null); | 133 | vWingStairsOne.setExit("up", vWingStairsTwo); |
121 | vOffscriptAlea.setExits(vOffscriptAleaRoomrandomizer, vOffscriptLock, null, vOffscriptMovingcharacter); | 134 | vWingStairsOne.setExit("east", vWingCorridorOne); |
122 | vOffscriptAleaRoomrandomizer.setExits(null, null, vOffscriptAlea, null); | 135 | vWingStairsTwo.setExit("south", vWingStairsOne); |
123 | vOffscriptMovingcharacter.setExits(vOffscriptMovingcharacterMo, vOffscriptAlea, null, null); | 136 | vWingStairsTwo.setExit("down", vWingStairsOne); |
137 | vWingStairsTwo.setExit("east", vWingCorridorTwo); | ||
138 | vWingCorridorTwo.setExit("north", vWingCorridorTwoOffice); | ||
139 | vWingCorridorTwoOffice.setExit("south", vWingCorridorTwo); | ||
140 | vWingCorridorTwoOffice.setExit("east", vWingOffice); | ||
141 | vWingOffice.setExit("west", vWingCorridorTwoOffice); | ||
142 | |||
143 | vOffscriptEat.setExit("north", vOffscriptEatPantry); | ||
144 | vOffscriptEat.setExit("west", vWingCorridorOne); | ||
145 | vOffscriptEat.setExit("east", vOffscriptTake); | ||
146 | vOffscriptEatPantry.setExit("south", vOffscriptEat); | ||
147 | vOffscriptTake.setExit("north", vOffscriptTakeStorageroom); | ||
148 | vOffscriptTake.setExit("west", vOffscriptEat); | ||
149 | vOffscriptTake.setExit("east", vOffscriptTimeout); | ||
150 | vOffscriptTakeStorageroom.setExit("south", vOffscriptTake); | ||
151 | vOffscriptTimeout.setExit("north", vOffscriptTimeoutCountdownroom); | ||