|
001 packagepackage is used to name the directory or folder a class is in cray;
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 java.util.*;
005 importimport means to make the classes and/or packages available in this program fang.*;
006 importimport means to make the classes and/or packages available in this program java.awt.*;
007 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
008 importimport means to make the classes and/or packages available in this program jam.Door;
009
010 /**
011 * All about my game here.
012 * @authorthis is the Javadoc tag for documenting who created the source code Cray
013 */
014 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Deal extendsextends means to customize or extend the functionality of a class GameLoop
015
016
017 {open braces start code blocks and must be matched with a close brace
018 privateprivate is used to restrict access to the current class only StringSprite door1Num;
019 privateprivate is used to restrict access to the current class only StringSprite door2Num;
020 privateprivate is used to restrict access to the current class only StringSprite door3Num;
021 privateprivate is used to restrict access to the current class only StringSprite askDoor1;
022 privateprivate is used to restrict access to the current class only StringSprite askDoor2;
023 privateprivate is used to restrict access to the current class only StringSprite win;
024 privateprivate is used to restrict access to the current class only StringSprite lose;
025 privateprivate is used to restrict access to the current class only ImageSprite door1Closed;
026 privateprivate is used to restrict access to the current class only ImageSprite door2Closed;
027 privateprivate is used to restrict access to the current class only ImageSprite door3Closed;
028 privateprivate is used to restrict access to the current class only ImageSprite dot1;
029 privateprivate is used to restrict access to the current class only ImageSprite dot2;
030 privateprivate is used to restrict access to the current class only ImageSprite dot3;
031 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer winningDoor;
032 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer chosen=this assignment operator makes the left side equal to the right side0;
033 privateprivate is used to restrict access to the current class only Door door1;
034 privateprivate is used to restrict access to the current class only Door door2;
035 privateprivate is used to restrict access to the current class only Door door3;
036 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer clicked=this assignment operator makes the left side equal to the right side0;
037 privateprivate is used to restrict access to the current class only Sound clip=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Kidscheer.wav");
038 privateprivate is used to restrict access to the current class only Sound clip2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Laugher.wav");
039
040
041
042
043 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
044 {open braces start code blocks and must be matched with a close brace
045 makeSprites();
046 addSprites();
047
048 }close braces end code blocks and must match an earlier open brace
049 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
050 {open braces start code blocks and must be matched with a close brace
051 intint is the type for whole numbers and it is short for integer x=this assignment operator makes the left side equal to the right siderandom.nextInt(3)+adds two numbers together or concatenates Strings together1;
052
053
054 door1Num=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("1");
055 door1Num.setHeight(0.1);
056 door1Num.leftJustify();
057 door1Num.topJustify();
058 door1Num.setLocation(0.13, 0.5);
059 //door1Num.setScale(.5);
060 door1Num.setColor(Color.YELLOW);
061
062 door2Num=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("2");
063 door2Num.setHeight(0.1);
064 door2Num.leftJustify();
065 door2Num.topJustify();
066 door2Num.setLocation(0.47, 0.5);
067 //door2Num.setScale(.5);
068 door2Num.setColor(Color.YELLOW);
069
070 door3Num=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("3");
071 door3Num.setHeight(0.1);
072 door3Num.leftJustify();
073 door3Num.topJustify();
074 door3Num.setLocation(0.8, 0.5);
075 //door3Num.setScale(.5);
076 door3Num.setColor(Color.YELLOW);
077
078 door1Closed=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("crayDoor.jpg");
079 door1Closed.setLocation(0.15,0.54);
080 door1Closed.setScale(0.5);
081 door1Closed.setColor(Color.RED);
082
083 door2Closed=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("crayDoor.jpg");
084 door2Closed.setLocation(0.5,0.54);
085 door2Closed.setScale(0.5);
086 door2Closed.setColor(Color.RED);
087
088 door3Closed=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("crayDoor.jpg");
089 door3Closed.setLocation(0.83,0.54);
090 door3Closed.setScale(0.5);
091 door3Closed.setColor(Color.RED);
092
093 dot1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Redx2.jpg");
094 dot1.setLocation(0.13,0.54);
095 dot1.setScale(0.1);
096 dot1.setColor(Color.RED);
097
098 dot2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Redx2.jpg");
099 dot2.setLocation(0.47,0.54);
100 dot2.setScale(0.1);
101 dot2.setColor(Color.RED);
102
103 dot3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Redx2.jpg");
104 dot3.setLocation(0.83,0.54);
105 dot3.setScale(0.1);
106 dot3.setColor(Color.RED);
107
108 askDoor1=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 by clicking on it.");
109 askDoor1.setHeight(0.05);
110 askDoor1.leftJustify();
111 askDoor1.topJustify();
112 askDoor1.setLocation(0.1, 0.1);
113 askDoor1.setColor(Color.WHITE);
114
115 askDoor2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click on the same door or the other door.");
116 askDoor2.setHeight(0.04);
117 askDoor2.leftJustify();
118 askDoor2.topJustify();
119 askDoor2.setLocation(0.1, 0.1);
120 askDoor2.setColor(Color.WHITE);
121
122 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("WINNER!");
123 win.setHeight(0.2);
124 win.leftJustify();
125 win.topJustify();
126 win.setLocation(0.1, 0.2);
127 win.setColor(Color.BLUE);
128
129 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!");
130 lose.setHeight(0.15);
131 lose.leftJustify();
132 lose.topJustify();
133 lose.setLocation(0.07, 0.2);
134 lose.setColor(Color.ORANGE);
135
136
137
138
139 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)
140 {open braces start code blocks and must be matched with a close brace
141 dot1.setColor(Color.GREEN);
142 dot1.setImage("Stacks_of_money.jpg");
143 dot1.setScale(0.15);
144 door1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(truetrue is the boolean value that is the opposite of false,falsefalse is a value for the boolean type and means not true,1);
145 door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(falsefalse is a value for the boolean type and means not true, falsefalse is a value for the boolean type and means not true, 2);
146 door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(falsefalse is a value for the boolean type and means not true, falsefalse is a value for the boolean type and means not true, 3);
147 }close braces end code blocks and must match an earlier open brace
148 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 same2)
149 {open braces start code blocks and must be matched with a close brace
150 dot2.setColor(Color.GREEN);
151 dot2.setImage("Stacks_of_money.jpg");
152 dot2.setScale(0.15);
153 door1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(falsefalse is a value for the boolean type and means not true,falsefalse is a value for the boolean type and means not true,1);
154 door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(truetrue is the boolean value that is the opposite of false, falsefalse is a value for the boolean type and means not true, 2);
155 door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(falsefalse is a value for the boolean type and means not true, falsefalse is a value for the boolean type and means not true, 3);
156 }close braces end code blocks and must match an earlier open brace
157 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 same3)
158 {open braces start code blocks and must be matched with a close brace
159 dot3.setColor(Color.GREEN);
160 dot3.setImage("Stacks_of_money.jpg");
161 dot3.setScale(0.15);
162 door1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(falsefalse is a value for the boolean type and means not true,falsefalse is a value for the boolean type and means not true,1);
163 door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(falsefalse is a value for the boolean type and means not true, falsefalse is a value for the boolean type and means not true, 2);
164 door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Door(truetrue is the boolean value that is the opposite of false, falsefalse is a value for the boolean type and means not true, 3);
165 }close braces end code blocks and must match an earlier open brace
166 }close braces end code blocks and must match an earlier open brace
167 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
168 {open braces start code blocks and must be matched with a close brace
169 canvas.addSprite(dot1);
170 canvas.addSprite(dot2);
171 canvas.addSprite(dot3);
172 canvas.addSprite(door1Closed);
173 canvas.addSprite(door2Closed);
174 canvas.addSprite(door3Closed);
175 canvas.addSprite(door1Num);
176 canvas.addSprite(door2Num);
177 canvas.addSprite(door3Num);
178 canvas.addSprite(askDoor1);
179
180
181 }close braces end code blocks and must match an earlier open brace
182 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)
183 {open braces start code blocks and must be matched with a close brace
184
185 intint is the type for whole numbers and it is short for integer x=this assignment operator makes the left side equal to the right siderandom.nextInt(2)+adds two numbers together or concatenates Strings together1;
186
187 ifif executes the next statement only if the condition in parenthesis evaluates to true(chosen!=this is the not equals operator which evaluates to true if both sides are different4 &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 &&) chosen!=this is the not equals operator which evaluates to true if both sides are different5)
188 {open braces start code blocks and must be matched with a close brace
189 Point2D.Double leftClick=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLeftClickLocation();
190
191 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door1Closed.intersects(leftClick))
192 {open braces start code blocks and must be matched with a close brace
193 chosen=this assignment operator makes the left side equal to the right side1;
194 }close braces end code blocks and must match an earlier open brace
195 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door2Closed.intersects(leftClick))
196 {open braces start code blocks and must be matched with a close brace
197 chosen=this assignment operator makes the left side equal to the right side2;
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(leftClick!=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 &&) door3Closed.intersects(leftClick))
200 {open braces start code blocks and must be matched with a close brace
201 chosen=this assignment operator makes the left side equal to the right side3;
202 }close braces end code blocks and must match an earlier open brace
203 }close braces end code blocks and must match an earlier open brace
204 ifif executes the next statement only if the condition in parenthesis evaluates to true( chosen>0 &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 &&) chosen!=this is the not equals operator which evaluates to true if both sides are different4 &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 &&) chosen!=this is the not equals operator which evaluates to true if both sides are different5)
205 {open braces start code blocks and must be matched with a close brace
206 ifif executes the next statement only if the condition in parenthesis evaluates to true(door1.canOpenFirst(chosen)==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
207 {open braces start code blocks and must be matched with a close brace
208 canvas.removeSprite(door1Num, askDoor1);
209 door1.open();
210 canvas.removeSprite(door1Closed);
211 canvas.addSprite(askDoor2);
212
213 }close braces end code blocks and must match an earlier open brace
214 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(door2.canOpenFirst(chosen)==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
215 {open braces start code blocks and must be matched with a close brace
216 canvas.removeSprite(door2Num, askDoor1);
217 canvas.removeSprite(door2Closed);
218 door2.open();
219 canvas.addSprite(askDoor2);
220 }close braces end code blocks and must match an earlier open brace
221 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(door3.canOpenFirst(chosen)==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
222 {open braces start code blocks and must be matched with a close brace
223 canvas.removeSprite(door3Num, askDoor1);
224 canvas.removeSprite(door3Closed);
225 door3.open();
226 canvas.addSprite(askDoor2);
227 }close braces end code blocks and must match an earlier open brace
228 chosen=this assignment operator makes the left side equal to the right side4;
229 }close braces end code blocks and must match an earlier open brace
230 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(chosen==this is the comparison operator which evaluates to true if both sides are the same4)
231 {open braces start code blocks and must be matched with a close brace
232
233 Point2D.Double leftClick=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLeftClickLocation();
234
235 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door1Closed.intersects(leftClick) &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 &&) door1.isOpen()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true &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 &&) door1.isPrize()==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
236 {open braces start code blocks and must be matched with a close brace
237 canvas.removeSprite(door1Num, door1Closed);
238 canvas.removeSprite(door2Num, door2Closed);
239 canvas.removeSprite(door3Num, door3Closed);
240 canvas.removeSprite(askDoor2);
241 canvas.addSprite(win);
242 clip.play();
243 chosen=this assignment operator makes the left side equal to the right side5;
244 }close braces end code blocks and must match an earlier open brace
245
246 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door1Closed.intersects(leftClick) &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 &&) door1.isOpen()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true &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 &&) door1.isPrize()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
247 {open braces start code blocks and must be matched with a close brace
248 canvas.removeSprite(door1Num, door1Closed);
249 canvas.removeSprite(door2Num, door2Closed);
250 canvas.removeSprite(door3Num, door3Closed);
251 canvas.removeSprite(askDoor2);
252 canvas.addSprite(lose);
253 clip2.play();
254 chosen=this assignment operator makes the left side equal to the right side5;
255 }close braces end code blocks and must match an earlier open brace
256
257 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door2Closed.intersects(leftClick) &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 &&) door2.isOpen()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true &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 &&) door2.isPrize()==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
258 {open braces start code blocks and must be matched with a close brace
259 canvas.removeSprite(door2Num, door2Closed);
260 canvas.removeSprite(door1Num, door1Closed);
261 canvas.removeSprite(door3Num, door3Closed);
262 canvas.removeSprite(askDoor2);
263 canvas.addSprite(win);
264 clip.play();
265 chosen=this assignment operator makes the left side equal to the right side5;
266 }close braces end code blocks and must match an earlier open brace
267
268 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door2Closed.intersects(leftClick) &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 &&) door2.isOpen()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true &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 &&) door2.isPrize()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
269 {open braces start code blocks and must be matched with a close brace
270 canvas.removeSprite(door2Num, door2Closed);
271 canvas.removeSprite(door1Num, door1Closed);
272 canvas.removeSprite(door3Num, door3Closed);
273 canvas.removeSprite(askDoor2);
274 canvas.addSprite(lose);
275 clip2.play();
276 chosen=this assignment operator makes the left side equal to the right side5;
277
278 }close braces end code blocks and must match an earlier open brace
279
280
281 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door3Closed.intersects(leftClick) &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 &&) door3.isOpen()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true &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 &&) door3.isPrize()==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
282 {open braces start code blocks and must be matched with a close brace
283 canvas.removeSprite(door3Num, door3Closed);
284 canvas.removeSprite(door1Num, door1Closed);
285 canvas.removeSprite(door2Num, door2Closed);
286 canvas.removeSprite(askDoor2);
287 canvas.addSprite(win);
288 clip.play();
289 chosen=this assignment operator makes the left side equal to the right side5;
290 }close braces end code blocks and must match an earlier open brace
291
292 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(leftClick!=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 &&) door3Closed.intersects(leftClick) &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 &&) door3.isOpen()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true &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 &&) door3.isPrize()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
293 {open braces start code blocks and must be matched with a close brace
294 canvas.removeSprite(door3Num, door3Closed);
295 canvas.removeSprite(door1Num, door1Closed);
296 canvas.removeSprite(door2Num, door2Closed);
297 canvas.removeSprite(askDoor2);
298 canvas.addSprite(lose);
299 clip2.play();
300 chosen=this assignment operator makes the left side equal to the right side5;
301 }close braces end code blocks and must match an earlier open brace
302
303 }close braces end code blocks and must match an earlier open brace
304 ifif executes the next statement only if the condition in parenthesis evaluates to true(chosen==this is the comparison operator which evaluates to true if both sides are the same5)
305 {open braces start code blocks and must be matched with a close brace
306 canvas.removeSprite(askDoor2);
307
308 }close braces end code blocks and must match an earlier open brace
309 }close braces end code blocks and must match an earlier open brace
310 }close braces end code blocks and must match an earlier open brace
311
312
313
|