|
001 //package jayson_deal;
002
003 packagepackage is used to name the directory or folder a class is in Jayson.deal;
004
005 importimport means to make the classes and/or packages available in this program wiki.Wiki;
006 importimport means to make the classes and/or packages available in this program fang.*;
007 importimport means to make the classes and/or packages available in this program java.awt.*;
008 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
009
010 /**
011 * Author: Jayson Park
012 * Let's Make a Deal game with a reset button.
013 */
014 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 Deal extendsextends means to customize or extend the functionality of a class GameLoop
015 {open braces start code blocks and must be matched with a close brace
016 /**Image Sprites forfor is a looping structure for repeatedly executing a block of code the three doors.*/
017 privateprivate is used to restrict access to the current class only ImageSprite door1, door2, door3;
018 /**Image forfor is a looping structure for repeatedly executing a block of code the explosion when a door is opened.*/
019 privateprivate is used to restrict access to the current class only ImageSprite explosion;
020 /**Image forfor is a looping structure for repeatedly executing a block of code the first lose prize.*/
021 privateprivate is used to restrict access to the current class only ImageSprite lose;
022 /**Image forfor is a looping structure for repeatedly executing a block of code the second lose prize.*/
023 privateprivate is used to restrict access to the current class only ImageSprite lose1;
024 /**Image forfor is a looping structure for repeatedly executing a block of code the first win prize.*/
025 privateprivate is used to restrict access to the current class only ImageSprite win;
026 /**Sprite forfor is a looping structure for repeatedly executing a block of code dot that appears when a door is chosen.*/
027 privateprivate is used to restrict access to the current class only Sprite chosendot;
028 /**Text forfor is a looping structure for repeatedly executing a block of code the reset message.*/
029 privateprivate is used to restrict access to the current class only StringSprite reset;
030 /**Text forfor is a looping structure for repeatedly executing a block of code the different stages of the game.*/
031 privateprivate is used to restrict access to the current class only StringSprite doormsg;
032 /**Sound forfor is a looping structure for repeatedly executing a block of code when a door is opened.*/
033 privateprivate is used to restrict access to the current class only Sound explode;
034 /**Integer forfor is a looping structure for repeatedly executing a block of code the randomization of which door is opened on click.*/
035 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer doorint;
036 /**Integer to hold the door number chosen.*/
037 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer doorchose =this assignment operator makes the left side equal to the right side 0;
038 /**Door that is sent forfor is a looping structure for repeatedly executing a block of code the finalfinal means not changeable (often used for constants) win or lose stage.*/
039 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer lastdoor =this assignment operator makes the left side equal to the right side 0;
040 /**Integer to hold the door that was opened.*/
041 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer dooropen =this assignment operator makes the left side equal to the right side 0;
042 /**Integer forfor is a looping structure for repeatedly executing a block of code the stages of the game.*/
043 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer firstclick =this assignment operator makes the left side equal to the right side 0;
044 /**Integer to hold the door not opened/chosen.*/
045 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer doornot =this assignment operator makes the left side equal to the right side 0;
046
047 //Declaring main method just so my IDE can work.
048 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)
049 {open braces start code blocks and must be matched with a close brace
050 //Constructor
051 Deal deal =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Deal();
052 //Special method to fix some errors.
053 deal.runAsApplication();
054 }close braces end code blocks and must match an earlier open brace
055
056 /**Sets up the game*/
057 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
058 {open braces start code blocks and must be matched with a close brace
059 makeSprites();
060 addSprites();
061 }close braces end code blocks and must match an earlier open brace
062
063 /**Makes the sprites*/
064 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
065 {open braces start code blocks and must be matched with a close brace
066 //Chosen dot to mark door.
067 chosendot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
068 chosendot.setScale(.1);
069 chosendot.setColor(Color.GREEN);
070
071 //Reset Instructions
072 reset =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Press R to reset.");
073 reset.setScale(.8);
074 reset.setLocation(.5, .8);
075
076 //Lose and Win Images/scales
077 lose =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Loser0000.JPG"));
078 lose.setScale(.25);
079 lose1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Loser0000.JPG"));
080 lose1.setScale(.25);
081 win =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Loser0000.JPG"));
082 win.setScale(.25);
083
084 //Sound File;
085 explode =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Explosion3.wav"));
086
087 //Image for the explosion effect.
088 explosion =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Loser0000.JPG"));
089 explosion.setScale(.25);
090
091 //Image and location of the first door.
092 door1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Doora.gif"));
093 door1.setLocation(.20, 0.5);
094 door1.setScale(.25);
095
096 //Image and location of the second door.
097 door2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Doora.gif"));
098 door2.setLocation(.5, 0.5);
099 door2.setScale(.25);
100
101 //Image and location of the third door.
102 door3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(("Doora.gif"));
103 door3.setLocation(.80, 0.5);
104 door3.setScale(.25);
105 }close braces end code blocks and must match an earlier open brace
106
107 /**Adds the sprites to the screen*/
108 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
109 {open braces start code blocks and must be matched with a close brace
110 canvas.addSprite(door1);
111 canvas.addSprite(door2);
112 canvas.addSprite(door3);
113 canvas.addSprite(reset);
114 }close braces end code blocks and must match an earlier open brace
115
116 /**Runs the gif once and sets Alarm to remove the sprite after 1 second.*/
117 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value explosion()
118 {open braces start code blocks and must be matched with a close brace
119 explosion.setLooping(falsefalse is a value for the boolean type and means not true);
120 explosion.startAnimationNow();
121 canvas.addSprite(explosion);
122 scheduleRelative(newnew is used to create objects by calling the constructor Boom(explosion), 1);
123 }close braces end code blocks and must match an earlier open brace
124
125 /**Sets an alarm to add the lose graphic to the canvas in half a second.*/
126 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value loseSprite()
127 {open braces start code blocks and must be matched with a close brace
128 scheduleRelative(newnew is used to create objects by calling the constructor Lose(lose), .5);
129 }close braces end code blocks and must match an earlier open brace
130
131 /**Adds a dot to the selected door
132 * Displays a message about door chosen and door clicked.
133 * Plays Sound forfor is a looping structure for repeatedly executing a block of code the explosion.*/
134 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value clickedDoor()
135 {open braces start code blocks and must be matched with a close brace
136 canvas.addSprite(chosendot);
137 doormsg =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("You have chosen Door #" +adds two numbers together or concatenates Strings together doorchose +adds two numbers together or concatenates Strings together
138 ".\nGood thing you didn't pick Door #" +adds two numbers together or concatenates Strings together
139 dooropen +adds two numbers together or concatenates Strings together
140 ".\nPress Q to stay or W to switch choice.");
141 doormsg.scale(.7);
142 doormsg.setLocation(.5, .20);
143 canvas.addSprite(doormsg);
144 explode.play();
145 firstclick++this is the increment operator, which increases the variable by 1;
146 }close braces end code blocks and must match an earlier open brace
147
148 /**Opens either door 2 or 3, calls the clickedDoor()*/
149 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value doorOne(intint is the type for whole numbers and it is short for integer doorint)
150 {open braces start code blocks and must be matched with a close brace
151 chosendot.setLocation(door1.getLocation());
152 doorchose =this assignment operator makes the left side equal to the right side 1;
153 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorint ==this is the comparison operator which evaluates to true if both sides are the same 0)
154 {open braces start code blocks and must be matched with a close brace
155 openDoor(doorint, door2);
156 dooropen =this assignment operator makes the left side equal to the right side 2;
157 doornot =this assignment operator makes the left side equal to the right side 3;
158 }close braces end code blocks and must match an earlier open brace
159 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorint ==this is the comparison operator which evaluates to true if both sides are the same 1)
160 {open braces start code blocks and must be matched with a close brace
161 openDoor(doorint, door3);
162 dooropen =this assignment operator makes the left side equal to the right side 3;
163 doornot =this assignment operator makes the left side equal to the right side 2;
164 }close braces end code blocks and must match an earlier open brace
165 clickedDoor();
166 }close braces end code blocks and must match an earlier open brace
167
168 /**Opens either door 1 or 3, calls the clickedDoor()*/
169 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value doorTwo(intint is the type for whole numbers and it is short for integer doorint)
170 {open braces start code blocks and must be matched with a close brace
171 chosendot.setLocation(door2.getLocation());
172 doorchose =this assignment operator makes the left side equal to the right side 2;
173 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorint ==this is the comparison operator which evaluates to true if both sides are the same 0)
174 {open braces start code blocks and must be matched with a close brace
175 openDoor(doorint, door1);
176 dooropen =this assignment operator makes the left side equal to the right side 1;
177 doornot =this assignment operator makes the left side equal to the right side 3;
178 }close braces end code blocks and must match an earlier open brace
179 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorint ==this is the comparison operator which evaluates to true if both sides are the same 1)
180 {open braces start code blocks and must be matched with a close brace
181 openDoor(doorint, door3);
182 dooropen =this assignment operator makes the left side equal to the right side 3;
183 doornot =this assignment operator makes the left side equal to the right side 1;
184 }close braces end code blocks and must match an earlier open brace
185 clickedDoor();
186 }close braces end code blocks and must match an earlier open brace
187
188 /**Opens either door 1 or 2, calls the clickedDoor()*/
189 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value doorThree(intint is the type for whole numbers and it is short for integer doorint)
190 {open braces start code blocks and must be matched with a close brace
191 chosendot.setLocation(door3.getLocation());
192 doorchose =this assignment operator makes the left side equal to the right side 3;
193 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorint ==this is the comparison operator which evaluates to true if both sides are the same 0)
194 {open braces start code blocks and must be matched with a close brace
195 dooropen =this assignment operator makes the left side equal to the right side 1;
196 doornot =this assignment operator makes the left side equal to the right side 2;
197 openDoor(doorint, door1);
198 }close braces end code blocks and must match an earlier open brace
199 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorint ==this is the comparison operator which evaluates to true if both sides are the same 1)
200 {open braces start code blocks and must be matched with a close brace
201 dooropen =this assignment operator makes the left side equal to the right side 2;
202 doornot =this assignment operator makes the left side equal to the right side 1;
203 openDoor(doorint, door2);
204 }close braces end code blocks and must match an earlier open brace
205 clickedDoor();
206 }close braces end code blocks and must match an earlier open brace
207
208 /**Removes the door sent, calls the explosion() and loseSprite()*/
209 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value openDoor(intint is the type for whole numbers and it is short for integer a, Sprite dooropened)
210 {open braces start code blocks and must be matched with a close brace
211 lose.setLocation(dooropened.getLocation());
212 explosion.setLocation(dooropened.getLocation());
213 explosion();
214 canvas.removeSprite(dooropened);
215 loseSprite();
216 }close braces end code blocks and must match an earlier open brace
217
218 /**Code to reset the game to replay without having to refresh the page.*/
219 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value resetGame()
220 {open braces start code blocks and must be matched with a close brace
221 doornot =this assignment operator makes the left side equal to the right side 0;
222 doorchose =this assignment operator makes the left side equal to the right side 0;
223 dooropen =this assignment operator makes the left side equal to the right side 0;
224 firstclick =this assignment operator makes the left side equal to the right side 0;
225 doorint =this assignment operator makes the left side equal to the right side 0;
226 canvas.addSprite(door1);
227 canvas.addSprite(door2);
228 canvas.addSprite(door3);
229 canvas.removeSprite(lose);
230 canvas.removeSprite(win);
231 canvas.removeSprite(lose1);
232 canvas.removeSprite(doormsg);
233 canvas.removeSprite(chosendot);
234 }close braces end code blocks and must match an earlier open brace
235
236 /**Sets the location of the 2nd lose graphic ifif executes the next statement only if the condition in parenthesis evaluates to true won.*/
237 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value notDoor(intint is the type for whole numbers and it is short for integer notthedoor)
238 {open braces start code blocks and must be matched with a close brace
239 ifif executes the next statement only if the condition in parenthesis evaluates to true (notthedoor ==this is the comparison operator which evaluates to true if both sides are the same 1)
240 {open braces start code blocks and must be matched with a close brace
241 lose1.setLocation(door1.getLocation());
242 }close braces end code blocks and must match an earlier open brace
243 ifif executes the next statement only if the condition in parenthesis evaluates to true (notthedoor ==this is the comparison operator which evaluates to true if both sides are the same 2)
244 {open braces start code blocks and must be matched with a close brace
245 lose1.setLocation(door2.getLocation());
246 }close braces end code blocks and must match an earlier open brace
247 ifif executes the next statement only if the condition in parenthesis evaluates to true (notthedoor ==this is the comparison operator which evaluates to true if both sides are the same 3)
248 {open braces start code blocks and must be matched with a close brace
249 lose1.setLocation(door3.getLocation());
250 }close braces end code blocks and must match an earlier open brace
251 }close braces end code blocks and must match an earlier open brace
252
253 /**Sets the location of the win graphic ifif executes the next statement only if the condition in parenthesis evaluates to true lost.*/
254 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value isDoor(intint is the type for whole numbers and it is short for integer dooropen)
255 {open braces start code blocks and must be matched with a close brace
256 ifif executes the next statement only if the condition in parenthesis evaluates to true (dooropen ==this is the comparison operator which evaluates to true if both sides are the same 1)
257 {open braces start code blocks and must be matched with a close brace
258 win.setLocation(door1.getLocation());
259 }close braces end code blocks and must match an earlier open brace
260 ifif executes the next statement only if the condition in parenthesis evaluates to true (dooropen ==this is the comparison operator which evaluates to true if both sides are the same 2)
261 {open braces start code blocks and must be matched with a close brace
262 win.setLocation(door2.getLocation());
263 }close braces end code blocks and must match an earlier open brace
264 ifif executes the next statement only if the condition in parenthesis evaluates to true (dooropen ==this is the comparison operator which evaluates to true if both sides are the same 3)
265 {open braces start code blocks and must be matched with a close brace
266 win.setLocation(door3.getLocation());
267 }close braces end code blocks and must match an earlier open brace
268 }close braces end code blocks and must match an earlier open brace
269
270 /**Removes all of the Doors from the canvas.*/
271 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value removeAllDoors()
272 {open braces start code blocks and must be matched with a close brace
273 canvas.removeSprite(door1);
274 canvas.removeSprite(door2);
275 canvas.removeSprite(door3);
276 }close braces end code blocks and must match an earlier open brace
277
278 /**If won, sets the chosen door as win and other door as lose.*/
279 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value win(ImageSprite windoor)
280 {open braces start code blocks and must be matched with a close brace
281 win.setLocation(windoor.getLocation());
282 notDoor(doornot);
283 removeAllDoors();
284 canvas.addSprite(lose1);
285 canvas.addSprite(win);
286 }close braces end code blocks and must match an earlier open brace
287
288 /**If lost, sets the chosen door as lose and other door as win*/
289 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value lose(ImageSprite losedoor)
290 {open braces start code blocks and must be matched with a close brace
291 lose1.setLocation(losedoor.getLocation());
292 isDoor(doornot);
293 removeAllDoors();
294 canvas.addSprite(lose1);
295 canvas.addSprite(win);
296 }close braces end code blocks and must match an earlier open brace
297
298 /**Last choice, sets conditions forfor is a looping structure for repeatedly executing a block of code winning*/
299 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value finalChoice(intint is the type for whole numbers and it is short for integer doorchosen)
300 {open braces start code blocks and must be matched with a close brace
301 intint is the type for whole numbers and it is short for integer lastnumber =this assignment operator makes the left side equal to the right side random.nextInt(2);
302 ifif executes the next statement only if the condition in parenthesis evaluates to true (lastnumber ==this is the comparison operator which evaluates to true if both sides are the same 1)
303 {open braces start code blocks and must be matched with a close brace
304 doormsg.setText("YOU WIN!");
305 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorchosen ==this is the comparison operator which evaluates to true if both sides are the same 1)
306 {open braces start code blocks and must be matched with a close brace
307 win(door1);
308 }close braces end code blocks and must match an earlier open brace
309 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorchosen ==this is the comparison operator which evaluates to true if both sides are the same 2)
310 {open braces start code blocks and must be matched with a close brace
311 win(door2);
312 }close braces end code blocks and must match an earlier open brace
313 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorchosen ==this is the comparison operator which evaluates to true if both sides are the same 3)
314 {open braces start code blocks and must be matched with a close brace
315 win(door3);
316 }close braces end code blocks and must match an earlier open brace
317 }close braces end code blocks and must match an earlier open brace
318 ifif executes the next statement only if the condition in parenthesis evaluates to true (lastnumber ==this is the comparison operator which evaluates to true if both sides are the same 0)
319 {open braces start code blocks and must be matched with a close brace
320 doormsg.setText("YOU LOSE!");
321 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorchosen ==this is the comparison operator which evaluates to true if both sides are the same 1)
322 {open braces start code blocks and must be matched with a close brace
323 lose(door1);
324 }close braces end code blocks and must match an earlier open brace
325 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorchosen ==this is the comparison operator which evaluates to true if both sides are the same 2)
326 {open braces start code blocks and must be matched with a close brace
327 lose(door2);
328 }close braces end code blocks and must match an earlier open brace
329 ifif executes the next statement only if the condition in parenthesis evaluates to true (doorchosen ==this is the comparison operator which evaluates to true if both sides are the same 3)
330 {open braces start code blocks and must be matched with a close brace
331 lose(door3);
332 }close braces end code blocks and must match an earlier open brace
333 }close braces end code blocks and must match an earlier open brace
334 }close braces end code blocks and must match an earlier open brace
335
336 /**Switches the door chosen when the w key is pressed.*/
337 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value switchChoice()
338 {open braces start code blocks and must be matched with a close brace
339 ifif executes the next statement only if the condition in parenthesis evaluates to true (getPlayer().getKeyboard().getLastKey() ==this is the comparison operator which evaluates to true if both sides are the same 'w')
340 {open braces start code blocks and must be matched with a close brace
341 ifif executes the next statement only if the condition in parenthesis evaluates to true (firstclick ==this is the comparison operator which evaluates to true if both sides are the same 1)
342 {open braces start code blocks and must be matched with a close brace
343 firstclick++this is the increment operator, which increases the variable by 1;
344 lastdoor =this assignment operator makes the left side equal to the right side doornot;
345 doornot =this assignment operator makes the left side equal to the right side doorchose;
346 finalChoice(lastdoor);
347 canvas.removeSprite(chosendot);
348 }close braces end code blocks and must match an earlier open brace
349 }close braces end code blocks and must match an earlier open brace
350 }close braces end code blocks and must match an earlier open brace
351
352 /**Stays on the door chosen when the q key is pressed.*/
353 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value stayChoice()
354 {open braces start code blocks and must be matched with a close brace
355 ifif executes the next statement only if the condition in parenthesis evaluates to true (getPlayer().getKeyboard().getLastKey() ==this is the comparison operator which evaluates to true if both sides are the same 'q')
356 {open braces start code blocks and must be matched with a close brace
357 ifif executes the next statement only if the condition in parenthesis evaluates to true (firstclick ==this is the comparison operator which evaluates to true if both sides are the same 1)
358 {open braces start code blocks and must be matched with a close brace
359 firstclick++this is the increment operator, which increases the variable by 1;
360 lastdoor =this assignment operator makes the left side equal to the right side doorchose;
361 finalChoice(lastdoor);
362 canvas.removeSprite(chosendot);
363 }close braces end code blocks and must match an earlier open brace
364 }close braces end code blocks and must match an earlier open brace
365 }close braces end code blocks and must match an earlier open brace
366
367 /**Watches forfor is a looping structure for repeatedly executing a block of code clicks on doors.*/
368 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value doorClick()
369 {open braces start code blocks and must be matched with a close brace
370 Point2D.Double click =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getClickLocation();
371 //did they click at all
372 ifif executes the next statement only if the condition in parenthesis evaluates to true (click !=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 &&) firstclick ==this is the comparison operator which evaluates to true if both sides are the same 0)
373 {open braces start code blocks and must be matched with a close brace
374 doorint =this assignment operator makes the left side equal to the right side random.nextInt(2);
375 ifif executes the next statement only if the condition in parenthesis evaluates to true (door1.intersects(click))
376 {open braces start code blocks and must be matched with a close brace
377 doorOne(doorint);
378 }close braces end code blocks and must match an earlier open brace
379 ifif executes the next statement only if the condition in parenthesis evaluates to true (door2.intersects(click))
380 {open braces start code blocks and must be matched with a close brace
381 doorTwo(doorint);
382 }close braces end code blocks and must match an earlier open brace
383 ifif executes the next statement only if the condition in parenthesis evaluates to true (door3.intersects(click))
384 {open braces start code blocks and must be matched with a close brace
385 doorThree(doorint);
386 }close braces end code blocks and must match an earlier open brace
387 }close braces end code blocks and must match an earlier open brace
388 }close braces end code blocks and must match an earlier open brace
389
390 /**Calls to the resetGame method when the r key is pressed*/
391 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value resetGameKey()
392 {open braces start code blocks and must be matched with a close brace
393 ifif executes the next statement only if the condition in parenthesis evaluates to true (getPlayer().getKeyboard().getLastKey() ==this is the comparison operator which evaluates to true if both sides are the same 'r')
394 {open braces start code blocks and must be matched with a close brace
395 resetGame();
396 }close braces end code blocks and must match an earlier open brace
397 }close braces end code blocks and must match an earlier open brace
398
399 /**Handle input and game events*/
400 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advanceFrame(doubledouble is the type for numbers that can contain decimal fractions timePassed)
401 {open braces start code blocks and must be matched with a close brace
402 switchChoice();
403 stayChoice();
404 doorClick();
405 resetGameKey();
406 }close braces end code blocks and must match an earlier open brace
407
408 /**Alarm classclass is a group of fields and methods used for making objects forfor is a looping structure for repeatedly executing a block of code the explosion Sprite removal.*/
409 privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects Boom implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
410 {open braces start code blocks and must be matched with a close brace
411 privateprivate is used to restrict access to the current class only Sprite spriteremove;
412
413 publicpublic is used to indicate unrestricted access (any other class can have access) Boom(Sprite sprite)
414 {open braces start code blocks and must be matched with a close brace
415 spriteremove =this assignment operator makes the left side equal to the right side sprite;
416 }close braces end code blocks and must match an earlier open brace
417
418 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
419 {open braces start code blocks and must be matched with a close brace
420 canvas.removeSprite(spriteremove);
421 }close braces end code blocks and must match an earlier open brace
422 }close braces end code blocks and must match an earlier open brace
423
424 /**Alarm classclass is a group of fields and methods used for making objects forfor is a looping structure for repeatedly executing a block of code the lose sprite addition.*/
425 privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects Lose implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
426 {open braces start code blocks and must be matched with a close brace
427 privateprivate is used to restrict access to the current class only Sprite loseadd;
428 publicpublic is used to indicate unrestricted access (any other class can have access) Lose(Sprite sprite)
429 {open braces start code blocks and must be matched with a close brace
430 loseadd =this assignment operator makes the left side equal to the right side sprite;
431 }close braces end code blocks and must match an earlier open brace
432
433 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
434 {open braces start code blocks and must be matched with a close brace
435 canvas.addSprite(loseadd);
436 }close braces end code blocks and must match an earlier open brace
437 }close braces end code blocks and must match an earlier open brace
438 }close braces end code blocks and must match an earlier open brace
|