|
001 packagepackage is used to name the directory or folder a class is in scg.ch14.core;
002
003 importimport means to make the classes and/or packages available in this program java.io.File;
004 importimport means to make the classes and/or packages available in this program java.io.FileNotFoundException;
005 importimport means to make the classes and/or packages available in this program java.io.FileReader;
006 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
007 importimport means to make the classes and/or packages available in this program java.util.Scanner;
008
009 importimport means to make the classes and/or packages available in this program scg.ch14.dictionary.Dictionary;
010
011 importimport means to make the classes and/or packages available in this program scg.ch14.gamestuff.Critter;
012 importimport means to make the classes and/or packages available in this program scg.ch14.gamestuff.GameObject;
013 importimport means to make the classes and/or packages available in this program scg.ch14.gamestuff.Item;
014 importimport means to make the classes and/or packages available in this program scg.ch14.gamestuff.Location;
015
016 importimport means to make the classes and/or packages available in this program scg.ch14.io.Keyboard;
017 importimport means to make the classes and/or packages available in this program scg.ch14.io.SansCommentFilterReader;
018
019 importimport means to make the classes and/or packages available in this program scg.ch14.util.ReadAndWrite;
020
021 /**
022 * Text adventure game phase all items. Reads the map, cast, and props.
023 * Permits moving around the map, seeing the description of each
024 * location, items and all of that.
025 */
026 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Game {open braces start code blocks and must be matched with a close brace
027 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) String CONFIGURATION_FILE_NAME =this assignment operator makes the left side equal to the right side "gameconfig.txt";
028
029 /** the defaultdefault is what is executed when no cases are matched number of columns forfor is a looping structure for repeatedly executing a block of code output */
030 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer DEFAULT_SCREEN_WIDTH =this assignment operator makes the left side equal to the right side 72;
031
032 /** the UUID of the player in the critter file */
033 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) String PLAYER_UUID =this assignment operator makes the left side equal to the right side "player";
034
035 /** Reference to the game; forfor is a looping structure for repeatedly executing a block of code getCurrentGame() */
036 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) Game theGame;
037
038 /** command alias dictionary */
039 privateprivate is used to restrict access to the current class only Dictionary aliases;
040
041 /** name of dictionary file */
042 privateprivate is used to restrict access to the current class only String aliasesFName;
043
044 /** all of the critters in the universe */
045 privateprivate is used to restrict access to the current class only ArrayList<Critter> cast;
046
047 /** the name of the cast file */
048 privateprivate is used to restrict access to the current class only String castFName;
049
050 /** game over flag */
051 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false gameOver;
052
053 /** the map of the universe */
054 privateprivate is used to restrict access to the current class only ArrayList<Location> map;
055
056 /** map file name */
057 privateprivate is used to restrict access to the current class only String mapFName;
058
059 /** delayed message string */
060 privateprivate is used to restrict access to the current class only String message;
061
062 /** the player's critter */
063 privateprivate is used to restrict access to the current class only Critter player;
064
065 /** all of the items in the universe */
066 privateprivate is used to restrict access to the current class only ArrayList<Item> props;
067
068 /** props file name */
069 privateprivate is used to restrict access to the current class only String propsFName;
070
071 /** ready flag; set falsefalse is a value for the boolean type and means not true ifif executes the next statement only if the condition in parenthesis evaluates to true configuration problems occur */
072 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false ready;
073
074 /** did the user quit the game? They neither win nor lose */
075 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false userQuit;
076
077 /** width of the screen forfor is a looping structure for repeatedly executing a block of code output; a variable so it can be changed */
078 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer screenWidth;
079
080 /** show the description thisthis means the current object (the implicit parameter) time around? */
081 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false showDescription;
082
083 /**
084 * Construct a newnew is used to create objects by calling the constructor game (with just a map). The name of the Location
085 * file and the dictionary are hard coded here. They probably belong
086 * in a configuration file.
087 */
088 publicpublic is used to indicate unrestricted access (any other class can have access) Game() {open braces start code blocks and must be matched with a close brace
089 screenWidth =this assignment operator makes the left side equal to the right side DEFAULT_SCREEN_WIDTH;
090 ready =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
091 message =this assignment operator makes the left side equal to the right side "";
092 ifif executes the next statement only if the condition in parenthesis evaluates to true (processConfigurationFile(CONFIGURATION_FILE_NAME)) {open braces start code blocks and must be matched with a close brace
093 thisthis means the current object (the implicit parameter).aliases =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Dictionary(openFileForInput(aliasesFName));
094 thisthis means the current object (the implicit parameter).map =this assignment operator makes the left side equal to the right side readMapFile(mapFName);
095 thisthis means the current object (the implicit parameter).cast =this assignment operator makes the left side equal to the right side readCastFile(castFName);
096 thisthis means the current object (the implicit parameter).props =this assignment operator makes the left side equal to the right side readPropsFile(propsFName);
097
098 distributeCritters();
099 distributeLoot();
100
101 ifif executes the next statement only if the condition in parenthesis evaluates to true ((map !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (cast !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (props !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)) {open braces start code blocks and must be matched with a close brace
102 player =this assignment operator makes the left side equal to the right side critterByUUID(PLAYER_UUID);
103 cast.remove(player);// we are not a critter in the game
104 thisthis means the current object (the implicit parameter).ready =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
105 }close braces end code blocks and must match an earlier open brace
106 }close braces end code blocks and must match an earlier open brace
107 }close braces end code blocks and must match an earlier open brace
108
109 /**
110 * Get a staticstatic means that an instance is not required for access (class level access) reference to the current game. Since there is only one
111 * {open braces start code blocks and must be matched with a close brace@link Game}close braces end code blocks and must match an earlier open brace the {open braces start code blocks and must be matched with a close brace@link GameObject}close braces end code blocks and must match an earlier open braces in it can find it through thisthis means the current object (the implicit parameter)
112 * method just like in FANG. They need it forfor is a looping structure for repeatedly executing a block of code calling message.
113 *
114 * @returnnull the current game.
115 */
116 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) Game getCurrentGame() {open braces start code blocks and must be matched with a close brace
117 returnreturn means to provide the result of the method and/or cease execution of the method immediately theGame;
118 }close braces end code blocks and must match an earlier open brace
119
120 /**
121 * Main program forfor is a looping structure for repeatedly executing a block of code the game . Create a game object; ifif executes the next statement only if the condition in parenthesis evaluates to true all goes well,
122 * call play.
123 *
124 * @paramthis is the Javadoc tag for documenting the purpose of parameters args command-line arguments to the program; ignored by
125 * thisthis means the current object (the implicit parameter) program
126 */
127 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args) {open braces start code blocks and must be matched with a close brace
128 theGame =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Game();
129 ifif executes the next statement only if the condition in parenthesis evaluates to true (theGame.isReady()) {open braces start code blocks and must be matched with a close brace
130 theGame.play();
131 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
132 System.err.println("Trouble initalizing game.");
133 }close braces end code blocks and must match an earlier open brace
134 }close braces end code blocks and must match an earlier open brace
135
136 /**
137 * Add a newnew is used to create objects by calling the constructor message to the message lines.
138 *
139 * @paramthis is the Javadoc tag for documenting the purpose of parameters msg
140 */
141 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addMessage(String msg) {open braces start code blocks and must be matched with a close brace
142 ifif executes the next statement only if the condition in parenthesis evaluates to true (message.length() !=this is the not equals operator which evaluates to true if both sides are different 0) {open braces start code blocks and must be matched with a close brace
143 message +=this increases the variable on the left by the value on the right "\n";
144 }close braces end code blocks and must match an earlier open brace
145 message +=this increases the variable on the left by the value on the right msg;
146 showDescription =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
147 }close braces end code blocks and must match an earlier open brace
148
149 /**
150 * Is the game ready (did reading work?)
151 *
152 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true ready; falsefalse is a value for the boolean type and means not true otherwise
153 */
154 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false isReady() {open braces start code blocks and must be matched with a close brace
155 returnreturn means to provide the result of the method and/or cease execution of the method immediately ready;
156 }close braces end code blocks and must match an earlier open brace
157
158 /**
159 * The mainThe main method is the place where applications begin executing. game loop. Play until done.
160 */
161 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value play() {open braces start code blocks and must be matched with a close brace
162 userQuit =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
163 gameOver =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
164 showDescription =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
165 whilewhile is a looping structure for executing code repeatedly (!this is the not operator, which changes true to false and false to truegameOver) {open braces start code blocks and must be matched with a close brace
166 showMessage();
167 ifif executes the next statement only if the condition in parenthesis evaluates to true (showDescription) {open braces start code blocks and must be matched with a close brace
168 // show state
169 showGameState();
170 }close braces end code blocks and must match an earlier open brace
171
172 showDescription =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
173
174 // get user input
175 System.out.print("Game> ");
176 String commandLine =this assignment operator makes the left side equal to the right side Keyboard.nextLine();
177 // update state
178 thisthis means the current object (the implicit parameter).processCommand(commandLine);
179 }close braces end code blocks and must match an earlier open brace
180 // show any pending messages from the last turn
181 showMessage();
182
183 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueuserQuit) {open braces start code blocks and must be matched with a close brace// user quit?
184 ifif executes the next statement only if the condition in parenthesis evaluates to true (player.getHealth() <=this evaluates to true if the left side is not more than the right side 0) {open braces start code blocks and must be matched with a close brace// or lose?
185 System.out.println("You lost the game. Next time avoid dying.");
186 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace// or win?
187 showGameState();// show last location
188 System.out.println("You win!");
189 }close braces end code blocks and must match an earlier open brace
190 }close braces end code blocks and must match an earlier open brace
191 }close braces end code blocks and must match an earlier open brace
192
193 /**
194 * Show the delayed message, ifif executes the next statement only if the condition in parenthesis evaluates to true any, and clear the message
195 */
196 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value showMessage() {open braces start code blocks and must be matched with a close brace
197 ifif executes the next statement only if the condition in parenthesis evaluates to true (message.length() !=this is the not equals operator which evaluates to true if both sides are different 0) {open braces start code blocks and must be matched with a close brace
198 System.out.println(message);
199 message =this assignment operator makes the left side equal to the right side "";
200 }close braces end code blocks and must match an earlier open brace
201 }close braces end code blocks and must match an earlier open brace
202
203 /**
204 * Find a location given its UUID.
205 *
206 * @paramthis is the Javadoc tag for documenting the purpose of parameters uuid the UUID of the location to find in the list of all
207 * Critters.
208 *
209 * @returnnull the matching location or nullnull is the value used to refer to a non-existant object
210 */
211 privateprivate is used to restrict access to the current class only Critter critterByUUID(String uuid) {open braces start code blocks and must be matched with a close brace
212 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different cast.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
213 ifif executes the next statement only if the condition in parenthesis evaluates to true (cast.get(i).getUUID().equalsIgnoreCase(uuid)) {open braces start code blocks and must be matched with a close brace
214 returnreturn means to provide the result of the method and/or cease execution of the method immediately cast.get(i);
215 }close braces end code blocks and must match an earlier open brace
216 }close braces end code blocks and must match an earlier open brace
217 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
218 }close braces end code blocks and must match an earlier open brace
219
220 /**
221 * After loading {open braces start code blocks and must be matched with a close brace@link #cast}close braces end code blocks and must match an earlier open brace and {open braces start code blocks and must be matched with a close brace@link #map}close braces end code blocks and must match an earlier open brace, connect up the
222 * critters with their locations.
223 */
224 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value distributeCritters() {open braces start code blocks and must be matched with a close brace
225 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different cast.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
226 Critter critter =this assignment operator makes the left side equal to the right side cast.get(i);
227 Location location =this assignment operator makes the left side equal to the right side locationByUUID(critter.getLocationID());
228 location.add(critter);
229 }close braces end code blocks and must match an earlier open brace
230 }close braces end code blocks and must match an earlier open brace
231
232 /**
233 * After loading {open braces start code blocks and must be matched with a close brace@link #props}close braces end code blocks and must match an earlier open brace, {open braces start code blocks and must be matched with a close brace@link #cast}close braces end code blocks and must match an earlier open brace, and {open braces start code blocks and must be matched with a close brace@link #map}close braces end code blocks and must match an earlier open brace,
234 * connect up the prop elements with their owners. Owners have the
235 * prop added.
236 */
237 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value distributeLoot() {open braces start code blocks and must be matched with a close brace
238 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different props.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
239 Item item =this assignment operator makes the left side equal to the right side props.get(i);
240 GameObject owner =this assignment operator makes the left side equal to the right side gameObjectByUUID(item.getOwnerID());
241 owner.add(item);
242 }close braces end code blocks and must match an earlier open brace
243 }close braces end code blocks and must match an earlier open brace
244
245 /**
246 * Drop an item. The remainder of the commandLine is available to pull
247 * out the names.
248 *
249 * @paramthis is the Javadoc tag for documenting the purpose of parameters commandLine the remaining line
250 *
251 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true at least one item is dropped
252 */
253 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doDrop(Scanner commandLine) {open braces start code blocks and must be matched with a close brace
254 Location curr =this assignment operator makes the left side equal to the right side locationByUUID(player.getLocationID());
255 booleanboolean is a type that is either true or false foundOne =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
256 String dropped =this assignment operator makes the left side equal to the right side "";
257 String separator =this assignment operator makes the left side equal to the right side "";
258 whilewhile is a looping structure for executing code repeatedly (commandLine.hasNext()) {open braces start code blocks and must be matched with a close brace
259 Item theItem =this assignment operator makes the left side equal to the right side itemByCommandLine(player, commandLine);
260 ifif executes the next statement only if the condition in parenthesis evaluates to true (theItem !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
261 give(player, curr, theItem);
262 dropped +=this increases the variable on the left by the value on the right separator +adds two numbers together or concatenates Strings together theItem.getName();
263 foundOne =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
264 }close braces end code blocks and must match an earlier open brace
265 }close braces end code blocks and must match an earlier open brace
266 ifif executes the next statement only if the condition in parenthesis evaluates to true (foundOne) {open braces start code blocks and must be matched with a close brace
267 addMessage("You dropped " +adds two numbers together or concatenates Strings together dropped +adds two numbers together or concatenates Strings together "");
268 }close braces end code blocks and must match an earlier open brace
269 returnreturn means to provide the result of the method and/or cease execution of the method immediately foundOne;
270 }close braces end code blocks and must match an earlier open brace
271
272 /**
273 * Move player East ifif executes the next statement only if the condition in parenthesis evaluates to true possible.
274 *
275 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true player moved; falsefalse is a value for the boolean type and means not true otherwise
276 */
277 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doEast() {open braces start code blocks and must be matched with a close brace
278 Location here =this assignment operator makes the left side equal to the right side player.getLocation();
279 booleanboolean is a type that is either true or false canMove =this assignment operator makes the left side equal to the right side (here.getEast() !=this is the not equals operator which evaluates to true if both sides are different Location.NO_SUCH_LOCATION) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
280 unlocked(here.getEKey(), player, here);
281 ifif executes the next statement only if the condition in parenthesis evaluates to true (canMove) {open braces start code blocks and must be matched with a close brace
282 moveTo(locationByUUID(here.getEast()));
283 }close braces end code blocks and must match an earlier open brace
284 returnreturn means to provide the result of the method and/or cease execution of the method immediately canMove;
285 }close braces end code blocks and must match an earlier open brace
286
287 /**
288 * Give an item from the player to some other critter. The command can
289 * have one of two forms:
290 *
291 * <p>give <critter> <item>
292 *
293 * <p>give <item> <critter>
294 *
295 * <p>(the word "give" has already been processed so thisthis means the current object (the implicit parameter) method is
296 * called). Must take words off commandLine, building up a name. Check
297 * that name against both the list of critters in the current location
298 * (who we could give to) and the player's inventory (what we could be
299 * giving)
300 *
301 * <p>Assuming a match is found, the rest of the line has to be the
302 * other name. Try to find it.
303 *
304 * <p>Both a critter and an item are found, then give(player, critter,
305 * item).
306 *
307 * <p>The tradesFor list in the critter is also checked to see ifif executes the next statement only if the condition in parenthesis evaluates to true an
308 * exchange takes place. If so, give(critter, player, tradeItem).
309 *
310 * @paramthis is the Javadoc tag for documenting the purpose of parameters commandLine the two names
311 *
312 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true something is given, falsefalse is a value for the boolean type and means not true otherwise
313 */
314 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doGive(Scanner commandLine) {open braces start code blocks and must be matched with a close brace
315 String firstName =this assignment operator makes the left side equal to the right side commandLine.next();
316 Location curr =this assignment operator makes the left side equal to the right side locationByUUID(player.getLocationID());
317 Item theItem =this assignment operator makes the left side equal to the right side player.itemByName(firstName);
318 Critter theCritter =this assignment operator makes the left side equal to the right side curr.critterByName(firstName);
319
320 whilewhile is a looping structure for executing code repeatedly (commandLine.hasNext() &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (theItem ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
321 (theCritter ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object)) {open braces start code blocks and must be matched with a close brace
322 firstName +=this increases the variable on the left by the value on the right " " +adds two numbers together or concatenates Strings together commandLine.next();
323 theItem =this assignment operator makes the left side equal to the right side player.itemByName(firstName);
324 theCritter =this assignment operator makes the left side equal to the right side curr.critterByName(firstName);
325 }close braces end code blocks and must match an earlier open brace
326
327 ifif executes the next statement only if the condition in parenthesis evaluates to true (theItem !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
328 String critterName =this assignment operator makes the left side equal to the right side restOfLine(commandLine);
329 theCritter =this assignment operator makes the left side equal to the right side curr.critterByName(critterName);
330 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (theCritter !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
331 String itemName =this assignment operator makes the left side equal to the right side restOfLine(commandLine);
332 theItem =this assignment operator makes the left side equal to the right side player.itemByName(itemName);
333 }close braces end code blocks and must match an earlier open brace
334
335 ifif executes the next statement only if the condition in parenthesis evaluates to true ((theCritter !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (theItem !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)) {open braces start code blocks and must be matched with a close brace
336 String trade =this assignment operator makes the left side equal to the right side theCritter.willTradeFor(theItem.getUUID());
337 addMessage("You give the " +adds two numbers together or concatenates Strings together theItem.getName() +adds two numbers together or concatenates Strings together " to the " +adds two numbers together or concatenates Strings together
338 theCritter.getName());
339 give(player, theCritter, theItem);
340 ifif executes the next statement only if the condition in parenthesis evaluates to true (trade !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
341 Item tradeItem =this assignment operator makes the left side equal to the right side theCritter.itemByUUID(trade);
342 ifif executes the next statement only if the condition in parenthesis evaluates to true (tradeItem !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
343 give(theCritter, player, tradeItem);
344 addMessage("The " +adds two numbers together or concatenates Strings together theCritter.getName() +adds two numbers together or concatenates Strings together " gives you a " +adds two numbers together or concatenates Strings together
345 tradeItem.getName());
346 }close braces end code blocks and must match an earlier open brace
347 }close braces end code blocks and must match an earlier open brace
348
349 ifif executes the next statement only if the condition in parenthesis evaluates to true (theCritter.getHealth() <=this evaluates to true if the left side is not more than the right side 0) {open braces start code blocks and must be matched with a close brace
350 addMessage(theCritter.getName() +adds two numbers together or concatenates Strings together " has left.");
351 curr.removeCritterUUID(theCritter.getUUID());
352 }close braces end code blocks and must match an earlier open brace
353
354 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
355 }close braces end code blocks and must match an earlier open brace
356
357 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
358 }close braces end code blocks and must match an earlier open brace
359
360 /**
361 * Move player North ifif executes the next statement only if the condition in parenthesis evaluates to true possible.
362 *
363 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true player moved; falsefalse is a value for the boolean type and means not true otherwise
364 */
365 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doNorth() {open braces start code blocks and must be matched with a close brace
366 Location here =this assignment operator makes the left side equal to the right side player.getLocation();
367 booleanboolean is a type that is either true or false canMove =this assignment operator makes the left side equal to the right side (here.getNorth() !=this is the not equals operator which evaluates to true if both sides are different Location.NO_SUCH_LOCATION) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
368 unlocked(here.getNKey(), player, here);
369 ifif executes the next statement only if the condition in parenthesis evaluates to true (canMove) {open braces start code blocks and must be matched with a close brace
370 moveTo(locationByUUID(here.getNorth()));
371 }close braces end code blocks and must match an earlier open brace
372 returnreturn means to provide the result of the method and/or cease execution of the method immediately canMove;
373 }close braces end code blocks and must match an earlier open brace
374
375 /**
376 * Pickup the item(s) listed in the commandLine
377 *
378 * @paramthis is the Javadoc tag for documenting the purpose of parameters commandLine scanner of rest of the line
379 *
380 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true at least one item is picked up
381 */
382 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doPickup(Scanner commandLine) {open braces start code blocks and must be matched with a close brace
383 Location curr =this assignment operator makes the left side equal to the right side locationByUUID(player.getLocationID());
384 booleanboolean is a type that is either true or false gotOne =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
385 String pickedup =this assignment operator makes the left side equal to the right side "";
386 String separator =this assignment operator makes the left side equal to the right side "";
387 whilewhile is a looping structure for executing code repeatedly (commandLine.hasNext()) {open braces start code blocks and must be matched with a close brace
388 Item theItem =this assignment operator makes the left side equal to the right side itemByCommandLine(curr, commandLine);
389 ifif executes the next statement only if the condition in parenthesis evaluates to true (theItem !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
390 give(curr, player, theItem);
391 pickedup +=this increases the variable on the left by the value on the right separator +adds two numbers together or concatenates Strings together theItem.getName();
392 gotOne =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
393 }close braces end code blocks and must match an earlier open brace
394 }close braces end code blocks and must match an earlier open brace
395 ifif executes the next statement only if the condition in parenthesis evaluates to true (gotOne) {open braces start code blocks and must be matched with a close brace
396 addMessage("You picked up " +adds two numbers together or concatenates Strings together pickedup +adds two numbers together or concatenates Strings together ".");
397 }close braces end code blocks and must match an earlier open brace
398 returnreturn means to provide the result of the method and/or cease execution of the method immediately gotOne;
399 }close braces end code blocks and must match an earlier open brace
400
401 /**
402 * Move player South ifif executes the next statement only if the condition in parenthesis evaluates to true possible.
403 *
404 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true player moved; falsefalse is a value for the boolean type and means not true otherwise
405 */
406 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doSouth() {open braces start code blocks and must be matched with a close brace
407 Location here =this assignment operator makes the left side equal to the right side player.getLocation();
408 booleanboolean is a type that is either true or false canMove =this assignment operator makes the left side equal to the right side (here.getSouth() !=this is the not equals operator which evaluates to true if both sides are different Location.NO_SUCH_LOCATION) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
409 unlocked(here.getSKey(), player, here);
410 ifif executes the next statement only if the condition in parenthesis evaluates to true (canMove) {open braces start code blocks and must be matched with a close brace
411 moveTo(locationByUUID(here.getSouth()));
412 }close braces end code blocks and must match an earlier open brace
413 returnreturn means to provide the result of the method and/or cease execution of the method immediately canMove;
414 }close braces end code blocks and must match an earlier open brace
415
416 /**
417 * Move player West ifif executes the next statement only if the condition in parenthesis evaluates to true possible.
418 *
419 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true player moved; falsefalse is a value for the boolean type and means not true otherwise
420 */
421 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false doWest() {open braces start code blocks and must be matched with a close brace
422 Location here =this assignment operator makes the left side equal to the right side player.getLocation();
423 booleanboolean is a type that is either true or false canMove =this assignment operator makes the left side equal to the right side (here.getWest() !=this is the not equals operator which evaluates to true if both sides are different Location.NO_SUCH_LOCATION) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
424 unlocked(here.getWKey(), player, here);
425 ifif executes the next statement only if the condition in parenthesis evaluates to true (canMove) {open braces start code blocks and must be matched with a close brace
426 moveTo(locationByUUID(here.getWest()));
427 }close braces end code blocks and must match an earlier open brace
428 returnreturn means to provide the result of the method and/or cease execution of the method immediately canMove;
429 }close braces end code blocks and must match an earlier open brace
430
431 /**
432 * Given the uuid, find the object matching.
433 *
434 * @paramthis is the Javadoc tag for documenting the purpose of parameters uuid the uuid to find
435 *
436 * @returnnull nullnull is the value used to refer to a non-existant object ifif executes the next statement only if the condition in parenthesis evaluates to true no object is found to match, matching {open braces start code blocks and must be matched with a close brace@link
437 * GameObject}close braces end code blocks and must match an earlier open brace otherwise.
438 */
439 privateprivate is used to restrict access to the current class only GameObject gameObjectByUUID(String uuid) {open braces start code blocks and must be matched with a close brace
440 ifif executes the next statement only if the condition in parenthesis evaluates to true (locationByUUID(uuid) !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
441 returnreturn means to provide the result of the method and/or cease execution of the method immediately locationByUUID(uuid);
442 }close braces end code blocks and must match an earlier open brace
443 ifif executes the next statement only if the condition in parenthesis evaluates to true (critterByUUID(uuid) !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
444 returnreturn means to provide the result of the method and/or cease execution of the method immediately critterByUUID(uuid);
445 }close braces end code blocks and must match an earlier open brace
446 ifif executes the next statement only if the condition in parenthesis evaluates to true (itemByUUID(uuid) !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
447 returnreturn means to provide the result of the method and/or cease execution of the method immediately itemByUUID(uuid);
448 }close braces end code blocks and must match an earlier open brace
449 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
450 }close braces end code blocks and must match an earlier open brace
451
452 /**
453 * Actually transfer the item from giver to getter.
454 *
455 * @paramthis is the Javadoc tag for documenting the purpose of parameters giver the GameObject that has item
456 * @paramthis is the Javadoc tag for documenting the purpose of parameters getter the GameObject to end up with item
457 * @paramthis is the Javadoc tag for documenting the purpose of parameters item the item to transfer
458 */
459 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value give(GameObject giver, GameObject getter, Item item) {open braces start code blocks and must be matched with a close brace
460 giver.removeItemUUID(item.getUUID());
461 getter.add(item);
462 }close braces end code blocks and must match an earlier open brace
463
464 /**
465 * Try to match the next set of words in the commandLine with the name
466 * of an item in owner's inventory
467 *
468 * @paramthis is the Javadoc tag for documenting the purpose of parameters owner the owner who must own the element we seek
469 * @paramthis is the Javadoc tag for documenting the purpose of parameters lineProcessor the commandLine (we pull words off of it)
470 *
471 * @returnnull the first matching item (matching some prefix of the words
472 * in commandLine) ifif executes the next statement only if the condition in parenthesis evaluates to true there is one; nullnull is the value used to refer to a non-existant object ifif executes the next statement only if the condition in parenthesis evaluates to true no match is found
473 */
474 privateprivate is used to restrict access to the current class only Item itemByCommandLine(GameObject owner,
475 Scanner lineProcessor) {open braces start code blocks and must be matched with a close brace
476 String name =this assignment operator makes the left side equal to the right side "";
477 String separator =this assignment operator makes the left side equal to the right side "";
478 whilewhile is a looping structure for executing code repeatedly (lineProcessor.hasNext()) {open braces start code blocks and must be matched with a close brace
479 name +=this increases the variable on the left by the value on the right separator +adds two numbers together or concatenates Strings together lineProcessor.next();
480 separator =this assignment operator makes the left side equal to the right side " ";
481 Item theItem =this assignment operator makes the left side equal to the right side owner.itemByName(name);
482 ifif executes the next statement only if the condition in parenthesis evaluates to true (theItem !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
483 returnreturn means to provide the result of the method and/or cease execution of the method immediately theItem;
484 }close braces end code blocks and must match an earlier open brace
485 }close braces end code blocks and must match an earlier open brace
486 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
487 }close braces end code blocks and must match an earlier open brace
488
489 /**
490 * Find a location given its UUID.
491 *
492 * @paramthis is the Javadoc tag for documenting the purpose of parameters uuid the UUID of the location to find in the list of all
493 * Items.
494 *
495 * @returnnull the matching location or nullnull is the value used to refer to a non-existant object
496 */
497 privateprivate is used to restrict access to the current class only Item itemByUUID(String uuid) {open braces start code blocks and must be matched with a close brace
498 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different props.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
499 ifif executes the next statement only if the condition in parenthesis evaluates to true (props.get(i).getUUID().equalsIgnoreCase(uuid)) {open braces start code blocks and must be matched with a close brace
500 returnreturn means to provide the result of the method and/or cease execution of the method immediately props.get(i);
501 }close braces end code blocks and must match an earlier open brace
502 }close braces end code blocks and must match an earlier open brace
503 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
504 }close braces end code blocks and must match an earlier open brace
505
506 /**
507 * Find a location given its UUID.
508 *
509 * @paramthis is the Javadoc tag for documenting the purpose of parameters uuid the UUID of the location to find in the list of all
510 * Locations.
511 *
512 * @returnnull the matching location or nullnull is the value used to refer to a non-existant object
513 */
514 privateprivate is used to restrict access to the current class only Location locationByUUID(String uuid) {open braces start code blocks and must be matched with a close brace
515 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different map.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
516 ifif executes the next statement only if the condition in parenthesis evaluates to true (map.get(i).getUUID().equalsIgnoreCase(uuid)) {open braces start code blocks and must be matched with a close brace
517 returnreturn means to provide the result of the method and/or cease execution of the method immediately map.get(i);
518 }close braces end code blocks and must match an earlier open brace
519 }close braces end code blocks and must match an earlier open brace
520 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
521 }close braces end code blocks and must match an earlier open brace
522
523 /**
524 * Handle looking. See ifif executes the next statement only if the condition in parenthesis evaluates to true the name matches an item in the player's
525 * inventory, an item in the location, or a critter in the location.
526 * Return truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true a match was found and described.
527 *
528 * @paramthis is the Javadoc tag for documenting the purpose of parameters name the name of the thing to look at.
529 *
530 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true a description was printed; falsefalse is a value for the boolean type and means not true otherwise
531 */
532 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false look(String name) {open braces start code blocks and must be matched with a close brace
533 ifif executes the next statement only if the condition in parenthesis evaluates to true (name.length() ==this is the comparison operator which evaluates to true if both sides are the same 0) {open braces start code blocks and must be matched with a close brace
534 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
535 }close braces end code blocks and must match an earlier open brace
536 Item ours =this assignment operator makes the left side equal to the right side player.itemByName(name);
537 ifif executes the next statement only if the condition in parenthesis evaluates to true (ours !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
538 showStringWrapped(ours.getFullDescription());
539 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
540 }close braces end code blocks and must match an earlier open brace
541 Location curr =this assignment operator makes the left side equal to the right side locationByUUID(player.getLocationID());
542 Item theirs =this assignment operator makes the left side equal to the right side curr.itemByName(name);
543 ifif executes the next statement only if the condition in parenthesis evaluates to true (theirs !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
544 showStringWrapped(theirs.getFullDescription());
545 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
546 }close braces end code blocks and must match an earlier open brace
547 Critter them =this assignment operator makes the left side equal to the right side curr.critterByName(name);
548 ifif executes the next statement only if the condition in parenthesis evaluates to true (them !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
549 showStringWrapped(them.getFullDescription());
550 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
551 }close braces end code blocks and must match an earlier open brace
552 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
553 }close braces end code blocks and must match an earlier open brace
554
555 /**
556 * Actually move the player to the given location. This is were the
557 * player and location are updated (and winning is checked).
558 *
559 * @paramthis is the Javadoc tag for documenting the purpose of parameters toWhere the Location to which the player should move.
560 */
561 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveTo(Location toWhere) {open braces start code blocks and must be matched with a close brace
562 player.setLocation(toWhere);
563 toWhere.add(player);
564 gameOver =this assignment operator makes the left side equal to the right side toWhere.isWinningLocation();
565 }close braces end code blocks and must match an earlier open brace
566
567 /**
568 * Open the named file forfor is a looping structure for repeatedly executing a block of code input, removing any comments from the file
569 * as it is read.
570 *
571 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname path name (relative or absolute) to file to open
572 *
573 * @returnnull a {open braces start code blocks and must be matched with a close brace@link Scanner}close braces end code blocks and must match an earlier open brace attached to the given file or nullnull is the value used to refer to a non-existant object ifif executes the next statement only if the condition in parenthesis evaluates to true
574 * there was a problem opening the named file
575 */
576 privateprivate is used to restrict access to the current class only Scanner openFileForInput(String fname) {open braces start code blocks and must be matched with a close brace
577 Scanner opened =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
578 trytry is for executing a code block that may experience exceptions (errors) {open braces start code blocks and must be matched with a close brace
579 opened =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(newnew is used to create objects by calling the constructor SansCommentFilterReader(
580 newnew is used to create objects by calling the constructor FileReader(newnew is used to create objects by calling the constructor File(fname))));
581 }close braces end code blocks and must match an earlier open brace catchcatch means to handle an exception that may occur (FileNotFoundException e) {open braces start code blocks and must be matched with a close brace
582 // do nothing (null will be returned which is what we want)
583 }close braces end code blocks and must match an earlier open brace
584 returnreturn means to provide the result of the method and/or cease execution of the method immediately opened;
585 }close braces end code blocks and must match an earlier open brace
586
587 /**
588 * Given a command, as entered by the user, process it. Translate the
589 * command through the alias dictionary and then look it up. This is
590 * just a dispatch routine; the real work is done in the handler
591 * commands.
592 *
593 * @paramthis is the Javadoc tag for documenting the purpose of parameters commandLine the word entered by the user.
594 */
595 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value processCommand(String commandLine) {open braces start code blocks and must be matched with a close brace
596 ifif executes the next statement only if the condition in parenthesis evaluates to true (commandLine.length() ==this is the comparison operator which evaluates to true if both sides are the same 0) {open braces start code blocks and must be matched with a close brace
597 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
598 }close braces end code blocks and must match an earlier open brace
599 // Scan across the command line as entered by the user
600 Scanner lineProcessor =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(commandLine);
601 String command =this assignment operator makes the left side equal to the right side lineProcessor.next();
602
603 String normalizedCommand =this assignment operator makes the left side equal to the right side aliases.get(command);
604 ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
605 normalizedCommand =this assignment operator makes the left side equal to the right side command;
606 }close braces end code blocks and must match an earlier open brace
607 ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("north")) {open braces start code blocks and must be matched with a close brace
608 doNorth();
609 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("south")) {open braces start code blocks and must be matched with a close brace
610 doSouth();
611 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("east")) {open braces start code blocks and must be matched with a close brace
612 doEast();
613 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("west")) {open braces start code blocks and must be matched with a close brace
614 doWest();
615 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("inventory")) {open braces start code blocks and must be matched with a close brace
616 showInventory("You have ", truetrue is the boolean value that is the opposite of false, player.getInventory());
617 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("look")) {open braces start code blocks and must be matched with a close brace
618 String name =this assignment operator makes the left side equal to the right side restOfLine(lineProcessor);
619 ifif executes the next statement only if the condition in parenthesis evaluates to true (look(name)) {open braces start code blocks and must be matched with a close brace
620 showDescription =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
621 }close braces end code blocks and must match an earlier open brace
622 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("pickup")) {open braces start code blocks and must be matched with a close brace
623 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truedoPickup(lineProcessor)) {open braces start code blocks and must be matched with a close brace
624 addMessage("Unable to find anything to pickup.");
625 }close braces end code blocks and must match an earlier open brace
626 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("drop")) {open braces start code blocks and must be matched with a close brace
627 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truedoDrop(lineProcessor)) {open braces start code blocks and must be matched with a close brace
628 addMessage("Unable to find anything to drop.");
629 }close braces end code blocks and must match an earlier open brace
630 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("give")) {open braces start code blocks and must be matched with a close brace
631 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truedoGive(lineProcessor)) {open braces start code blocks and must be matched with a close brace
632 addMessage("Unable to give that to them.");
633 }close braces end code blocks and must match an earlier open brace
634 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (normalizedCommand.equalsIgnoreCase("exit")) {open braces start code blocks and must be matched with a close brace
635 gameOver =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
636 userQuit =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
637 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
638 unknownCommand(commandLine, normalizedCommand);
639 }close braces end code blocks and must match an earlier open brace
640 ifif executes the next statement only if the condition in parenthesis evaluates to true (player.getHealth() <=this evaluates to true if the left side is not more than the right side 0) {open braces start code blocks and must be matched with a close brace
641 gameOver =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
642 }close braces end code blocks and must match an earlier open brace
643 }close braces end code blocks and must match an earlier open brace
644
645 /**
646 * Process the named configuration file. The file is a collection of
647 * attribute value pairs which should specify the "alias", "cast",
648 * "map", and "props" file names. If all four files are specified,
649 * method returns truetrue is the boolean value that is the opposite of false (with fields set).
650 *
651 * @paramthis is the Javadoc tag for documenting the purpose of parameters configurationFName name of file to process
652 *
653 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true all four file names were set to non-nullnull is the value used to refer to a non-existant object values;
654 * falsefalse is a value for the boolean type and means not true otherwise
655 */
656 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false processConfigurationFile(String configurationFName) {open braces start code blocks and must be matched with a close brace
657 aliasesFName =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
658 castFName =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
659 mapFName =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
660 propsFName =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
661
662 Scanner config =this assignment operator makes the left side equal to the right side openFileForInput(configurationFName);
663 String attribute =this assignment operator makes the left side equal to the right side ReadAndWrite.readAttribute(config);
664 whilewhile is a looping structure for executing code repeatedly (config.hasNext()) {open braces start code blocks and must be matched with a close brace
665 /* ignore */ ReadAndWrite.readMatch(config, "=");
666 String value =this assignment operator makes the left side equal to the right side ReadAndWrite.readValue(config);
667 ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("alias")) {open braces start code blocks and must be matched with a close brace
668 aliasesFName =this assignment operator makes the left side equal to the right side value;
669 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("cast")) {open braces start code blocks and must be matched with a close brace
670 castFName =this assignment operator makes the left side equal to the right side value;
671 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("map")) {open braces start code blocks and must be matched with a close brace
672 mapFName =this assignment operator makes the left side equal to the right side value;
673 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("props")) {open braces start code blocks and must be matched with a close brace
674 propsFName =this assignment operator makes the left side equal to the right side value;
675 }close braces end code blocks and must match an earlier open brace
676 ifif executes the next statement only if the condition in parenthesis evaluates to true (config.hasNext()) {open braces start code blocks and must be matched with a close brace
677 attribute =this assignment operator makes the left side equal to the right side ReadAndWrite.readAttribute(config);
678 }close braces end code blocks and must match an earlier open brace
679 }close braces end code blocks and must match an earlier open brace
680
681 returnreturn means to provide the result of the method and/or cease execution of the method immediately (aliasesFName !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (castFName !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
682 (mapFName !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (propsFName !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object);
683 }close braces end code blocks and must match an earlier open brace
684
685 /**
686 * Read the map file. Open the named file and read it as critters into
687 * the array list returned by the method.
688 *
689 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname name of critter file
690 *
691 * @returnnull ArrayList<Critter> containing all of the read critters.
692 */
693 privateprivate is used to restrict access to the current class only ArrayList<Critter> readCastFile(String fname) {open braces start code blocks and must be matched with a close brace
694 ArrayList<Critter> returnCast =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
695 Scanner castFile =this assignment operator makes the left side equal to the right side openFileForInput(fname);
696 ifif executes the next statement only if the condition in parenthesis evaluates to true (castFile !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
697 returnCast =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<Critter>();
698 whilewhile is a looping structure for executing code repeatedly (castFile.hasNext()) {open braces start code blocks and must be matched with a close brace
699 Critter critter =this assignment operator makes the left side equal to the right side Critter.readObjectFromFile(castFile);
700 ifif executes the next statement only if the condition in parenthesis evaluates to true (critter !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
701 returnCast.add(critter);
702 }close braces end code blocks and must match an earlier open brace
703 }close braces end code blocks and must match an earlier open brace
704 }close braces end code blocks and must match an earlier open brace
705 returnreturn means to provide the result of the method and/or cease execution of the method immediately returnCast;
706 }close braces end code blocks and must match an earlier open brace
707
708 /**
709 * Read the map file. Open the named file and read it as locations
710 * into the array list returned by the method.
711 *
712 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname name of location file
713 *
714 * @returnnull ArrayList<Location> conatining all of the read locations.
715 */
716 privateprivate is used to restrict access to the current class only ArrayList<Location> readMapFile(String fname) {open braces start code blocks and must be matched with a close brace
717 ArrayList<Location> returnMap =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
718 Scanner mapFile =this assignment operator makes the left side equal to the right side openFileForInput(fname);
719 ifif executes the next statement only if the condition in parenthesis evaluates to true (mapFile !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
720 returnMap =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<Location>();
721 whilewhile is a looping structure for executing code repeatedly (mapFile.hasNext()) {open braces start code blocks and must be matched with a close brace
722 Location location =this assignment operator makes the left side equal to the right side Location.readObjectFromFile(mapFile);
723 ifif executes the next statement only if the condition in parenthesis evaluates to true (location !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
724 returnMap.add(location);
725 }close braces end code blocks and must match an earlier open brace
726 }close braces end code blocks and must match an earlier open brace
727 }close braces end code blocks and must match an earlier open brace
728 returnreturn means to provide the result of the method and/or cease execution of the method immediately returnMap;
729 }close braces end code blocks and must match an earlier open brace
730
731 /**
732 * Read the props file. Open the named file and read it as items into
733 * the array list returned by the method.
734 *
735 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname name of item file
736 *
737 * @returnnull ArrayList<Item> containing all of the read items.
738 */
739 privateprivate is used to restrict access to the current class only ArrayList<Item> readPropsFile(String fname) {open braces start code blocks and must be matched with a close brace
740 ArrayList<Item> returnProps =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
741 Scanner propsFile =this assignment operator makes the left side equal to the right side openFileForInput(fname);
742 ifif executes the next statement only if the condition in parenthesis evaluates to true (propsFile !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
743 returnProps =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<Item>();
744 whilewhile is a looping structure for executing code repeatedly (propsFile.hasNext()) {open braces start code blocks and must be matched with a close brace
745 Item item =this assignment operator makes the left side equal to the right side Item.readObjectFromFile(propsFile);
746 ifif executes the next statement only if the condition in parenthesis evaluates to true (item !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
747 returnProps.add(item);
748 }close braces end code blocks and must match an earlier open brace
749 }close braces end code blocks and must match an earlier open brace
750 }close braces end code blocks and must match an earlier open brace
751 returnreturn means to provide the result of the method and/or cease execution of the method immediately returnProps;
752 }close braces end code blocks and must match an earlier open brace
753
754 /**
755 * Get the rest of the line from the scanner (assumed to be on a
756 * single line): trim and compress spaces.
757 *
758 * @paramthis is the Javadoc tag for documenting the purpose of parameters lineProcessor the scanner to clean out
759 *
760 * @returnnull the rest of the line.
761 */
762 privateprivate is used to restrict access to the current class only String restOfLine(Scanner lineProcessor) {open braces start code blocks and must be matched with a close brace
763 returnreturn means to provide the result of the method and/or cease execution of the method immediately lineProcessor.nextLine().trim().replaceAll("\\s+", " ");
764 }close braces end code blocks and must match an earlier open brace
765
766 /**
767 * Display the current state in a game-centric way. Show the
768 * description of the current place and list the stuff and critters in
769 * it.
770 */
771 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value showGameState() {open braces start code blocks and must be matched with a close brace
772 // Get the current location.
773 Location curr =this assignment operator makes the left side equal to the right side locationByUUID(player.getLocationID());
774 showStringWrapped(curr.getFullDescription());
775
776 ArrayList<Item> inventory =this assignment operator makes the left side equal to the right side curr.getInventory();
777 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueinventory.isEmpty()) {open braces start code blocks and must be matched with a close brace// only if there is stuff
778 showInventory("You see ", inventory);
779 }close braces end code blocks and must match an earlier open brace
780
781 // list all the visitors
782 ArrayList<Critter> critters =this assignment operator makes the left side equal to the right side curr.getVisitors();
783 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer c =this assignment operator makes the left side equal to the right side 0; c !=this is the not equals operator which evaluates to true if both sides are different critters.size(); ++this is the increment operator, which increases the variable by 1c) {open braces start code blocks and must be matched with a close brace
784 // EXACT REFERENCE MATCH is just what we want here (!= rather
785 // than !equals)
786 ifif executes the next statement only if the condition in parenthesis evaluates to true (critters.get(c) !=this is the not equals operator which evaluates to true if both sides are different player) {open braces start code blocks and must be matched with a close brace// don't list self
787 System.out.println("You see a " +adds two numbers together or concatenates Strings together critters.get(c).getName());
788 }close braces end code blocks and must match an earlier open brace
789 }close braces end code blocks and must match an earlier open brace
790 }close braces end code blocks and must match an earlier open brace
791
792 /**
793 * Print the prefix followed by the list of all of the items.
794 *
795 * @paramthis is the Javadoc tag for documenting the purpose of parameters prefix The string to go before the list, "You see",
796 * "You have", etc.
797 * @paramthis is the Javadoc tag for documenting the purpose of parameters inventory The inventory list
798 */
799 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value showInventory(String prefix, ArrayList<Item> inventory) {open braces start code blocks and must be matched with a close brace
800 showInventory(prefix, falsefalse is a value for the boolean type and means not true, inventory);
801 }close braces end code blocks and must match an earlier open brace
802
803 /**
804 * Print the prefix followed by the list of all of the items. Only
805 * items with no "owned description" are shown unless showAll is truetrue is the boolean value that is the opposite of false.
806 * The reason: items with owned descriptions change the description of
807 * their owner.
808 *
809 * @paramthis is the Javadoc tag for documenting the purpose of parameters prefix The string to go before the list, "You see",
810 * "You have", etc.
811 * @paramthis is the Javadoc tag for documenting the purpose of parameters showAll force owned description items to show up, too
812 * @paramthis is the Javadoc tag for documenting the purpose of parameters inventory The inventory list
813 */
814 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value showInventory(String prefix, booleanboolean is a type that is either true or false showAll,
815 ArrayList<Item> inventory) {open braces start code blocks and must be matched with a close brace
816 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueinventory.isEmpty()) {open braces start code blocks and must be matched with a close brace
817 booleanboolean is a type that is either true or false somethingToShow =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
818 String inventoryString =this assignment operator makes the left side equal to the right side prefix;
819 String separator =this assignment operator makes the left side equal to the right side "";
820
821 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different inventory.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
822 Item item =this assignment operator makes the left side equal to the right side inventory.get(i);
823 ifif executes the next statement only if the condition in parenthesis evaluates to true (showAll ||this is boolean or, meaning if either or both are true then the result is true (item.getOwnedDescription() ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object)) {open braces start code blocks and must be matched with a close brace
824 inventoryString +=this increases the variable on the left by the value on the right separator +adds two numbers together or concatenates Strings together inventory.get(i).getName();
825 separator =this assignment operator makes the left side equal to the right side ", ";
826 somethingToShow =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
827 }close braces end code blocks and must match an earlier open brace
828 }close braces end code blocks and must match an earlier open brace
829
830 inventoryString +=this increases the variable on the left by the value on the right ".";
831 ifif executes the next statement only if the condition in parenthesis evaluates to true (somethingToShow) {open braces start code blocks and must be matched with a close brace
832 showStringWrapped(inventoryString);
833 }close braces end code blocks and must match an earlier open brace
834 }close braces end code blocks and must match an earlier open brace
835 }close braces end code blocks and must match an earlier open brace
836
837 /**
838 * Wrap the given string so that it doesn't go past the edge of the
839 * screen. Uses {open braces start code blocks and must be matched with a close brace@link util.ReadAndWrite#wrap(String, intint is the type for whole numbers and it is short for integer)}close braces end code blocks and must match an earlier open brace to dodo is part of the do-while looping structure (post condition loop) the
840 * wrapping; then processes the list here.
841 *
842 * @paramthis is the Javadoc tag for documenting the purpose of parameters displayString the string to show
843 */
844 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value showStringWrapped(String displayString) {open braces start code blocks and must be matched with a close brace
845 ArrayList<String> wrappedDisplay =this assignment operator makes the left side equal to the right side ReadAndWrite.wrap(displayString,
846 screenWidth);
847 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different wrappedDisplay.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
848 System.out.println(wrappedDisplay.get(i));
849 }close braces end code blocks and must match an earlier open brace
850 }close braces end code blocks and must match an earlier open brace
851
852 /**
853 * Tell the user that their command was not understood. The parameters
854 * are the pre and post translation versions of the command. That way,
855 * ifif executes the next statement only if the condition in parenthesis evaluates to true one wants, one can show the internal command alias that was
856 * found.
857 *
858 * @paramthis is the Javadoc tag for documenting the purpose of parameters playerProvided just what the player typed
859 * @paramthis is the Javadoc tag for documenting the purpose of parameters translated the internal alias
860 */
861 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value unknownCommand(String playerProvided,
862 String translated) {open braces start code blocks and must be matched with a close brace
863 System.out.println("Unable to understand comamnd " +adds two numbers together or concatenates Strings together
864 playerProvided);
865 }close braces end code blocks and must match an earlier open brace
866
867 /**
868 * Is the direction unlocked? That is, ifif executes the next statement only if the condition in parenthesis evaluates to true key is required forfor is a looping structure for repeatedly executing a block of code critter
869 * to move from here, check ifif executes the next statement only if the condition in parenthesis evaluates to true it is okay.
870 *
871 * <p>If key is nullnull is the value used to refer to a non-existant object, all is well (no key needed)
872 *
873 * <p>If key is a UUID, unlocked ifif executes the next statement only if the condition in parenthesis evaluates to true critter has key as an item or the
874 * location has the key as a critter.
875 *
876 * <p>If key begins '!this is the not operator, which changes true to false and false to true' then it is a NOT key (can't have the item or
877 * critter).
878 *
879 * @paramthis is the Javadoc tag for documenting the purpose of parameters key the uuid to unlock
880 * @paramthis is the Javadoc tag for documenting the purpose of parameters wantsToMove the critter who wants to move
881 * @paramthis is the Javadoc tag for documenting the purpose of parameters here the location to move from
882 *
883 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true the way is clear; falsefalse is a value for the boolean type and means not true otherwise
884 */
885 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false unlocked(String key, Critter wantsToMove, Location here) {open braces start code blocks and must be matched with a close brace
886 booleanboolean is a type that is either true or false passable =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
887 ifif executes the next statement only if the condition in parenthesis evaluates to true (key !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
888 ifif executes the next statement only if the condition in parenthesis evaluates to true (key.charAt(0) ==this is the comparison operator which evaluates to true if both sides are the same '!this is the not operator, which changes true to false and false to true') {open braces start code blocks and must be matched with a close brace// It is a "not" key
889 key =this assignment operator makes the left side equal to the right side key.substring(1);// get rid of !
890 passable =this assignment operator makes the left side equal to the right side (!this is the not operator, which changes true to false and false to truewantsToMove.hasItemUUID(key) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
891 (!this is the not operator, which changes true to false and false to truehere.hasCritterUUID(key)));
892 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
893 passable =this assignment operator makes the left side equal to the right side (wantsToMove.hasItemUUID(key) ||this is boolean or, meaning if either or both are true then the result is true
894 (here.hasCritterUUID(key)));
895 }close braces end code blocks and must match an earlier open brace
896 }close braces end code blocks and must match an earlier open brace
897 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truepassable) {open braces start code blocks and must be matched with a close brace
898 addMessage("Your way appears to be blocked.");
899 }close braces end code blocks and must match an earlier open brace
900 returnreturn means to provide the result of the method and/or cease execution of the method immediately passable;
901 }close braces end code blocks and must match an earlier open brace
902 }close braces end code blocks and must match an earlier open brace
903
904 //Uploaded on Mon Mar 29 21:40:59 EDT 2010
|