|
001 packagepackage is used to name the directory or folder a class is in Anam;
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 gamepractice 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;
014 privateprivate is used to restrict access to the current class only ImageSprite door2;
015 privateprivate is used to restrict access to the current class only ImageSprite door3;
016 privateprivate is used to restrict access to the current class only StringSprite num1;
017 privateprivate is used to restrict access to the current class only StringSprite num2;
018 privateprivate is used to restrict access to the current class only StringSprite num3;
019 privateprivate is used to restrict access to the current class only ImageSprite belle;
020 privateprivate is used to restrict access to the current class only ImageSprite choco;
021 privateprivate is used to restrict access to the current class only StringSprite heading;
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 numClicks;
023 privateprivate is used to restrict access to the current class only ImageSprite dollar;
024 privateprivate is used to restrict access to the current class only StringSprite instr;
025 privateprivate is used to restrict access to the current class only StringSprite ss;
026 privateprivate is used to restrict access to the current class only StringSprite win;
027 privateprivate is used to restrict access to the current class only StringSprite lose;
028 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;
029 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;
030 privateprivate is used to restrict access to the current class only StringSprite end;
031
032
033
034 /**sets up the game */
035 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
036 {open braces start code blocks and must be matched with a close brace
037
038 winningDoor=this assignment operator makes the left side equal to the right siderandom.nextInt(3)+adds two numbers together or concatenates Strings together1;
039 stage=this assignment operator makes the left side equal to the right side0;
040
041 end=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click Reload to Play Again");
042 end.setLocation(0.50, 0.90);
043 end.setSize(0.50);
044 end.setColor(Palette.getColor("SILVER"));
045 addSprite(end);
046 end.setVisible(falsefalse is a value for the boolean type and means not true);
047
048 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Congrats!!");
049 win.setLocation(0.55, 0.30);
050 win.setSize(0.50);
051 win.setColor(Palette.getColor("Light Green"));
052 addSprite(win);
053 win.setVisible(falsefalse is a value for the boolean type and means not true);
054
055
056 lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Ooopss..");
057 lose.setLocation(0.45, 0.30);
058 lose.setSize(0.50);
059 lose.setColor(Palette.getColor("Light Blue"));
060 addSprite(lose);
061 lose.setVisible(falsefalse is a value for the boolean type and means not true);
062
063
064 ss=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Stay or Pick Another Door");
065 ss.setLocation(0.50, .90);
066 ss.setSize(0.30);
067 ss.setColor(Color.WHITE);
068 addSprite(ss);
069 ss.setVisible(falsefalse is a value for the boolean type and means not true);
070
071
072 instr=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");
073 instr.setLocation(0.50, 0.80);
074 instr.setSize(0.40);
075 instr.setColor(Color.WHITE);
076 addSprite(instr);
077
078
079 numClicks=this assignment operator makes the left side equal to the right side0;
080
081 heading=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");
082 heading.setLocation(0.48, 0.12);
083 heading.setSize(0.60);
084 heading.setColor(Palette.getColor("Light Salmon"));
085 addSprite(heading);
086
087 belle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Belle.jpg");
088 //belle.setLocation(0.5, 0.5);
089 belle.setSize(0.14);
090
091 door2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("door.jpg");
092 door2.setLocation(0.5, 0.5);
093 door2.setSize(.25);
094
095 choco=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Choco.jpg");
096 //choco.setLocation(0.25, 0.50);
097 choco.setSize(0.12);
098
099 door1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("door.jpg");
100 door1.setLocation(0.23, 0.5);
101 door1.setSize(0.25);
102
103 dollar=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("dollar.jpg");
104 //dollar.setLocation(0.76, 0.50);
105 dollar.setSize(0.20);
106
107 door3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("door.jpg");
108 door3.setLocation(0.77, 0.5);
109 door3.setSize(0.25);
110
111 num1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("1");
112 num1.setLocation(0.22, 0.50);
113 num1.setSize(0.10);
114 num1.setColor(Color.BLACK);
115
116 num2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("2");
117 num2.setLocation(0.50, 0.50);
118 num2.setSize(0.10);
119 num2.setColor(Color.BLACK);
120
121
122 num3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("3");
123 num3.setLocation(0.77, 0.50);
124 num3.setSize(0.10);
125 num3.setColor(Color.BLACK);
126 addSprite(dollar);
127 addSprite(belle);
128 addSprite(choco);
129 addSprite(door1);
130 addSprite(door2);
131 addSprite(door3);
132 addSprite(num1);
133 addSprite(num2);
134 addSprite(num3);
135
136
137 ifif executes the next statement only if the condition in parenthesis evaluates to true (winningDoor==this is the comparison operator which evaluates to true if both sides are the same1)
138 {open braces start code blocks and must be matched with a close brace
139 dollar.setLocation(0.76, 0.50);
140 belle.setLocation(0.5, 0.5);
141 choco.setLocation(0.25, 0.50);
142 }close braces end code blocks and must match an earlier open brace
143 ifif executes the next statement only if the condition in parenthesis evaluates to true (winningDoor==this is the comparison operator which evaluates to true if both sides are the same2)
144 {open braces start code blocks and must be matched with a close brace
145 belle.setLocation(0.76, 0.50);
146 dollar.setLocation(0.5, 0.5);
147 choco.setLocation(0.25, 0.50);
148 }close braces end code blocks and must match an earlier open brace
149 ifif executes the next statement only if the condition in parenthesis evaluates to true (winningDoor==this is the comparison operator which evaluates to true if both sides are the same3)
150 {open braces start code blocks and must be matched with a close brace
151 choco.setLocation(0.76, 0.50);
152 belle.setLocation(0.5, 0.5);
153 dollar.setLocation(0.25, 0.50);
154 }close braces end code blocks and must match an earlier open brace
155
156 }close braces end code blocks and must match an earlier open brace
157
158 /**handle input and game events*/
159
160 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value doStage1Stuff()
161 {open braces start code blocks and must be matched with a close brace
162 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
163 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)
164 {open braces start code blocks and must be matched with a close brace
165 ifif executes the next statement only if the condition in parenthesis evaluates to true(door1.intersects(click))
166 {open braces start code blocks and must be matched with a close brace
167 canvas.removeSprite(door2);
168 canvas.removeSprite(num2);
169 instr.setVisible(falsefalse is a value for the boolean type and means not true);
170 ss.setVisible(truetrue is the boolean value that is the opposite of false);
171 stage=this assignment operator makes the left side equal to the right side1;
172
173 }close braces end code blocks and must match an earlier open brace
174 ifif executes the next statement only if the condition in parenthesis evaluates to true(door2.intersects(click))
175 {open braces start code blocks and must be matched with a close brace
176 canvas.removeSprite(door1);
177 canvas.removeSprite(num1);
178 instr.setVisible(falsefalse is a value for the boolean type and means not true);
179 ss.setVisible(truetrue is the boolean value that is the opposite of false);
180 stage=this assignment operator makes the left side equal to the right side1;
181
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(door3.intersects(click))
184 {open braces start code blocks and must be matched with a close brace
185 canvas.removeSprite(door1);
186 canvas.removeSprite(num1);
187 instr.setVisible(falsefalse is a value for the boolean type and means not true);
188 ss.setVisible(truetrue is the boolean value that is the opposite of false);
189 stage=this assignment operator makes the left side equal to the right side1;
190
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 }close braces end code blocks and must match an earlier open brace
194 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value doStage2Stuff()
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(door1.intersects(click))
200 {open braces start code blocks and must be matched with a close brace
201 canvas.removeSprite(door1);
202 canvas.removeSprite(num1);
203 canvas.removeSprite(door2);
204 canvas.removeSprite(num2);
205 canvas.removeSprite(door3);
206 canvas.removeSprite(num3);
207 ss.setVisible(falsefalse is a value for the boolean type and means not true);
208 lose.setVisible(truetrue is the boolean value that is the opposite of false);
209 end.setVisible(truetrue is the boolean value that is the opposite of false);
210
211 }close braces end code blocks and must match an earlier open brace
212 ifif executes the next statement only if the condition in parenthesis evaluates to true(door2.intersects(click))
213 {open braces start code blocks and must be matched with a close brace
214 canvas.removeSprite(door2);
215 canvas.removeSprite(num2);
216 canvas.removeSprite(door1);
217 canvas.removeSprite(num1);
218 canvas.removeSprite(door3);
219 canvas.removeSprite(num3);
220 ss.setVisible(falsefalse is a value for the boolean type and means not true);
221 lose.setVisible(truetrue is the boolean value that is the opposite of false);
222 end.setVisible(truetrue is the boolean value that is the opposite of false);
223
224 }close braces end code blocks and must match an earlier open brace
225 ifif executes the next statement only if the condition in parenthesis evaluates to true(door3.intersects(click))
226 {open braces start code blocks and must be matched with a close brace
227 canvas.removeSprite(door1);
228 canvas.removeSprite(num1);
229 canvas.removeSprite(door2);
230 canvas.removeSprite(num2);
231 canvas.removeSprite(door3);
232 canvas.removeSprite(num3);
233 lose.setVisible(falsefalse is a value for the boolean type and means not true);
234 instr.setVisible(falsefalse is a value for the boolean type and means not true);
235 ss.setVisible(falsefalse is a value for the boolean type and means not true);
236 win.setVisible(truetrue is the boolean value that is the opposite of false);
237 end.setVisible(truetrue is the boolean value that is the opposite of false);
238
239 }close braces end code blocks and must match an earlier open brace
240 }close braces end code blocks and must match an earlier open brace
241 }close braces end code blocks and must match an earlier open brace
242
243 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
244
245 {open braces start code blocks and must be matched with a close brace
246
247 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)
248 {open braces start code blocks and must be matched with a close brace
249 doStage1Stuff();
250 }close braces end code blocks and must match an earlier open brace
251 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)
252 {open braces start code blocks and must be matched with a close brace
253 doStage2Stuff();
254 }close braces end code blocks and must match an earlier open brace
255 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 same2)
256 {open braces start code blocks and must be matched with a close brace
257 //doStage3Stuff();
258 }close braces end code blocks and must match an earlier open brace
259
260 }close braces end code blocks and must match an earlier open brace
261
262
263 }close braces end code blocks and must match an earlier open brace
|