|
001 packagepackage is used to name the directory or folder a class is in ThomasJohanningmeier;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007
008 /**
009 * All about my game here.
010 * @authorthis is the Javadoc tag for documenting who created the source code Tjohanni
011 */
012 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 MontyHall extendsextends means to customize or extend the functionality of a class GameLoop
013 {open braces start code blocks and must be matched with a close brace
014
015
016 privateprivate is used to restrict access to the current class only StringSprite lose;
017 privateprivate is used to restrict access to the current class only StringSprite win;
018 privateprivate is used to restrict access to the current class only StringSprite direction1;
019 privateprivate is used to restrict access to the current class only StringSprite direction2;
020 privateprivate is used to restrict access to the current class only ImageSprite box1;
021 privateprivate is used to restrict access to the current class only ImageSprite box2;
022 privateprivate is used to restrict access to the current class only ImageSprite box3;
023 privateprivate is used to restrict access to the current class only StringSprite door1Sprite;
024 privateprivate is used to restrict access to the current class only StringSprite door2Sprite;
025 privateprivate is used to restrict access to the current class only StringSprite door3Sprite;
026 privateprivate is used to restrict access to the current class only ImageSprite greendot;
027 privateprivate is used to restrict access to the current class only ImageSprite reddot;
028 privateprivate is used to restrict access to the current class only ImageSprite reddot2;
029 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer stage;
030 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer prize;
031
032 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
033 {open braces start code blocks and must be matched with a close brace
034 stage=this assignment operator makes the left side equal to the right side0;
035 makeSprites();
036 addSprites();
037 }close braces end code blocks and must match an earlier open brace
038
039 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
040 {open braces start code blocks and must be matched with a close brace
041 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
042 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
043
044 greendot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Treasure.jpg"));
045 greendot.setScale(0.20);
046 greendot.setColor(Color.GREEN);
047
048 reddot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("atom_bomb.jpg"));
049 reddot.setScale(0.20);
050 reddot.setColor(Color.RED);
051
052 reddot2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("atom_bomb.jpg"));
053 reddot2.setScale(0.20);
054 reddot2.setColor(Color.RED);
055
056 box1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("planet1.jpg"));
057 box1.setScale(0.25);
058 box1.setLocation(0.25, 0.5);
059 box1.setColor(Color.YELLOW);
060
061 box2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("planet2.jpg"));
062 box2.setScale(0.25);
063 box2.setLocation(0.5, 0.5);
064 box2.setColor(Color.YELLOW);
065
066 box3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("planet3.jpg"));
067 box3.setScale(0.25);
068 box3.setLocation(0.75, 0.5);
069 box3.setColor(Color.YELLOW);
070
071 door1Sprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Door 1");
072 door1Sprite.setHeight(0.05);
073 door1Sprite.setLocation(0.25, 0.68);
074 door1Sprite.setColor(Color.BLUE);
075
076 door2Sprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Door 2");
077 door2Sprite.setHeight(0.05);
078 door2Sprite.setLocation(0.5, 0.68);
079 door2Sprite.setColor(Color.BLUE);
080
081 door3Sprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Door 3");
082 door3Sprite.setHeight(0.05);
083 door3Sprite.setLocation(0.75, 0.68);
084 door3Sprite.setColor(Color.BLUE);
085
086 direction1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Pick a Door!");
087 direction1.setHeight(.10);
088 direction1.setLocation(0.5, 0.9);
089 direction1.setColor(Color.YELLOW);
090
091 direction2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click the other door to change doors or click the same door again!");
092 direction2.setHeight(.030);
093 direction2.setLocation(0.5, 0.9);
094 direction2.setColor(Color.YELLOW);
095
096 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Win!");
097 win.setHeight(.10);
098 win.setLocation(0.5, 0.9);
099 win.setColor(Color.YELLOW);
100
101 lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Lose!");
102 lose.setHeight(.10);
103 lose.setLocation(0.5, 0.9);
104 lose.setColor(Color.YELLOW);
105
106
107
108 }close braces end code blocks and must match an earlier open brace
109 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
110 {open braces start code blocks and must be matched with a close brace
111 prize=this assignment operator makes the left side equal to the right siderandom.nextInt(3)+adds two numbers together or concatenates Strings together1;
112
113 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
114 {open braces start code blocks and must be matched with a close brace
115 greendot.setLocation(0.75, 0.5);
116 reddot.setLocation(0.5, 0.5);
117 reddot2.setLocation(0.25, 0.5);
118 }close braces end code blocks and must match an earlier open brace
119 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
120 {open braces start code blocks and must be matched with a close brace
121 greendot.setLocation(0.25, 0.5);
122 reddot.setLocation(0.75, 0.5);
123 reddot2.setLocation(0.5, 0.5);
124 }close braces end code blocks and must match an earlier open brace
125 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same3)
126 {open braces start code blocks and must be matched with a close brace
127 greendot.setLocation(0.5, 0.5);
128 reddot.setLocation(0.25, 0.5);
129 reddot2.setLocation(0.75, 0.5);
130 }close braces end code blocks and must match an earlier open brace
131
132
133 canvas.addSprite(reddot2);
134 canvas.addSprite(reddot);
135 canvas.addSprite(greendot);
136 canvas.addSprite(box1);
137 canvas.addSprite(box2);
138 canvas.addSprite(box3);
139 canvas.addSprite(door1Sprite);
140 canvas.addSprite(door2Sprite);
141 canvas.addSprite(door3Sprite);
142 canvas.addSprite(direction1);
143 }close braces end code blocks and must match an earlier open brace
144
145 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleFirstClickDoor1()
146 {open braces start code blocks and must be matched with a close brace
147 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
148 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
149 {open braces start code blocks and must be matched with a close brace
150 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
151 {open braces start code blocks and must be matched with a close brace
152 canvas.removeSprite(box2);
153 canvas.removeSprite(door2Sprite);
154 canvas.removeSprite(direction1);
155 canvas.addSprite(direction2);
156 stage=this assignment operator makes the left side equal to the right side1;
157 }close braces end code blocks and must match an earlier open brace
158 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
159 {open braces start code blocks and must be matched with a close brace
160 canvas.removeSprite(box3);
161 canvas.removeSprite(door3Sprite);
162 canvas.removeSprite(direction1);
163 canvas.addSprite(direction2);
164 stage=this assignment operator makes the left side equal to the right side1;
165 }close braces end code blocks and must match an earlier open brace
166 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same3)
167 {open braces start code blocks and must be matched with a close brace
168 canvas.removeSprite(box3);
169 canvas.removeSprite(door3Sprite);
170 canvas.removeSprite(direction1);
171 canvas.addSprite(direction2);
172 stage=this assignment operator makes the left side equal to the right side1;
173 }close braces end code blocks and must match an earlier open brace
174 }close braces end code blocks and must match an earlier open brace
175
176 }close braces end code blocks and must match an earlier open brace
177
178 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleFirstClickDoor2()
179 {open braces start code blocks and must be matched with a close brace
180 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
181 ifif executes the next statement only if the condition in parenthesis evaluates to true(box2.intersects(click))
182 {open braces start code blocks and must be matched with a close brace
183 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
184 {open braces start code blocks and must be matched with a close brace
185 canvas.removeSprite(box1);
186 canvas.removeSprite(door1Sprite);
187 canvas.removeSprite(direction1);
188 canvas.addSprite(direction2);
189 stage=this assignment operator makes the left side equal to the right side1;
190 }close braces end code blocks and must match an earlier open brace
191 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
192 {open braces start code blocks and must be matched with a close brace
193 canvas.removeSprite(box3);
194 canvas.removeSprite(door3Sprite);
195 canvas.removeSprite(direction1);
196 canvas.addSprite(direction2);
197 stage=this assignment operator makes the left side equal to the right side1;
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(prize==this is the comparison operator which evaluates to true if both sides are the same3)
200 {open braces start code blocks and must be matched with a close brace
201 canvas.removeSprite(box1);
202 canvas.removeSprite(door1Sprite);
203 canvas.removeSprite(direction1);
204 canvas.addSprite(direction2);
205 stage=this assignment operator makes the left side equal to the right side1;
206 }close braces end code blocks and must match an earlier open brace
207 }close braces end code blocks and must match an earlier open brace
208 }close braces end code blocks and must match an earlier open brace
209
210 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleFirstClickDoor3()
211 {open braces start code blocks and must be matched with a close brace
212 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
213 ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
214 {open braces start code blocks and must be matched with a close brace
215 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
216 {open braces start code blocks and must be matched with a close brace
217 canvas.removeSprite(box1);
218 canvas.removeSprite(door1Sprite);
219 canvas.removeSprite(direction1);
220 canvas.addSprite(direction2);
221 stage=this assignment operator makes the left side equal to the right side1;
222 }close braces end code blocks and must match an earlier open brace
223 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
224 {open braces start code blocks and must be matched with a close brace
225 canvas.removeSprite(box2);
226 canvas.removeSprite(door2Sprite);
227 canvas.removeSprite(direction1);
228 canvas.addSprite(direction2);
229 stage=this assignment operator makes the left side equal to the right side1;
230 }close braces end code blocks and must match an earlier open brace
231 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same3)
232 {open braces start code blocks and must be matched with a close brace
233 canvas.removeSprite(box1);
234 canvas.removeSprite(door1Sprite);
235 canvas.removeSprite(direction1);
236 canvas.addSprite(direction2);
237 stage=this assignment operator makes the left side equal to the right side1;
238 }close braces end code blocks and must match an earlier open brace
239 }close braces end code blocks and must match an earlier open brace
240
241 }close braces end code blocks and must match an earlier open brace
242 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleSecondClickDoor1()
243 {open braces start code blocks and must be matched with a close brace
244 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
245 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
246 {open braces start code blocks and must be matched with a close brace
247 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
248 {open braces start code blocks and must be matched with a close brace
249 canvas.removeSprite(box1);
250 canvas.removeSprite(door1Sprite);
251 canvas.removeSprite(direction2);
252 canvas.addSprite(lose);
253 stage=this assignment operator makes the left side equal to the right side3;
254 }close braces end code blocks and must match an earlier open brace
255 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
256 {open braces start code blocks and must be matched with a close brace
257 canvas.removeSprite(box1);
258 canvas.removeSprite(door1Sprite);
259 canvas.removeSprite(direction2);
260 canvas.addSprite(win);
261 stage=this assignment operator makes the left side equal to the right side3;
262 }close braces end code blocks and must match an earlier open brace
263 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same3)
264 {open braces start code blocks and must be matched with a close brace
265 canvas.removeSprite(box1);
266 canvas.removeSprite(door1Sprite);
267 canvas.removeSprite(direction2);
268 canvas.addSprite(lose);
269 stage=this assignment operator makes the left side equal to the right side3;
270 }close braces end code blocks and must match an earlier open brace
271 }close braces end code blocks and must match an earlier open brace
272 }close braces end code blocks and must match an earlier open brace
273 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleSecondClickDoor2()
274 {open braces start code blocks and must be matched with a close brace
275 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
276 ifif executes the next statement only if the condition in parenthesis evaluates to true(box2.intersects(click))
277 {open braces start code blocks and must be matched with a close brace
278 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
279 {open braces start code blocks and must be matched with a close brace
280 canvas.removeSprite(box2);
281 canvas.removeSprite(door2Sprite);
282 canvas.removeSprite(direction2);
283 canvas.addSprite(lose);
284 stage=this assignment operator makes the left side equal to the right side3;
285 }close braces end code blocks and must match an earlier open brace
286 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
287 {open braces start code blocks and must be matched with a close brace
288 canvas.removeSprite(box2);
289 canvas.removeSprite(door2Sprite);
290 canvas.removeSprite(direction2);
291 canvas.addSprite(lose);
292 stage=this assignment operator makes the left side equal to the right side3;
293 }close braces end code blocks and must match an earlier open brace
294 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same3)
295 {open braces start code blocks and must be matched with a close brace
296 canvas.removeSprite(box2);
297 canvas.removeSprite(door2Sprite);
298 canvas.removeSprite(direction2);
299 canvas.addSprite(win);
300 stage=this assignment operator makes the left side equal to the right side3;
301 }close braces end code blocks and must match an earlier open brace
302 }close braces end code blocks and must match an earlier open brace
303 }close braces end code blocks and must match an earlier open brace
304 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleSecondClickDoor3()
305 {open braces start code blocks and must be matched with a close brace
306 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
307 ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
308 {open braces start code blocks and must be matched with a close brace
309 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same1)
310 {open braces start code blocks and must be matched with a close brace
311 canvas.removeSprite(box3);
312 canvas.removeSprite(door3Sprite);
313 canvas.removeSprite(direction2);
314 canvas.addSprite(win);
315 stage=this assignment operator makes the left side equal to the right side3;
316 }close braces end code blocks and must match an earlier open brace
317 ifif executes the next statement only if the condition in parenthesis evaluates to true(prize==this is the comparison operator which evaluates to true if both sides are the same2)
318 {open braces start code blocks and must be matched with a close brace
319 canvas.removeSprite(box3);
320 canvas.removeSprite(door3Sprite);
321 canvas.removeSprite(direction2);
322 canvas.addSprite(lose);
323 stage=this assignment operator makes the left side equal to the right side3;
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(prize==this is the comparison operator which evaluates to true if both sides are the same3)
326 {open braces start code blocks and must be matched with a close brace
327 canvas.removeSprite(box3);
328 canvas.removeSprite(door3Sprite);
329 canvas.removeSprite(direction2);
330 canvas.addSprite(lose);
331 stage=this assignment operator makes the left side equal to the right side3;
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
335 }close braces end code blocks and must match an earlier open brace
336 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)
337 {open braces start code blocks and must be matched with a close brace
338
339 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
340 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 differentnullnull is the value used to refer to a non-existant object)
341 {open braces start code blocks and must be matched with a close brace
342
343 ifif executes the next statement only if the condition in parenthesis evaluates to true(stage==this is the comparison operator which evaluates to true if both sides are the same0)
344 {open braces start code blocks and must be matched with a close brace
345 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
346 {open braces start code blocks and must be matched with a close brace
347 handleFirstClickDoor1();
348 }close braces end code blocks and must match an earlier open brace
349 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(box2.intersects(click))
350 {open braces start code blocks and must be matched with a close brace
351 handleFirstClickDoor2();
352 }close braces end code blocks and must match an earlier open brace
353 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
354 {open braces start code blocks and must be matched with a close brace
355 handleFirstClickDoor3();
356 }close braces end code blocks and must match an earlier open brace
357 }close braces end code blocks and must match an earlier open brace
358 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(stage==this is the comparison operator which evaluates to true if both sides are the same1)
359 {open braces start code blocks and must be matched with a close brace
360 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
361 {open braces start code blocks and must be matched with a close brace
362 handleSecondClickDoor1();
363 }close braces end code blocks and must match an earlier open brace
364 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(box2.intersects(click))
365 {open braces start code blocks and must be matched with a close brace
366 handleSecondClickDoor2();
367 }close braces end code blocks and must match an earlier open brace
368 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
369 {open braces start code blocks and must be matched with a close brace
370 handleSecondClickDoor3();
371 }close braces end code blocks and must match an earlier open brace
372 }close braces end code blocks and must match an earlier open brace
373 }close braces end code blocks and must match an earlier open brace
374 }close braces end code blocks and must match an earlier open brace
375 }close braces end code blocks and must match an earlier open brace
|