|
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 MontyhallExperiment 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 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value clearDoors(String message, Sound sound)
116 {open braces start code blocks and must be matched with a close brace
117 canvas.removeSprite(box2);
118 canvas.removeSprite(box2L);
119
120 canvas.removeSprite(box3);
121 canvas.removeSprite(box3L);
122
123 canvas.removeSprite(box1);
124 canvas.removeSprite(box1L);
125
126 Instructions.setText(message);
127 sound.play();
128 stage =this assignment operator makes the left side equal to the right side 2;
129 }close braces end code blocks and must match an earlier open brace
130 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value clickSecond()
131 {open braces start code blocks and must be matched with a close brace
132
133
134 Instructions.setText("Stay or Switch?");
135 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
136 //did they click at all
137 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)
138 {open braces start code blocks and must be matched with a close brace
139 ifif executes the next statement only if the condition in parenthesis evaluates to true(box1.intersects(click))
140 {open braces start code blocks and must be matched with a close brace
141
142
143 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)
144 {open braces start code blocks and must be matched with a close brace
145 clearDoors("You Win" , goodsound);
146 stage=this assignment operator makes the left side equal to the right side 2;
147 }close braces end code blocks and must match an earlier open brace
148 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)
149 {open braces start code blocks and must be matched with a close brace
150 clearDoors("You Lose" , badsound);
151 stage =this assignment operator makes the left side equal to the right side 2;
152 }close braces end code blocks and must match an earlier open brace
153 elseelse is what happens when the if condition is false
154 {open braces start code blocks and must be matched with a close brace
155 clearDoors("You Lose" , badsound);
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 }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(box2.intersects(click))
160 {open braces start code blocks and must be matched with a close brace
161
162 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)
163 {open braces start code blocks and must be matched with a close brace
164 clearDoors("You Lose" , badsound);
165 stage =this assignment operator makes the left side equal to the right side 2;
166 }close braces end code blocks and must match an earlier open brace
167 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)
168 {open braces start code blocks and must be matched with a close brace
169 clearDoors("You Win" , goodsound);
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 elseelse is what happens when the if condition is false
173 {open braces start code blocks and must be matched with a close brace
174 clearDoors("You Lose" , badsound);
175 stage =this assignment operator makes the left side equal to the right side 2;
176 }close braces end code blocks and must match an earlier open brace
177 }close braces end code blocks and must match an earlier open brace
178 ifif executes the next statement only if the condition in parenthesis evaluates to true(box3.intersects(click))
179 {open braces start code blocks and must be matched with a close brace
180
181 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)
182 {open braces start code blocks and must be matched with a close brace
183 clearDoors("You Lose" , badsound);
184 stage =this assignment operator makes the left side equal to the right side 2;
185 }close braces end code blocks and must match an earlier open brace
186 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)
187 {open braces start code blocks and must be matched with a close brace
188 clearDoors("You Lose" , badsound);
189
190 stage =this assignment operator makes the left side equal to the right side 2;
191 }close braces end code blocks and must match an earlier open brace
192 elseelse is what happens when the if condition is false
193 {open braces start code blocks and must be matched with a close brace
194 clearDoors("You Win" , goodsound);
195 stage =this assignment operator makes the left side equal to the right side 2;
196 }close braces end code blocks and must match an earlier open brace
197 }close braces end code blocks and must match an earlier open brace
198 }close braces end code blocks and must match an earlier open brace
199 }close braces end code blocks and must match an earlier open brace
200
201
202 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
203 {open braces start code blocks and must be matched with a close brace
204 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"));
205 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"));
206 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");
207 Instructions.setScale(.5);
208 Instructions.setLocation(.3, .3);
209 Instructions.setColor(Color.WHITE);
210
211 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"));
212 prize1.setScale(0.25);
213 prize1.setLocation(.20, 0.5);
214
215 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"));
216 prize2.setScale(0.25);
217 prize2.setLocation(.50, 0.5);
218
219 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"));
220 prize3.setScale(0.25);
221 prize3.setLocation(.80, 0.5);
222
223
224 String text=this assignment operator makes the left side equal to the right side"heads";
225 x=this assignment operator makes the left side equal to the right siderandom.nextInt(3);
226 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)
227 {open braces start code blocks and must be matched with a close brace
228 prize1.setLocation(.20, 0.5);
229 prize2.setLocation(.50, 0.5);
230 prize3.setLocation(.80, 0.5);
231
232 }close braces end code blocks and must match an earlier open brace
233 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)
234 {open braces start code blocks and must be matched with a close brace
235 prize2.setLocation(.20, 0.5);
236 prize1.setLocation(.50, 0.5);
237 prize3.setLocation(.80, 0.5);
238
239 }close braces end code blocks and must match an earlier open brace
240 elseelse is what happens when the if condition is false
241 {open braces start code blocks and must be matched with a close brace
242 prize3.setLocation(.20, 0.5);
243 prize2.setLocation(.50, 0.5);
244 prize1.setLocation(.80, 0.5);
245 }close braces end code blocks and must match an earlier open brace
246
247 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"));
248 box1.setScale(0.25);
249 box1.setLocation(0.20, 0.5);
250 box1L=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("1");
251 box1L.setColor(Color.GREEN);
252 box1L.setScale(0.25);
253 box1L.setLocation(0.20, 0.5);
254
255 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"));
256 box2.setScale(0.25);
257 box2.setLocation(0.50, 0.5);
258 box2L=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("2");
259 box2L.setColor(Color.GREEN);
260 box2L.setScale(0.25);
261 box2L.setLocation(0.50, 0.5);
262
263 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"));
264 box3.setScale(0.25);
265 box3.setLocation(0.80, 0.5);
266 box3L=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("3");
267 box3L.setColor(Color.GREEN);
268 box3L.setScale(0.25);
269 box3L.setLocation(0.80, 0.5);
270 }close braces end code blocks and must match an earlier open brace
271
272 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
273 {open braces start code blocks and must be matched with a close brace
274 canvas.addSprite(Instructions);
275 canvas.addSprite(prize1);
276 canvas.addSprite(prize2);
277 canvas.addSprite(prize3);
278 canvas.addSprite(box1);
279 canvas.addSprite(box2);
280 canvas.addSprite(box3);
281 canvas.addSprite(box1L);
282 canvas.addSprite(box2L);
283 canvas.addSprite(box3L);
284
285
286 }close braces end code blocks and must match an earlier open brace
287
288 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)
289
290 {open braces start code blocks and must be matched with a close brace
291 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)
292 {open braces start code blocks and must be matched with a close brace
293 clickFirst();
294 }close braces end code blocks and must match an earlier open brace
295 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)
296 {open braces start code blocks and must be matched with a close brace
297 clickSecond();
298 }close braces end code blocks and must match an earlier open brace
299 }close braces end code blocks and must match an earlier open brace
300 }close braces end code blocks and must match an earlier open brace
|