|
001 packagepackage is used to name the directory or folder a class is in mkim;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * All about my game.
009 * @authornull My Name Here
010 */
011 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 montyhallsecond extendsextends means to customize or extend the functionality of a class Game
012 {open braces start code blocks and must be matched with a close brace
013 privateprivate is used to restrict access to the current class only ImageSprite door1, door2, door3;
014 privateprivate is used to restrict access to the current class only ImageSprite loser1, loser2;
015 privateprivate is used to restrict access to the current class only ImageSprite winner;
016 privateprivate is used to restrict access to the current class only StringSprite header, answer;
017 privateprivate is used to restrict access to the current class only StringSprite num1, num2, num3;
018 privateprivate is used to restrict access to the current class only StringSprite win, fail;
019 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer doorpicked;
020 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 =this assignment operator makes the left side equal to the right side 0;
021 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer clickcount =this assignment operator makes the left side equal to the right side 0;
022 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer q;
023 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer w;
024 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer e;
025 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer r;
026 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer open;
027 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer notopen;
028 /**sets up the game*/
029 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
030 {open braces start code blocks and must be matched with a close brace
031 clickcount=this assignment operator makes the left side equal to the right side0;
032 makeSprite();
033 addSprite();
034 }close braces end code blocks and must match an earlier open brace
035 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprite()
036 {open braces start code blocks and must be matched with a close brace
037 door1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Door123444.jpg");
038 door1.setLocation(.2, .5);
039 door1.setScale(.5);
040 door1.setVisible(truetrue is the boolean value that is the opposite of false);
041
042 door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Door123444.jpg");
043 door2.setLocation(.5, .5);
044 door2.setScale(.5);
045 door2.setVisible(truetrue is the boolean value that is the opposite of false);
046
047 door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Door123444.jpg");
048 door3.setLocation(.8, .5);
049 door3.setScale(.5);
050 door3.setVisible(truetrue is the boolean value that is the opposite of false);
051
052 loser1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Loser0000.JPG");
053 loser1.setLocation(.2, .5);
054 loser1.setScale(.1);
055
056 loser2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Loser0000.JPG");
057 loser2.setLocation(.5, .5);
058 loser2.setScale(.1);
059
060 winner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Win12333333.jpg");
061 winner.setLocation(.8, .5);
062 winner.setScale(.1);
063
064 header=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Choose a Door");
065 header.setLocation(.5, .2);
066 header.setSize(.3);
067 canvas.addSprite(header);
068
069 num1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("1");
070 num1.setLocation(.2, .85);
071 num1.setSize(.15);
072
073 num2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("2");
074 num2.setLocation(.5, .85);
075 num2.setSize(.15);
076
077 num3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("3");
078 num3.setLocation(.8, .85);
079 num3.setSize(.15);
080
081 answer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Are You Sure?");
082 answer.setLocation(.5, .1);
083 answer.setSize(.5);
084 answer.setVisible(falsefalse is a value for the boolean type and means not true);
085 canvas.addSprite(answer);
086
087 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");
088 win.setLocation(.5, .3);
089 win.setSize(.25);
090
091 fail=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Failed");
092 fail.setLocation(.5, .3);
093 fail.setSize(.25);
094 }close braces end code blocks and must match an earlier open brace
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprite()
096 {open braces start code blocks and must be matched with a close brace
097 canvas.addSprite(door1);
098 canvas.addSprite(door2);
099 canvas.addSprite(door3);
100 canvas.addSprite(num1);
101 canvas.addSprite(num2);
102 canvas.addSprite(num3);
103 }close braces end code blocks and must match an earlier open brace
104 /**handle input and game events*/
105 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
106 {open braces start code blocks and must be matched with a close brace
107 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)
108 {open braces start code blocks and must be matched with a close brace
109 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
110 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 &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 &&) clickcount ==this is the comparison operator which evaluates to true if both sides are the same 0)
111 {open braces start code blocks and must be matched with a close brace
112 ifif executes the next statement only if the condition in parenthesis evaluates to true (door1.intersects(click))
113 {open braces start code blocks and must be matched with a close brace
114 clickcount=this assignment operator makes the left side equal to the right side1;
115 q=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
116 doorpicked=this assignment operator makes the left side equal to the right side1;
117 ifif executes the next statement only if the condition in parenthesis evaluates to true(q==this is the comparison operator which evaluates to true if both sides are the same0)
118 {open braces start code blocks and must be matched with a close brace
119 loser1.setLocation(door2.getLocation());
120 canvas.removeSprite(door2);
121 addSprite(loser1);
122 open=this assignment operator makes the left side equal to the right side2;
123 notopen=this assignment operator makes the left side equal to the right side3;
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(q==this is the comparison operator which evaluates to true if both sides are the same1)
126 {open braces start code blocks and must be matched with a close brace
127 loser1.setLocation(door3.getLocation());
128 canvas.removeSprite(door3);
129 addSprite(loser1);
130 open=this assignment operator makes the left side equal to the right side3;
131 notopen=this assignment operator makes the left side equal to the right side2;
132 }close braces end code blocks and must match an earlier open brace
133 answer.setVisible(truetrue is the boolean value that is the opposite of false);
134 header.setVisible(falsefalse is a value for the boolean type and means not true);
135 stage=this assignment operator makes the left side equal to the right side1;
136 }close braces end code blocks and must match an earlier open brace
137 ifif executes the next statement only if the condition in parenthesis evaluates to true (door2.intersects(click))
138 {open braces start code blocks and must be matched with a close brace
139 clickcount=this assignment operator makes the left side equal to the right side1;
140 w=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
141 doorpicked=this assignment operator makes the left side equal to the right side2;
142 ifif executes the next statement only if the condition in parenthesis evaluates to true(w==this is the comparison operator which evaluates to true if both sides are the same0)
143 {open braces start code blocks and must be matched with a close brace
144 loser1.setLocation(door1.getLocation());
145 canvas.removeSprite(door1);
146 addSprite(loser1);
147 open=this assignment operator makes the left side equal to the right side1;
148 notopen=this assignment operator makes the left side equal to the right side3;
149 }close braces end code blocks and must match an earlier open brace
150 ifif executes the next statement only if the condition in parenthesis evaluates to true(w==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 loser1.setLocation(door3.getLocation());
153 canvas.removeSprite(door3);
154 addSprite(loser1);
155 open=this assignment operator makes the left side equal to the right side3;
156 notopen=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 answer.setVisible(truetrue is the boolean value that is the opposite of false);
159 header.setVisible(falsefalse is a value for the boolean type and means not true);
160 stage=this assignment operator makes the left side equal to the right side1;
161 }close braces end code blocks and must match an earlier open brace
162 ifif executes the next statement only if the condition in parenthesis evaluates to true (door3.intersects(click))
163 {open braces start code blocks and must be matched with a close brace
164 clickcount=this assignment operator makes the left side equal to the right side1;
165 e=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
166 doorpicked=this assignment operator makes the left side equal to the right side3;
167 ifif executes the next statement only if the condition in parenthesis evaluates to true(e==this is the comparison operator which evaluates to true if both sides are the same0)
168 {open braces start code blocks and must be matched with a close brace
169 loser1.setLocation(door1.getLocation());
170 canvas.removeSprite(door1);
171 addSprite(loser1);
172 open=this assignment operator makes the left side equal to the right side1;
173 notopen=this assignment operator makes the left side equal to the right side2;
174 }close braces end code blocks and must match an earlier open brace
175 ifif executes the next statement only if the condition in parenthesis evaluates to true(e==this is the comparison operator which evaluates to true if both sides are the same1)
176 {open braces start code blocks and must be matched with a close brace
177 loser1.setLocation(door2.getLocation());
178 canvas.removeSprite(door2);
179 addSprite(loser1);
180 open=this assignment operator makes the left side equal to the right side2;
181 notopen=this assignment operator makes the left side equal to the right side1;
182 }close braces end code blocks and must match an earlier open brace
183 answer.setVisible(truetrue is the boolean value that is the opposite of false);
184 header.setVisible(falsefalse is a value for the boolean type and means not true);
185 stage=this assignment operator makes the left side equal to the right side1;
186 }close braces end code blocks and must match an earlier open brace
187 }close braces end code blocks and must match an earlier open brace
188 }close braces end code blocks and must match an earlier open brace
189 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)
190 {open braces start code blocks and must be matched with a close brace
191 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
192 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 &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 &&) clickcount ==this is the comparison operator which evaluates to true if both sides are the same 1)
193 {open braces start code blocks and must be matched with a close brace
194 r=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
195 clickcount=this assignment operator makes the left side equal to the right side2;
196 ifif executes the next statement only if the condition in parenthesis evaluates to true(door1.intersects(click) &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 &&) open ==this is the comparison operator which evaluates to true if both sides are the same 2)
197 {open braces start code blocks and must be matched with a close brace
198 ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same0)
199 {open braces start code blocks and must be matched with a close brace
200 winner.setLocation(door1.getLocation());
201 loser2.setLocation(door3.getLocation());
202 canvas.addSprite(win);
203 }close braces end code blocks and must match an earlier open brace
204 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same1)
205 {open braces start code blocks and must be matched with a close brace
206 loser2.setLocation(door1.getLocation());
207 winner.setLocation(door3.getLocation());
208 canvas.addSprite(fail);
209 }close braces end code blocks and must match an earlier open brace
210 canvas.removeSprite(door1);
211 canvas.removeSprite(door2);
212 canvas.removeSprite(door3);
213 addSprite(loser2);
214 addSprite(winner);
215 }close braces end code blocks and must match an earlier open brace
216 ifif executes the next statement only if the condition in parenthesis evaluates to true(door1.intersects(click) &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 &&) open==this is the comparison operator which evaluates to true if both sides are the same3)
217 {open braces start code blocks and must be matched with a close brace
218 ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same0)
219 {open braces start code blocks and must be matched with a close brace
220 winner.setLocation(door1.getLocation());
221 loser2.setLocation(door2.getLocation());
222 canvas.addSprite(win);
223 }close braces end code blocks and must match an earlier open brace
224 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same1)
225 {open braces start code blocks and must be matched with a close brace
226 loser2.setLocation(door1.getLocation());
227 winner.setLocation(door2.getLocation());
228 canvas.addSprite(fail);
229 }close braces end code blocks and must match an earlier open brace
230 canvas.removeSprite(door1);
231 canvas.removeSprite(door2);
232 canvas.removeSprite(door3);
233 addSprite(loser2);
234 addSprite(winner);
235 }close braces end code blocks and must match an earlier open brace
236 ifif executes the next statement only if the condition in parenthesis evaluates to true(door2.intersects(click) &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 &&) open==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 ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same0)
239 {open braces start code blocks and must be matched with a close brace
240 winner.setLocation(door2.getLocation());
241 loser2.setLocation(door1.getLocation());
242 canvas.addSprite(win);
243 }close braces end code blocks and must match an earlier open brace
244 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same1)
245 {open braces start code blocks and must be matched with a close brace
246 loser2.setLocation(door2.getLocation());
247 winner.setLocation(door1.getLocation());
248 canvas.addSprite(fail);
249 }close braces end code blocks and must match an earlier open brace
250 canvas.removeSprite(door1);
251 canvas.removeSprite(door2);
252 canvas.removeSprite(door3);
253 addSprite(loser2);
254 addSprite(winner);
255 }close braces end code blocks and must match an earlier open brace
256 ifif executes the next statement only if the condition in parenthesis evaluates to true(door2.intersects(click) &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 &&) open==this is the comparison operator which evaluates to true if both sides are the same3)
257 {open braces start code blocks and must be matched with a close brace
258 ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same0)
259 {open braces start code blocks and must be matched with a close brace
260 winner.setLocation(door2.getLocation());
261 loser2.setLocation(door3.getLocation());
262 canvas.addSprite(win);
263 }close braces end code blocks and must match an earlier open brace
264 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same1)
265 {open braces start code blocks and must be matched with a close brace
266 loser2.setLocation(door2.getLocation());
267 winner.setLocation(door3.getLocation());
268 canvas.addSprite(fail);
269 }close braces end code blocks and must match an earlier open brace
270 canvas.removeSprite(door1);
271 canvas.removeSprite(door2);
272 canvas.removeSprite(door3);
273 addSprite(loser2);
274 addSprite(winner);
275 }close braces end code blocks and must match an earlier open brace
276 ifif executes the next statement only if the condition in parenthesis evaluates to true(door3.intersects(click) &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 &&) open==this is the comparison operator which evaluates to true if both sides are the same1)
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(r==this is the comparison operator which evaluates to true if both sides are the same0)
279 {open braces start code blocks and must be matched with a close brace
280 winner.setLocation(door3.getLocation());
281 loser2.setLocation(door1.getLocation());
282 canvas.addSprite(win);
283 }close braces end code blocks and must match an earlier open brace
284 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same1)
285 {open braces start code blocks and must be matched with a close brace
286 loser2.setLocation(door3.getLocation());
287 winner.setLocation(door1.getLocation());
288 canvas.addSprite(fail);
289 }close braces end code blocks and must match an earlier open brace
290 canvas.removeSprite(door1);
291 canvas.removeSprite(door2);
292 canvas.removeSprite(door3);
293 addSprite(loser2);
294 addSprite(winner);
295 }close braces end code blocks and must match an earlier open brace
296 ifif executes the next statement only if the condition in parenthesis evaluates to true(door3.intersects(click) &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 &&) open==this is the comparison operator which evaluates to true if both sides are the same2)
297 {open braces start code blocks and must be matched with a close brace
298 ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same0)
299 {open braces start code blocks and must be matched with a close brace
300 winner.setLocation(door3.getLocation());
301 loser2.setLocation(door2.getLocation());
302 canvas.addSprite(win);
303 }close braces end code blocks and must match an earlier open brace
304 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(r==this is the comparison operator which evaluates to true if both sides are the same1)
305 {open braces start code blocks and must be matched with a close brace
306 loser2.setLocation(door3.getLocation());
307 winner.setLocation(door2.getLocation());
308 canvas.addSprite(fail);
309 }close braces end code blocks and must match an earlier open brace
310 canvas.removeSprite(door1);
311 canvas.removeSprite(door2);
312 canvas.removeSprite(door3);
313 addSprite(loser2);
314 addSprite(winner);
315 }close braces end code blocks and must match an earlier open brace
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 }close braces end code blocks and must match an earlier open brace
319 }close braces end code blocks and must match an earlier open brace
|