|
001 packagepackage is used to name the directory or folder a class is in ChrisHull;
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 * @authornull Chull
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 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer x;
015 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;
016 privateprivate is used to restrict access to the current class only StringSprite Instructions;
017 /* got idea from KimMooney */
018 privateprivate is used to restrict access to the current class only Sound goodsound;
019 privateprivate is used to restrict access to the current class only Sound badsound;
020 privateprivate is used to restrict access to the current class only Sprite box1;
021 privateprivate is used to restrict access to the current class only Sprite box2;
022 privateprivate is used to restrict access to the current class only Sprite box3;
023 privateprivate is used to restrict access to the current class only Sprite box1L;
024 privateprivate is used to restrict access to the current class only Sprite box2L;
025 privateprivate is used to restrict access to the current class only Sprite box3L;
026 privateprivate is used to restrict access to the current class only Sprite prize1;
027 privateprivate is used to restrict access to the current class only Sprite prize2;
028 privateprivate is used to restrict access to the current class only Sprite prize3;
029
030
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 toggleAudible();
035 makeSprites();
036 addSprites();
037
038 }close braces end code blocks and must match an earlier open brace
039 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value clickFirst()
040 {open braces start code blocks and must be matched with a close brace
041 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
042 //did they click at all
043 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)
044 {open braces start code blocks and must be matched with a close brace
045 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
046 {open braces start code blocks and must be matched with a close brace
047
048
049 ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same0)
050 {open braces start code blocks and must be matched with a close brace
051 canvas.removeSprite(box2);
052 canvas.removeSprite(box2L);
053 stage =this assignment operator makes the left side equal to the right side 1;
054 }close braces end code blocks and must match an earlier open brace
055 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same1)
056 {open braces start code blocks and must be matched with a close brace
057 canvas.removeSprite(box3);
058 canvas.removeSprite(box3L);
059 stage =this assignment operator makes the left side equal to the right side 1;
060 }close braces end code blocks and must match an earlier open brace
061 elseelse is what happens when the if condition is false
062 {open braces start code blocks and must be matched with a close brace
063 canvas.removeSprite(box2);
064 canvas.removeSprite(box2L);
065 stage =this assignment operator makes the left side equal to the right side 1;
066 }close braces end code blocks and must match an earlier open brace
067 }close braces end code blocks and must match an earlier open brace
068 ifif executes the next statement only if the condition in parenthesis evaluates to true(box2.intersects(click))
069 {open braces start code blocks and must be matched with a close brace
070
071 ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same0)
072 {open braces start code blocks and must be matched with a close brace
073 canvas.removeSprite(box2);
074 canvas.removeSprite(box2L);
075 stage =this assignment operator makes the left side equal to the right side 1;
076 }close braces end code blocks and must match an earlier open brace
077 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same1)
078 {open braces start code blocks and must be matched with a close brace
079 canvas.removeSprite(box3);
080 canvas.removeSprite(box3L);
081 stage =this assignment operator makes the left side equal to the right side 1;
082 }close braces end code blocks and must match an earlier open brace
083 elseelse is what happens when the if condition is false
084 {open braces start code blocks and must be matched with a close brace
085 canvas.removeSprite(box2);
086 canvas.removeSprite(box2L);
087 stage =this assignment operator makes the left side equal to the right side 1;
088 }close braces end code blocks and must match an earlier open brace
089 }close braces end code blocks and must match an earlier open brace
090 ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
091 {open braces start code blocks and must be matched with a close brace
092
093 ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same0)
094 {open braces start code blocks and must be matched with a close brace
095 canvas.removeSprite(box2);
096 canvas.removeSprite(box2L);
097 stage =this assignment operator makes the left side equal to the right side 1;
098 }close braces end code blocks and must match an earlier open brace
099 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same1)
100 {open braces start code blocks and must be matched with a close brace
101 canvas.removeSprite(box3);
102 canvas.removeSprite(box3L);
103 stage =this assignment operator makes the left side equal to the right side 1;
104 }close braces end code blocks and must match an earlier open brace
105 elseelse is what happens when the if condition is false
106 {open braces start code blocks and must be matched with a close brace
107 canvas.removeSprite(box2);
108 http://ggc.javawide.org/index.php?title=ChrisHull/Montyhall&action=edit
109 canvas.removeSprite(box2L);
110 stage =this assignment operator makes the left side equal to the right side 1;
111 }close braces end code blocks and must match an earlier open brace
112 }close braces end code blocks and must match an earlier open brace
113 }close braces end code blocks and must match an earlier open brace
114 }close braces end code blocks and must match an earlier open brace
115
116 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value clickSecond()
117 {open braces start code blocks and must be matched with a close brace
118
119
120 Instructions.setText("Stay or Switch?");
121 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
122 //did they click at all
123 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)
124 {open braces start code blocks and must be matched with a close brace
125 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
126 {open braces start code blocks and must be matched with a close brace
127
128
129 ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same0)
130 {open braces start code blocks and must be matched with a close brace
131 canvas.removeSprite(box2);
132 canvas.removeSprite(box2L);
133
134 canvas.removeSprite(box3);
135 canvas.removeSprite(box3L);
136
137 canvas.removeSprite(box1);
138 canvas.removeSprite(box1L);
139
140 Instructions.setText("You Win!");
141 goodsound.play();
142 stage =this assignment operator makes the left side equal to the right side 2;
143 }close braces end code blocks and must match an earlier open brace
144 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same1)
145 {open braces start code blocks and must be matched with a close brace
146 canvas.removeSprite(box2);
147 canvas.removeSprite(box2L);
148
149 canvas.removeSprite(box3);
150 canvas.removeSprite(box3L);
151
152 canvas.removeSprite(box1);
153 canvas.removeSprite(box1L);
154 Instructions.setText("You Lose!");
155 badsound.play();
156 stage =this assignment operator makes the left side equal to the right side 2;
157 }close braces end code blocks and must match an earlier open brace
158 elseelse is what happens when the if condition is false
159 {open braces start code blocks and must be matched with a close brace
160 canvas.removeSprite(box2);
161 canvas.removeSprite(box2L);
162
163 canvas.removeSprite(box3);
164 canvas.removeSprite(box3L);
165
166 canvas.removeSprite(box1);
167 canvas.removeSprite(box1L);
168 Instructions.setText("You Lose!");
169 badsound.play();
170 stage =this assignment operator makes the left side equal to the right side 2;
171 }close braces end code blocks and must match an earlier open brace
172 }close braces end code blocks and must match an earlier open brace
173 ifif executes the next statement only if the condition in parenthesis evaluates to true(box2.intersects(click))
174 {open braces start code blocks and must be matched with a close brace
175
176 ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same0)
177 {open braces start code blocks and must be matched with a close brace
178 canvas.removeSprite(box2);
179 canvas.removeSprite(box2L);
180
181 canvas.removeSprite(box3);
182 canvas.removeSprite(box3L);
183
184 canvas.removeSprite(box1);
185 canvas.removeSprite(box1L);
186 Instructions.setText("You Lose!");
187 badsound.play();
188 stage =this assignment operator makes the left side equal to the right side 2;
189 }close braces end code blocks and must match an earlier open brace
190 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same1)
191 {open braces start code blocks and must be matched with a close brace
192 canvas.removeSprite(box2);
193 canvas.removeSprite(box2L);
194
195 canvas.removeSprite(box3);
196 canvas.removeSprite(box3L);
197
198 canvas.removeSprite(box1);
199 canvas.removeSprite(box1L);
200 Instructions.setText("You Win!");
201 goodsound.play();
202 stage =this assignment operator makes the left side equal to the right side 2;
203 }close braces end code blocks and must match an earlier open brace
204 elseelse is what happens when the if condition is false
205 {open braces start code blocks and must be matched with a close brace
206 canvas.removeSprite(box2);
207 canvas.removeSprite(box2L);
208
209 canvas.removeSprite(box3);
210 canvas.removeSprite(box3L);
211
212 canvas.removeSprite(box1);
213 canvas.removeSprite(box1L);
214 Instructions.setText("You Lose!");
215 badsound.play();
216 stage =this assignment operator makes the left side equal to the right side 2;
217 }close braces end code blocks and must match an earlier open brace
218 }close braces end code blocks and must match an earlier open brace
219 ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
220 {open braces start code blocks and must be matched with a close brace
221
222 ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same0)
223 {open braces start code blocks and must be matched with a close brace
224 canvas.removeSprite(box2);
225 canvas.removeSprite(box2L);
226
227 canvas.removeSprite(box3);
228 canvas.removeSprite(box3L);
229
230 canvas.removeSprite(box1);
231 canvas.removeSprite(box1L);
232 Instructions.setText("You Lose!");
233 badsound.play();
234 stage =this assignment operator makes the left side equal to the right side 2;
235 }close braces end code blocks and must match an earlier open brace
236 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (x==this is the comparison operator which evaluates to true if both sides are the same1)
237 {open braces start code blocks and must be matched with a close brace
238 canvas.removeSprite(box2);
239 canvas.removeSprite(box2L);
240
241 canvas.removeSprite(box3);
242 canvas.removeSprite(box3L);
243
244 canvas.removeSprite(box1);
245 canvas.removeSprite(box1L);
246 Instructions.setText("You Lose!");
247 badsound.play();
248 stage =this assignment operator makes the left side equal to the right side 2;
249 }close braces end code blocks and must match an earlier open brace
250 elseelse is what happens when the if condition is false
251 {open braces start code blocks and must be matched with a close brace
252 canvas.removeSprite(box2);
253 canvas.removeSprite(box2L);
254
255 canvas.removeSprite(box3);
256 canvas.removeSprite(box3L);
257
258 canvas.removeSprite(box1);
259 canvas.removeSprite(box1L);
260 Instructions.setText("You Win!");
261 goodsound.play();
262 stage =this assignment operator makes the left side equal to the right side 2;
263 }close braces end code blocks and must match an earlier open brace
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 }close braces end code blocks and must match an earlier open brace
267
268
269 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
270 {open braces start code blocks and must be matched with a close brace
271 goodsound =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("Clap.wav"));
272 badsound =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("Boom.wav"));
273 Instructions=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Please choose your door");
274 Instructions.setScale(.5);
275 Instructions.setLocation(.3, .3);
276 Instructions.setColor(Color.WHITE);
277
278 prize1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("P1.JPG"));
279 prize1.setScale(0.25);
280 prize1.setLocation(.20, 0.5);
281
282 prize2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("P2.JPG"));
283 prize2.setScale(0.25);
284 prize2.setLocation(.50, 0.5);
285
286 prize3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("P2.JPG"));
287 prize3.setScale(0.25);
288 prize3.setLocation(.80, 0.5);
289
290
291
292 x=this assignment operator makes the left side equal to the right siderandom.nextInt(3);
293 ifif executes the next statement only if the condition in parenthesis evaluates to true(x==this is the comparison operator which evaluates to true if both sides are the same0)
294 {open braces start code blocks and must be matched with a close brace
295 prize1.setLocation(.20, 0.5);
296 prize2.setLocation(.50, 0.5);
297 prize3.setLocation(.80, 0.5);
298
299 }close braces end code blocks and must match an earlier open brace
300 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(x==this is the comparison operator which evaluates to true if both sides are the same1)
301 {open braces start code blocks and must be matched with a close brace
302 prize2.setLocation(.20, 0.5);
303 prize1.setLocation(.50, 0.5);
304 prize3.setLocation(.80, 0.5);
305
306 }close braces end code blocks and must match an earlier open brace
307 elseelse is what happens when the if condition is false
308 {open braces start code blocks and must be matched with a close brace
309 prize3.setLocation(.20, 0.5);
310 prize2.setLocation(.50, 0.5);
311 prize1.setLocation(.80, 0.5);
312 }close braces end code blocks and must match an earlier open brace
313
314 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("Doorb.JPG"));
315 box1.setScale(0.25);
316 box1.setLocation(0.20, 0.5);
317 box1L=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("1");
318 box1L.setColor(Color.GREEN);
319 box1L.setScale(0.25);
320 box1L.setLocation(0.20, 0.5);
321
322 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("Doorb.JPG"));
323 box2.setScale(0.25);
324 box2.setLocation(0.50, 0.5);
325 box2L=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("2");
326 box2L.setColor(Color.GREEN);
327 box2L.setScale(0.25);
328 box2L.setLocation(0.50, 0.5);
329
330 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("Doorb.JPG"));
331 box3.setScale(0.25);
332 box3.setLocation(0.80, 0.5);
333 box3L=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("3");
334 box3L.setColor(Color.GREEN);
335 box3L.setScale(0.25);
336 box3L.setLocation(0.80, 0.5);
337 }close braces end code blocks and must match an earlier open brace
338
339 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
340 {open braces start code blocks and must be matched with a close brace
341 canvas.addSprite(Instructions);
342 canvas.addSprite(prize1);
343 canvas.addSprite(prize2);
344 canvas.addSprite(prize3);
345 canvas.addSprite(box1);
346 canvas.addSprite(box2);
347 canvas.addSprite(box3);
348 canvas.addSprite(box1L);
349 canvas.addSprite(box2L);
350 canvas.addSprite(box3L);
351
352
353 }close braces end code blocks and must match an earlier open brace
354
355 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)
356
357 {open braces start code blocks and must be matched with a close brace
358 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)
359 {open braces start code blocks and must be matched with a close brace
360 clickFirst();
361 }close braces end code blocks and must match an earlier open brace
362 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)
363 {open braces start code blocks and must be matched with a close brace
364 clickSecond();
365 }close braces end code blocks and must match an earlier open brace
366 }close braces end code blocks and must match an earlier open brace
367 }close braces end code blocks and must match an earlier open brace
|