|
001 packagepackage is used to name the directory or folder a class is in GBell;
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 * Based on Lets Make a Deal, with assistance from Jacob Olsen and Dr. Jenkins.
010 * @authornull Geremy Bell
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 DoorGame 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 Sprite left, middle, right;
015 privateprivate is used to restrict access to the current class only ImageSprite prize, junk1, junk2;
016 privateprivate is used to restrict access to the current class only StringSprite instruction, instruction1, title, win, lose;
017 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;
018 /**This audio file listed as freeware at http://www.thepcmanwebsite.com/pcman.shtml*/
019 privateprivate is used to restrict access to the current class only Sound sound0=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Opening.wav"));
020 privateprivate is used to restrict access to the current class only Sound sound1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Beep2.wav"));
021
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
023 {open braces start code blocks and must be matched with a close brace
024 stage=this assignment operator makes the left side equal to the right side0;
025 toggleAudible();
026 sound0.play();
027 pauseToggle();
028 makeSprites();
029 addSprites();
030 {open braces start code blocks and must be matched with a close brace
031 y=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
032 x=this assignment operator makes the left side equal to the right siderandom.nextInt(3);
033 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)
034 {open braces start code blocks and must be matched with a close brace
035 location=this assignment operator makes the left side equal to the right side3;
036 prize.setLocation(0.85, 0.4);
037 junk1.setLocation(0.15, 0.4);
038 junk2.setLocation(0.5, 0.4);
039 }close braces end code blocks and must match an earlier open brace
040 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)
041 {open braces start code blocks and must be matched with a close brace
042 location=this assignment operator makes the left side equal to the right side1;
043 prize.setLocation(0.15, 0.4);
044 junk1.setLocation(0.85, 0.4);
045 junk2.setLocation(0.5, 0.4);
046 }close braces end code blocks and must match an earlier open brace
047 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)
048 {open braces start code blocks and must be matched with a close brace
049 location=this assignment operator makes the left side equal to the right side2;
050 prize.setLocation(0.5, 0.4);
051 junk1.setLocation(0.15, 0.4);
052 junk2.setLocation(0.85, 0.4);
053 }close braces end code blocks and must match an earlier open brace
054 }close braces end code blocks and must match an earlier open brace
055 }close braces end code blocks and must match an earlier open brace
056 /**Makes sprites*/
057 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeSprites()
058 {open braces start code blocks and must be matched with a close brace
059 middle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 1);
060 middle.setScale(.25);
061 middle.setLocation(0.5, 0.4);
062 middle.setColor(Color.RED);
063
064 left=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 1);
065 left.setScale(.25);
066 left.setLocation(0.15, 0.4);
067 left.setColor(Color.RED);
068
069 right=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 1);
070 right.setScale(.25);
071 right.setLocation(0.85, 0.4);
072 right.setColor(Color.RED);
073
074 prize=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite ("Gbellbluesmile.gif");
075 prize.setScale(.2);
076
077 junk1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite ("Ex.jpg");
078 junk1.setScale(.3);
079
080 junk2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite ("Ex.jpg");
081 junk2.setScale(.3);
082
083 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");
084 title.setLocation(.5, .1);
085 title.setColor(Color.WHITE);
086 title.setScale(.8);
087
088 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 to begin.");
089 instruction.setLocation(.5, .78);
090 instruction.setColor(Color.GREEN);
091 instruction.setScale(.4);
092
093 instruction1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Either click the same door or choose another.");
094 instruction1.setLocation(.5, .78);
095 instruction1.setColor(Color.GREEN);
096 instruction1.setScale(.85);
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 win!");
099 win.setLocation(.5, .78);
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 lose.");
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(junk1);
113 canvas.addSprite(junk2);
114 canvas.addSprite(middle);
115 canvas.addSprite(left);
116 canvas.addSprite(right);
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 left box*/
121 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value leftClicked()
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(left.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 sound1.play();
128
129 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)
130 {open braces start code blocks and must be matched with a close brace
131 canvas.removeSprite(middle);
132 }close braces end code blocks and must match an earlier open brace
133 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)
134 {open braces start code blocks and must be matched with a close brace
135 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)
136 canvas.removeSprite(right);
137 elseelse is what happens when the if condition is false
138 canvas.removeSprite(middle);
139 }close braces end code blocks and must match an earlier open brace
140 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)
141 {open braces start code blocks and must be matched with a close brace
142 canvas.removeSprite(right);
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 }close braces end code blocks and must match an earlier open brace
146 /**First click is middle box*/
147 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value middleClicked()
148 {open braces start code blocks and must be matched with a close brace
149 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
150 ifif executes the next statement only if the condition in parenthesis evaluates to true(middle.intersects(click))
151 {open braces start code blocks and must be matched with a close brace
152 choice=this assignment operator makes the left side equal to the right side2;
153 sound1.play();
154 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)
155 {open braces start code blocks and must be matched with a close brace
156 canvas.removeSprite(left);
157 }close braces end code blocks and must match an earlier open brace
158 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)
159 {open braces start code blocks and must be matched with a close brace
160 canvas.removeSprite(right);
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 (location==this is the comparison operator which evaluates to true if both sides are the same2)
163 {open braces start code blocks and must be matched with a close brace
164 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)
165 canvas.removeSprite(right);
166 elseelse is what happens when the if condition is false
167 canvas.removeSprite(left);
168 }close braces end code blocks and must match an earlier open brace
169 }close braces end code blocks and must match an earlier open brace
170 }close braces end code blocks and must match an earlier open brace
171 /**First click is right box*/
172 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value rightClicked()
173 {open braces start code blocks and must be matched with a close brace
174 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
175 ifif executes the next statement only if the condition in parenthesis evaluates to true(right.intersects(click))
176 {open braces start code blocks and must be matched with a close brace
177 choice=this assignment operator makes the left side equal to the right side3;
178 sound1.play();
179 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)
180 {open braces start code blocks and must be matched with a close brace
181 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)
182 canvas.removeSprite(middle);
183 elseelse is what happens when the if condition is false
184 canvas.removeSprite(left);
185 }close braces end code blocks and must match an earlier open brace
186 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)
187 {open braces start code blocks and must be matched with a close brace
188 canvas.removeSprite(middle);
189 }close braces end code blocks and must match an earlier open brace
190 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)
191 {open braces start code blocks and must be matched with a close brace
192 canvas.removeSprite(left);
193 }close braces end code blocks and must match an earlier open brace
194 }close braces end code blocks and must match an earlier open brace
195 }close braces end code blocks and must match an earlier open brace
196
197 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)
198 {open braces start code blocks and must be matched with a close brace
199 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
200 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)
201 {open braces start code blocks and must be matched with a close brace
202 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)
203 {open braces start code blocks and must be matched with a close brace
204 stage=this assignment operator makes the left side equal to the right side1;
205 canvas.removeSprite(instruction);
206 canvas.addSprite(instruction1);
207 leftClicked();
208 middleClicked();
209 rightClicked();
210 }close braces end code blocks and must match an earlier open brace
211 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)
212 {open braces start code blocks and must be matched with a close brace
213 canvas.removeSprite(instruction1);
214 ifif executes the next statement only if the condition in parenthesis evaluates to true(left.intersects(click))
215 {open braces start code blocks and must be matched with a close brace
216 choice=this assignment operator makes the left side equal to the right side1;
217 }close braces end code blocks and must match an earlier open brace
218 ifif executes the next statement only if the condition in parenthesis evaluates to true(middle.intersects(click))
219 {open braces start code blocks and must be matched with a close brace
220 choice=this assignment operator makes the left side equal to the right side2;
221 }close braces end code blocks and must match an earlier open brace
222 ifif executes the next statement only if the condition in parenthesis evaluates to true(right.intersects(click))
223 {open braces start code blocks and must be matched with a close brace
224 choice=this assignment operator makes the left side equal to the right side3;
225 }close braces end code blocks and must match an earlier open brace
226 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)
227 {open braces start code blocks and must be matched with a close brace
228 canvas.removeSprite(left, middle, right);
229 sound1.play();
230 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)
231 {open braces start code blocks and must be matched with a close brace
232 canvas.addSprite(win);
233 }close braces end code blocks and must match an earlier open brace
234 elseelse is what happens when the if condition is false
235 {open braces start code blocks and must be matched with a close brace
236 canvas.addSprite(lose);
237 }close braces end code blocks and must match an earlier open brace
238 }close braces end code blocks and must match an earlier open brace
239
240 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)
241 {open braces start code blocks and must be matched with a close brace
242 canvas.removeSprite(left, middle, right);
243 sound1.play();
244 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)
245 {open braces start code blocks and must be matched with a close brace
246 canvas.addSprite(win);
247 }close braces end code blocks and must match an earlier open brace
248 elseelse is what happens when the if condition is false
249 {open braces start code blocks and must be matched with a close brace
250 canvas.addSprite(lose);
251 }close braces end code blocks and must match an earlier open brace
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(left, middle, right);
257 sound1.play();
258 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)
259 {open braces start code blocks and must be matched with a close brace
260 canvas.addSprite(win);
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 }close braces end code blocks and must match an earlier open brace
266 }close braces end code blocks and must match an earlier open brace
267
268 }close braces end code blocks and must match an earlier open brace
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
|