|
001 packagepackage is used to name the directory or folder a class is in Kirby;
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 * Lets Make a Deal Game
010 * author Travis Kirby
011 */
012
013 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 LetsMakeADeal2 extendsextends means to customize or extend the functionality of a class GameLoop
014
015 {open braces start code blocks and must be matched with a close brace
016 privateprivate is used to restrict access to the current class only Sprite Door1, Door2, Door3;
017 privateprivate is used to restrict access to the current class only ImageSprite prize, loss1, loss2;
018 privateprivate is used to restrict access to the current class only StringSprite instruction, instruction1, instruction2, title, win, lose;
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 location, stage, choice, x, y;
020
021 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
022 {open braces start code blocks and must be matched with a close brace
023 stage=this assignment operator makes the left side equal to the right side0;
024 pauseToggle();
025 makeSprites();
026 addSprites();
027 {open braces start code blocks and must be matched with a close brace
028 y=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
029 x=this assignment operator makes the left side equal to the right siderandom.nextInt(3);
030 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)
031 {open braces start code blocks and must be matched with a close brace
032 location=this assignment operator makes the left side equal to the right side3;
033 prize.setLocation(0.85, 0.5);
034 loss1.setLocation(0.15, 0.5);
035 loss2.setLocation(0.5, 0.5);
036 }close braces end code blocks and must match an earlier open brace
037 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)
038 {open braces start code blocks and must be matched with a close brace
039 location=this assignment operator makes the left side equal to the right side1;
040 prize.setLocation(0.15, 0.5);
041 loss1.setLocation(0.85, 0.5);
042 loss2.setLocation(0.5, 0.5);
043 }close braces end code blocks and must match an earlier open brace
044 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)
045 {open braces start code blocks and must be matched with a close brace
046 location=this assignment operator makes the left side equal to the right side2;
047 prize.setLocation(0.5, 0.5);
048 loss1.setLocation(0.15, 0.5);
049 loss2.setLocation(0.85, 0.5);
050 }close braces end code blocks and must match an earlier open brace
051 }close braces end code blocks and must match an earlier open brace
052 }close braces end code blocks and must match an earlier open brace
053 /**Makes sprites*/
054 /**Images from Microsoft Word 2007 Clip Art*/
055 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeSprites()
056 {open braces start code blocks and must be matched with a close brace
057 Door1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Doord.gif"));
058 Door1.setLocation(.15, 0.5);
059 Door1.setScale(.33);
060
061 Door2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Doore.gif"));
062 Door2.setLocation(.5, 0.5);
063 Door2.setScale(.33);
064
065 Door3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Doorf.gif"));
066 Door3.setLocation(.85, 0.5);
067 Door3.setScale(.33);
068
069 prize=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite (Wiki.getMedia("Win2.gif"));
070 prize.setScale(.2);
071
072 loss1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite (Wiki.getMedia("Lose2.gif"));
073 loss1.setScale(.3);
074
075 loss2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite (Wiki.getMedia("Lose2.gif"));
076 loss2.setScale(.3);
077
078 title=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Let's Make A Deal");
079 title.setLocation(.5, .1);
080 title.setColor(Color.WHITE);
081 title.setScale(.8);
082
083 instruction=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Pick a door.");
084 instruction.setLocation(.5, .80);
085 instruction.setColor(Color.BLUE);
086 instruction.setScale(.4);
087
088 instruction1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Click the same door or switch.");
089 instruction1.setLocation(.5, .80);
090 instruction1.setColor(Color.RED);
091 instruction1.setScale(.85);
092
093 instruction2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Refresh page to play again.");
094 instruction2.setLocation(.5, .93);
095 instruction2.setColor(Color.RED);
096 instruction2.setScale(.4);
097
098 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("You won!");
099 win.setLocation(.5, .80);
100 win.setColor(Color.GREEN);
101 win.setScale(.85);
102
103 lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("You lost...");
104 lose.setLocation(.5, .78);
105 lose.setColor(Color.GREEN);
106 lose.setScale(.85);
107 }close braces end code blocks and must match an earlier open brace
108 /**Adds first sprites*/
109 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addSprites()
110 {open braces start code blocks and must be matched with a close brace
111 canvas.addSprite(prize);
112 canvas.addSprite(loss1);
113 canvas.addSprite(loss2);
114 canvas.addSprite(Door2);
115 canvas.addSprite(Door1);
116 canvas.addSprite(Door3);
117 canvas.addSprite(title);
118 canvas.addSprite(instruction);
119 }close braces end code blocks and must match an earlier open brace
120 /**First click is Door 1*/
121 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Door1Clicked()
122 {open braces start code blocks and must be matched with a close brace
123 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
124 ifif executes the next statement only if the condition in parenthesis evaluates to true(Door1.intersects(click))
125 {open braces start code blocks and must be matched with a close brace
126 choice=this assignment operator makes the left side equal to the right side1;
127
128 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same3)
129 {open braces start code blocks and must be matched with a close brace
130 canvas.removeSprite(Door2);
131 }close braces end code blocks and must match an earlier open brace
132 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same1)
133 {open braces start code blocks and must be matched with a close brace
134 ifif executes the next statement only if the condition in parenthesis evaluates to true (y==this is the comparison operator which evaluates to true if both sides are the same0)
135 canvas.removeSprite(Door3);
136 elseelse is what happens when the if condition is false
137 canvas.removeSprite(Door2);
138 }close braces end code blocks and must match an earlier open brace
139 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same2)
140 {open braces start code blocks and must be matched with a close brace
141 canvas.removeSprite(Door3);
142 }close braces end code blocks and must match an earlier open brace
143 }close braces end code blocks and must match an earlier open brace
144 }close braces end code blocks and must match an earlier open brace
145 /**First click is Door 2*/
146 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Door2Clicked()
147 {open braces start code blocks and must be matched with a close brace
148 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
149 ifif executes the next statement only if the condition in parenthesis evaluates to true(Door2.intersects(click))
150 {open braces start code blocks and must be matched with a close brace
151 choice=this assignment operator makes the left side equal to the right side2;
152 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same3)
153 {open braces start code blocks and must be matched with a close brace
154 canvas.removeSprite(Door1);
155 }close braces end code blocks and must match an earlier open brace
156 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same1)
157 {open braces start code blocks and must be matched with a close brace
158 canvas.removeSprite(Door3);
159 }close braces end code blocks and must match an earlier open brace
160 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same2)
161 {open braces start code blocks and must be matched with a close brace
162 ifif executes the next statement only if the condition in parenthesis evaluates to true (y==this is the comparison operator which evaluates to true if both sides are the same0)
163 canvas.removeSprite(Door3);
164 elseelse is what happens when the if condition is false
165 canvas.removeSprite(Door1);
166 }close braces end code blocks and must match an earlier open brace
167 }close braces end code blocks and must match an earlier open brace
168 }close braces end code blocks and must match an earlier open brace
169 /**First click is Door 3*/
170 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Door3Clicked()
171 {open braces start code blocks and must be matched with a close brace
172 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
173 ifif executes the next statement only if the condition in parenthesis evaluates to true(Door3.intersects(click))
174 {open braces start code blocks and must be matched with a close brace
175 choice=this assignment operator makes the left side equal to the right side3;
176 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same3)
177 {open braces start code blocks and must be matched with a close brace
178 ifif executes the next statement only if the condition in parenthesis evaluates to true (y==this is the comparison operator which evaluates to true if both sides are the same0)
179 canvas.removeSprite(Door2);
180 elseelse is what happens when the if condition is false
181 canvas.removeSprite(Door1);
182 }close braces end code blocks and must match an earlier open brace
183 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same1)
184 {open braces start code blocks and must be matched with a close brace
185 canvas.removeSprite(Door2);
186 }close braces end code blocks and must match an earlier open brace
187 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same2)
188 {open braces start code blocks and must be matched with a close brace
189 canvas.removeSprite(Door1);
190 }close braces end code blocks and must match an earlier open brace
191 }close braces end code blocks and must match an earlier open brace
192 }close braces end code blocks and must match an earlier open brace
193
194 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)
195 {open braces start code blocks and must be matched with a close brace
196 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
197 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)
198 {open braces start code blocks and must be matched with a close brace
199 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)
200 {open braces start code blocks and must be matched with a close brace
201 stage=this assignment operator makes the left side equal to the right side1;
202 canvas.removeSprite(instruction);
203 canvas.addSprite(instruction1);
204 Door1Clicked();
205 Door2Clicked();
206 Door3Clicked();
207 }close braces end code blocks and must match an earlier open brace
208 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)
209 {open braces start code blocks and must be matched with a close brace
210 canvas.removeSprite(instruction1);
211 ifif executes the next statement only if the condition in parenthesis evaluates to true(Door1.intersects(click))
212 {open braces start code blocks and must be matched with a close brace
213 choice=this assignment operator makes the left side equal to the right side1;
214 }close braces end code blocks and must match an earlier open brace
215 ifif executes the next statement only if the condition in parenthesis evaluates to true(Door2.intersects(click))
216 {open braces start code blocks and must be matched with a close brace
217 choice=this assignment operator makes the left side equal to the right side2;
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(Door3.intersects(click))
220 {open braces start code blocks and must be matched with a close brace
221 choice=this assignment operator makes the left side equal to the right side3;
222 }close braces end code blocks and must match an earlier open brace
223 ifif executes the next statement only if the condition in parenthesis evaluates to true (choice==this is the comparison operator which evaluates to true if both sides are the same1)
224 {open braces start code blocks and must be matched with a close brace
225 canvas.removeSprite(Door1, Door2, Door3);
226 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same1)
227 {open braces start code blocks and must be matched with a close brace
228 canvas.addSprite(win);
229 canvas.addSprite(instruction2);
230 }close braces end code blocks and must match an earlier open brace
231 elseelse is what happens when the if condition is false
232 {open braces start code blocks and must be matched with a close brace
233 canvas.addSprite(lose);
234 canvas.addSprite(instruction2);
235 }close braces end code blocks and must match an earlier open brace
236 }close braces end code blocks and must match an earlier open brace
237
238 ifif executes the next statement only if the condition in parenthesis evaluates to true (choice==this is the comparison operator which evaluates to true if both sides are the same2)
239 {open braces start code blocks and must be matched with a close brace
240 canvas.removeSprite(Door1, Door2, Door3);
241 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same2)
242 {open braces start code blocks and must be matched with a close brace
243 canvas.addSprite(win);
244 canvas.addSprite(instruction2);
245 }close braces end code blocks and must match an earlier open brace
246 elseelse is what happens when the if condition is false
247 {open braces start code blocks and must be matched with a close brace
248 canvas.addSprite(lose);
249 canvas.addSprite(instruction2);
250 }close braces end code blocks and must match an earlier open brace
251
252 }close braces end code blocks and must match an earlier open brace
253
254 ifif executes the next statement only if the condition in parenthesis evaluates to true (choice==this is the comparison operator which evaluates to true if both sides are the same3)
255 {open braces start code blocks and must be matched with a close brace
256 canvas.removeSprite(Door1, Door2, Door3);
257 ifif executes the next statement only if the condition in parenthesis evaluates to true (location==this is the comparison operator which evaluates to true if both sides are the same3)
258 {open braces start code blocks and must be matched with a close brace
259 canvas.addSprite(win);
260 canvas.addSprite(instruction2);
261 }close braces end code blocks and must match an earlier open brace
262 elseelse is what happens when the if condition is false
263 {open braces start code blocks and must be matched with a close brace
264 canvas.addSprite(lose);
265 canvas.addSprite(instruction2);
266 }close braces end code blocks and must match an earlier open brace
267 }close braces end code blocks and must match an earlier open brace
268
269 }close braces end code blocks and must match an earlier open brace
270 }close braces end code blocks and must match an earlier open brace
271 }close braces end code blocks and must match an earlier open brace
272 }close braces end code blocks and must match an earlier open brace
273
|