diff options
-rw-r--r-- | src/esieequest/Command.java | 6 | ||||
-rw-r--r-- | src/esieequest/Game.java | 261 | ||||
-rw-r--r-- | src/esieequest/GameEngine.java | 270 | ||||
-rw-r--r-- | src/esieequest/Parser.java | 21 | ||||
-rw-r--r-- | src/esieequest/Room.java | 16 | ||||
-rw-r--r-- | src/esieequest/UserInterface.java | 135 |
6 files changed, 436 insertions, 273 deletions
diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java index fd05930..14c3d32 100644 --- a/src/esieequest/Command.java +++ b/src/esieequest/Command.java | |||
@@ -1,8 +1,6 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * A text command that triggers an action in the game. | ||
5 | * | ||
6 | * This class holds information about a command that was issued by the user. A | 4 | * 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 | 5 | * 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 | 6 | * (for example, if the command was "take map", then the two strings obviously |
@@ -33,8 +31,8 @@ public class Command { | |||
33 | * @param secondWord | 31 | * @param secondWord |
34 | * The second word of the command. | 32 | * The second word of the command. |
35 | */ | 33 | */ |
36 | public Command(final String pCommandWord, final String pSecondWord) { | 34 | public Command(final String pFirstWord, final String pSecondWord) { |
37 | this.aCommandWord = pCommandWord; | 35 | this.aCommandWord = pFirstWord; |
38 | this.aSecondWord = pSecondWord; | 36 | this.aSecondWord = pSecondWord; |
39 | } | 37 | } |
40 | 38 | ||
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 43db8f7..925f067 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java | |||
@@ -1,7 +1,5 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | import java.util.HashMap; | ||
4 | |||
5 | /** | 3 | /** |
6 | * The game engine. | 4 | * The game engine. |
7 | * | 5 | * |
@@ -15,262 +13,15 @@ import java.util.HashMap; | |||
15 | * @version February 2014 | 13 | * @version February 2014 |
16 | */ | 14 | */ |
17 | public class Game { | 15 | public class Game { |
18 | private HashMap<String, Room> aRooms; | 16 | private UserInterface aGui; |
19 | private Room aCurrentRoom; | 17 | private GameEngine aEngine; |
20 | private Parser aParser; | ||
21 | 18 | ||
22 | /** | 19 | /** |
23 | * Create the game and initialize its internal map. | 20 | * Create the game and initialise its internal map. |
24 | */ | 21 | */ |
25 | public Game() { | 22 | public Game() { |
26 | this.aRooms = new HashMap<String, Room>(); | 23 | this.aEngine = new GameEngine(); |
27 | this.createRooms(); | 24 | this.aGui = new UserInterface(this.aEngine); |
28 | this.aParser = new Parser(); | 25 | this.aEngine.setGUI(this.aGui); |
29 | this.play(); | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * Main play routine. Loops until end of play. | ||
34 | */ | ||
35 | private void play() { | ||
36 | this.printWelcome(); | ||
37 | boolean vFinished = false; | ||
38 | while (!vFinished) { | ||
39 | Command vCommand = this.aParser.getCommand(); | ||
40 | vFinished = this.processCommand(vCommand); | ||
41 | } | ||
42 | |||
43 | System.out.println("Thank you for playing. Good bye."); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Create all the rooms and link their exits together. | ||
48 | */ | ||
49 | private void createRooms() { | ||
50 | // create rooms | ||
51 | this.aRooms.put("AmphitheaterSeat", new Room("in the amphitheater")); | ||
52 | this.aRooms.put("AmphitheaterStage", new Room("on the amphitheater stage")); | ||
53 | |||
54 | this.aRooms.put("CafeteriaStreet", new Room("in the main corridor, in front of the cafeteria")); | ||
55 | this.aRooms.put("Cafeteria", new Room("at the cafeteria")); | ||
56 | |||
57 | this.aRooms.put("EsieespaceStreet", new Room("in the main corridor, in front of the ESIEEspace HQ")); | ||
58 | this.aRooms.put("EsieespaceFront", new Room("in front of the ESIEEspace HQ")); | ||
59 | this.aRooms.put("EsieespaceEntrance", new Room("at the ESIEEspace HQ entrance")); | ||
60 | this.aRooms.put("Esieespace", new Room("in the ESIEEspace HQ")); | ||
61 | |||
62 | this.aRooms.put("ClubnixStreet", new Room("in the main corridor, in front of the Club*Nix")); | ||
63 | this.aRooms.put("ClubnixFront", new Room("in front of the Club*Nix")); | ||
64 | this.aRooms.put("ClubnixEntrance", new Room("at the Club*Nix entrance")); | ||
65 | this.aRooms.put("Clubnix", new Room("in the Club*Nix")); | ||
66 | |||
67 | this.aRooms.put("EntranceStreet", new Room("in the main corridor, at the reception")); | ||
68 | this.aRooms.put("EntranceStairs", new Room("on the main entrance stairs")); | ||
69 | this.aRooms.put("EntranceRoundabout", new Room("on the roundabout")); | ||
70 | |||
71 | this.aRooms.put("WingStreet", new Room("in font of wing #3")); | ||
72 | this.aRooms.put("WingCorridorOne", new Room("in the corridor in wing #3, on the ground floor")); | ||
73 | this.aRooms.put("WingStairsOne", new Room("in the stairwell on the ground floor")); | ||
74 | this.aRooms.put("WingStairsTwo", new Room("in the stairwell on the first floor")); | ||
75 | this.aRooms.put("WingCorridorTwo", new Room("in the corridor in wind #3, on the first floor")); | ||
76 | this.aRooms.put("WingCorridorTwoOffice", new Room("in front of the office #3254")); | ||
77 | this.aRooms.put("WingOffice", new Room("in the office #3254")); | ||
78 | |||
79 | this.aRooms.put("OffscriptEat", new Room("somewhere implementing hunger")); | ||
80 | this.aRooms.put("OffscriptEatPantry", new Room("in the pantry")); | ||
81 | this.aRooms.put("OffscriptTake", new Room("somewhere implementing weight")); | ||
82 | this.aRooms.put("OffscriptTakeStorageroom", new Room("in a storage room")); | ||
83 | this.aRooms.put("OffscriptTimeout", new Room("somewhere implementing time")); | ||
84 | this.aRooms.put("OffscriptTimeoutCountdownroom", new Room("in a dangerous room")); | ||
85 | this.aRooms.put("OffscriptTrapdoor", new Room("somewhere implementing a trap")); | ||
86 | this.aRooms.put("OffscriptTrapdoorDeadend", new Room("trapped")); | ||
87 | this.aRooms.put("OffscriptBeamer", new Room("somewhere implementing teleportation")); | ||
88 | this.aRooms.put("OffscriptBeamerAnchor", new Room("on a checkpoint")); | ||
89 | this.aRooms.put("OffscriptLock", new Room("somewhere implementing a doorlock")); | ||
90 | this.aRooms.put("OffscriptLockLockedroom", new Room("in a locked room that is not anymore")); | ||
91 | this.aRooms.put("OffscriptAlea", new Room("somewhere implementing alea")); | ||
92 | this.aRooms.put("OffscriptAleaRoomrandomizer", new Room("in a weird room that will transport you somewhere else")); | ||
93 | this.aRooms.put("OffscriptMovingcharacter", new Room("somewhere implementing a moving character")); | ||
94 | this.aRooms.put("OffscriptMovingcharacterMo", new Room("in M-O's room")); | ||
95 | |||
96 | // connect rooms | ||
97 | this.aRooms.get("AmphitheaterSeat").setExit("north", this.aRooms.get("AmphitheaterStage")); | ||
98 | this.aRooms.get("AmphitheaterStage").setExit("west", this.aRooms.get("Cafeteria")); | ||
99 | |||
100 | this.aRooms.get("CafeteriaStreet").setExit("south", this.aRooms.get("Cafeteria")); | ||
101 | this.aRooms.get("CafeteriaStreet").setExit("east", this.aRooms.get("EsieespaceStreet")); | ||
102 | this.aRooms.get("Cafeteria").setExit("north", this.aRooms.get("CafeteriaStreet")); | ||
103 | this.aRooms.get("Cafeteria").setExit("east", this.aRooms.get("AmphitheaterStage")); | ||
104 | |||
105 | this.aRooms.get("EsieespaceStreet").setExit("west", this.aRooms.get("Cafeteria")); | ||
106 | this.aRooms.get("EsieespaceStreet").setExit("south", this.aRooms.get("EsieespaceFront")); | ||
107 | this.aRooms.get("EsieespaceStreet").setExit("east", this.aRooms.get("EntranceStreet")); | ||
108 | this.aRooms.get("EsieespaceFront").setExit("north", this.aRooms.get("EsieespaceStreet")); | ||
109 | this.aRooms.get("EsieespaceFront").setExit("east", this.aRooms.get("EsieespaceEntrance")); | ||
110 | this.aRooms.get("EsieespaceEntrance").setExit("north", this.aRooms.get("Esieespace")); | ||
111 | this.aRooms.get("EsieespaceEntrance").setExit("west", this.aRooms.get("EsieespaceFront")); | ||
112 | this.aRooms.get("Esieespace").setExit("south", this.aRooms.get("EsieespaceEntrance")); | ||
113 | |||
114 | this.aRooms.get("ClubnixStreet").setExit("west", this.aRooms.get("WingStreet")); | ||
115 | this.aRooms.get("ClubnixStreet").setExit("south", this.aRooms.get("ClubnixFront")); | ||
116 | this.aRooms.get("ClubnixFront").setExit("north", this.aRooms.get("ClubnixStreet")); | ||
117 | this.aRooms.get("ClubnixFront").setExit("east", this.aRooms.get("ClubnixEntrance")); | ||
118 | this.aRooms.get("ClubnixEntrance").setExit("north", this.aRooms.get("Clubnix")); | ||
119 | this.aRooms.get("ClubnixEntrance").setExit("west", this.aRooms.get("ClubnixFront")); | ||
120 | this.aRooms.get("Clubnix").setExit("south", this.aRooms.get("ClubnixEntrance")); | ||
121 | |||
122 | this.aRooms.get("EntranceStreet").setExit("west", this.aRooms.get("EsieespaceStreet")); | ||
123 | this.aRooms.get("EntranceStreet").setExit("south", this.aRooms.get("EntranceStairs")); | ||
124 | this.aRooms.get("EntranceStreet").setExit("east", this.aRooms.get("WingStreet")); | ||
125 | this.aRooms.get("EntranceStairs").setExit("north", this.aRooms.get("EntranceStreet")); | ||
126 | this.aRooms.get("EntranceStairs").setExit("south", this.aRooms.get("EntranceRoundabout")); | ||
127 | this.aRooms.get("EntranceRoundabout").setExit("north", this.aRooms.get("EntranceStairs")); | ||
128 | |||
129 | this.aRooms.get("WingStreet").setExit("north", this.aRooms.get("WingCorridorOne")); | ||
130 | this.aRooms.get("WingStreet").setExit("west", this.aRooms.get("EntranceStreet")); | ||
131 | this.aRooms.get("WingStreet").setExit("east", this.aRooms.get("ClubnixStreet")); | ||
132 | this.aRooms.get("WingCorridorOne").setExit("west", this.aRooms.get("WingStairsOne")); | ||
133 | this.aRooms.get("WingCorridorOne").setExit("south", this.aRooms.get("WingStreet")); | ||
134 | this.aRooms.get("WingCorridorOne").setExit("east", this.aRooms.get("OffscriptEat")); | ||
135 | this.aRooms.get("WingStairsOne").setExit("south", this.aRooms.get("WingStairsTwo")); | ||
136 | this.aRooms.get("WingStairsOne").setExit("up", this.aRooms.get("WingStairsTwo")); | ||
137 | this.aRooms.get("WingStairsOne").setExit("east", this.aRooms.get("WingCorridorOne")); | ||
138 | this.aRooms.get("WingStairsTwo").setExit("south", this.aRooms.get("WingStairsOne")); | ||
139 | this.aRooms.get("WingStairsTwo").setExit("down", this.aRooms.get("WingStairsOne")); | ||
140 | this.aRooms.get("WingStairsTwo").setExit("east", this.aRooms.get("WingCorridorTwo")); | ||
141 | this.aRooms.get("WingCorridorTwo").setExit("north", this.aRooms.get("WingCorridorTwoOffice")); | ||
142 | this.aRooms.get("WingCorridorTwoOffice").setExit("south", this.aRooms.get("WingCorridorTwo")); | ||
143 | this.aRooms.get("WingCorridorTwoOffice").setExit("east", this.aRooms.get("WingOffice")); | ||
144 | this.aRooms.get("WingOffice").setExit("west", this.aRooms.get("WingCorridorTwoOffice")); | ||
145 | |||
146 | this.aRooms.get("OffscriptEat").setExit("north", this.aRooms.get("OffscriptEatPantry")); | ||
147 | this.aRooms.get("OffscriptEat").setExit("west", this.aRooms.get("WingCorridorOne")); | ||
148 | this.aRooms.get("OffscriptEat").setExit("east", this.aRooms.get("OffscriptTake")); | ||
149 | this.aRooms.get("OffscriptEatPantry").setExit("south", this.aRooms.get("OffscriptEat")); | ||
150 | this.aRooms.get("OffscriptTake").setExit("north", this.aRooms.get("OffscriptTakeStorageroom")); | ||
151 | this.aRooms.get("OffscriptTake").setExit("west", this.aRooms.get("OffscriptEat")); | ||
152 | this.aRooms.get("OffscriptTake").setExit("east", this.aRooms.get("OffscriptTimeout")); | ||
153 | this.aRooms.get("OffscriptTakeStorageroom").setExit("south", this.aRooms.get("OffscriptTake")); | ||
154 | this.aRooms.get("OffscriptTimeout").setExit("north", this.aRooms.get("OffscriptTimeoutCountdownroom")); | ||
155 | this.aRooms.get("OffscriptTimeout").setExit("west", this.aRooms.get("OffscriptTakeStorageroom")); | ||
156 | this.aRooms.get("OffscriptTimeout").setExit("east", this.aRooms.get("OffscriptTrapdoor")); | ||
157 | this.aRooms.get("OffscriptTimeoutCountdownroom").setExit("south", this.aRooms.get("OffscriptTimeout")); | ||
158 | this.aRooms.get("OffscriptTrapdoor").setExit("north", this.aRooms.get("OffscriptTrapdoorDeadend")); | ||
159 | this.aRooms.get("OffscriptTrapdoor").setExit("west", this.aRooms.get("OffscriptTimeout")); | ||
160 | this.aRooms.get("OffscriptTrapdoor").setExit("east", this.aRooms.get("OffscriptBeamer")); | ||
161 | this.aRooms.get("OffscriptTrapdoorDeadend").setExit("south", this.aRooms.get("OffscriptTrapdoor")); | ||
162 | this.aRooms.get("OffscriptBeamer").setExit("north", this.aRooms.get("OffscriptBeamerAnchor")); | ||
163 | this.aRooms.get("OffscriptBeamer").setExit("west", this.aRooms.get("OffscriptTrapdoor")); | ||
164 | this.aRooms.get("OffscriptBeamer").setExit("east", this.aRooms.get("OffscriptLock")); | ||
165 | this.aRooms.get("OffscriptBeamerAnchor").setExit("south", this.aRooms.get("OffscriptBeamer")); | ||
166 | this.aRooms.get("OffscriptLock").setExit("north", this.aRooms.get("OffscriptLockLockedroom")); | ||
167 | this.aRooms.get("OffscriptLock").setExit("west", this.aRooms.get("OffscriptBeamer")); | ||
168 | this.aRooms.get("OffscriptLock").setExit("east", this.aRooms.get("OffscriptAlea")); | ||
169 | this.aRooms.get("OffscriptLockLockedroom").setExit("south", this.aRooms.get("OffscriptLock")); | ||
170 | this.aRooms.get("OffscriptAlea").setExit("north", this.aRooms.get("OffscriptAleaRoomrandomizer")); | ||
171 | this.aRooms.get("OffscriptAlea").setExit("west", this.aRooms.get("OffscriptLock")); | ||
172 | this.aRooms.get("OffscriptAlea").setExit("east", this.aRooms.get("OffscriptMovingcharacter")); | ||
173 | this.aRooms.get("OffscriptAleaRoomrandomizer").setExit("south", this.aRooms.get("OffscriptAlea")); | ||
174 | this.aRooms.get("OffscriptMovingcharacter").setExit("north", this.aRooms.get("OffscriptMovingcharacterMo")); | ||
175 | this.aRooms.get("OffscriptMovingcharacter").setExit("west", this.aRooms.get("OffscriptAlea")); | ||