|
001 packagepackage is used to name the directory or folder a class is in Charles;
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 Charles Perez
010 */
011 /**the timed action in the advanced was created with the help of Kevins code*/
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 BearHockey extendsextends means to customize or extend the functionality of a class Game
013 {open braces start code blocks and must be matched with a close brace
014 /**movePuck is used to manipulate the pucks motion*/
015 privateprivate is used to restrict access to the current class only ProjectileTransformer movePuck;
016 privateprivate is used to restrict access to the current class only StringSprite logo1, logo2, p1, p1score, p2, p2score, clock, stage, gOMessage;
017 /**plyr is an array that indexs the two players in the order they connect to the game */
018 privateprivate is used to restrict access to the current class only Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays plyr;
019 privateprivate is used to restrict access to the current class only ImageSprite puck;
020 privateprivate is used to restrict access to the current class only LineSprite topC, bottomC, lGoal, rGoal;
021 /** s1 and s2 are used to represent the players scores, and level is used to represent stages of the game where aspects get modified*/
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 s1, s2, level, winner;
023 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions b, count;
024 privateprivate is used to restrict access to the current class only String helptxt;
025
026
027 /**sets up the game*/
028 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
029 {open braces start code blocks and must be matched with a close brace
030 level=this assignment operator makes the left side equal to the right side1;
031 intint is the type for whole numbers and it is short for integer s1=this assignment operator makes the left side equal to the right side0;
032 intint is the type for whole numbers and it is short for integer s2=this assignment operator makes the left side equal to the right side0;
033 count=this assignment operator makes the left side equal to the right side90;
034 gameLogos();
035 displayStage();
036 makePlayerIcons();
037 makePuck();
038 makeHelp();
039 locatePlayer();
040 makeScoreBoard();
041 makeTimeClock();
042 gameArea();
043 gameEnd();
044 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.rotateDegrees(180);
045
046 }close braces end code blocks and must match an earlier open brace
047 /**creates the help message forfor is a looping structure for repeatedly executing a block of code the player to read once game is loaded*/
048 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeHelp()
049 {open braces start code blocks and must be matched with a close brace
050 helptxt=this assignment operator makes the left side equal to the right side
051 "*To begin click start.<br>"+adds two numbers together or concatenates Strings together
052 "*Player one will be the first player who joined while player two will be the second.<br>"+adds two numbers together or concatenates Strings together
053 "*Move your bear up by using W and down by using S.<br>"+adds two numbers together or concatenates Strings together
054 "*The object of the game is to keep the G puck out of your goal and score more than your opponent before the time is up!<br>"+adds two numbers together or concatenates Strings together
055 "*Once you've completed level one, the game will advance and become more difficult!<br>"+adds two numbers together or concatenates Strings together
056 "You have 90 seconds Good Luck!<br>";
057 setHelpText(helptxt);
058 }close braces end code blocks and must match an earlier open brace
059 /**Contains the design as well as adds the border forfor is a looping structure for repeatedly executing a block of code the game's action to be contained in*/
060 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value gameArea()
061 {open braces start code blocks and must be matched with a close brace
062 topC=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(-0.1,0.5, 1.1, 0.5);
063 topC.setLocation(0.5,0.3);
064 topC.setColor(getColor("Green"));
065 topC.setLineThickness(0.05);
066 addSprite(topC);
067
068 bottomC=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(-0.1,0.5, 1.1, 0.5);
069 bottomC.setLocation(0.5,0.98);
070 bottomC.setColor(getColor("Green"));
071 bottomC.setLineThickness(0.05);
072 addSprite(bottomC);
073
074 lGoal=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(0.0, 0.0, 0.0, 0.62);
075 lGoal.setLineThickness(0.03);
076 lGoal.setLocation(0.02, 0.64);
077 lGoal.setColor(getColor("White"));
078 addSprite(lGoal);
079
080 rGoal=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(0.0, 0.0, 0.0, 0.62);
081 rGoal.setLineThickness(0.03);
082 rGoal.setLocation(0.98, 0.64);
083 rGoal.setColor(getColor("White"));
084 addSprite(rGoal);
085 }close braces end code blocks and must match an earlier open brace
086 /**creates an incomplete string that is filled in based on the players scores at the end of the game*/
087 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value gameEnd()
088 {open braces start code blocks and must be matched with a close brace
089 gOMessage=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("");
090 gOMessage.setLocation(0.5,0.5);
091 gOMessage.setVisible(falsefalse is a value for the boolean type and means not true);
092 addSprite(gOMessage);
093 }close braces end code blocks and must match an earlier open brace
094 /**creates the level display at the top of the game screen so the player knows what point of the game they are in*/
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value displayStage()
096 {open braces start code blocks and must be matched with a close brace
097 stage=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Level:"+adds two numbers together or concatenates Strings togetherlevel);
098 stage.setScale(0.2);
099 stage.setLocation(0.5, 0.1);
100 stage.setColor(getColor("Red"));
101 addSprite(stage);
102 }close braces end code blocks and must match an earlier open brace
103 /**creates the score board that indicates the players number and displayes each players individual score*/
104 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeScoreBoard()
105 {open braces start code blocks and must be matched with a close brace
106 p1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Player 1");
107 p1.setLocation(0.15, 0.1);
108 p1.setScale(0.2);
109 p1.setColor(getColor("Yellow"));
110 addSprite(p1);
111
112 p1score=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score:"+adds two numbers together or concatenates Strings togethers1);
113 p1score.setLocation(0.15, 0.2);
114 p1score.setScale(0.2);
115 p1score.setColor(getColor("Yellow"));
116 addSprite(p1score);
117
118 p2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Player 2");
119 p2.setLocation(0.8, 0.1);
120 p2.setScale(0.2);
121 p2.setColor(getColor("Yellow"));
122 addSprite(p2);
123
124 p2score=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score:"+adds two numbers together or concatenates Strings togethers2);
125 p2score.setLocation(0.8, 0.2);
126 p2score.setScale(0.2);
127 p2score.setColor(getColor("Yellow"));
128 addSprite(p2score);
129 }close braces end code blocks and must match an earlier open brace
130 /**creates the clock display forfor is a looping structure for repeatedly executing a block of code the time left in the game.*/
131 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTimeClock()
132 {open braces start code blocks and must be matched with a close brace
133 clock=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Time Left:"+adds two numbers together or concatenates Strings togethercount);
134 clock.setLocation(0.5, 0.25);
135 clock.setScale(0.25);
136 clock.setColor(getColor("White"));
137 addSprite(clock);
138 }close braces end code blocks and must match an earlier open brace
139 /**creates two strings as logos on the side of the game table with the bottom one upside down*/
140 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value gameLogos()
141 {open braces start code blocks and must be matched with a close brace
142 logo1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("BearHockey");
143 logo1.setLocation(0.5, 0.3);
144 logo1.setHeight(0.04);
145 logo1.setColor(getColor("Yellow"));
146 addSprite(logo1);
147
148 logo2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("BearHockey");
149 logo2.setLocation(0.5, 0.98);
150 logo2.setHeight(0.04);
151 logo2.setColor(getColor("Yellow"));
152 logo2.setRotationDegrees(180);
153 addSprite(logo2);
154 }close braces end code blocks and must match an earlier open brace
155 /**Creates the images used to represent the players in the game area via a bear that i created in art to go with the GGC theme*/
156 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePlayerIcons()
157 {open braces start code blocks and must be matched with a close brace
158 plyr=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arraysgetNumberOfPlayers()]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
159 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<plyr.length; i++this is the increment operator, which increases the variable by 1)
160 {open braces start code blocks and must be matched with a close brace
161 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Bear2.jpg");
162 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.14);
163 addSprite(plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
164 }close braces end code blocks and must match an earlier open brace
165 }close braces end code blocks and must match an earlier open brace
166
167 /**creates and adds the image that represents the puck*/
168 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePuck()
169 {open braces start code blocks and must be matched with a close brace
170 puck=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Puck.jpg");
171 puck.setScale(0.06);
172 puck.setLocation(0.5, 0.65);
173 movePuck=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.1, 0.25);
174 puck.setTracker(movePuck);
175 addSprite(puck);
176 }close braces end code blocks and must match an earlier open brace
177 /**instructes the puck to bounce off of certain objects.*/
178 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handlePuckMotion()
179 {open braces start code blocks and must be matched with a close brace
180 puck.bounceOffOf(topC);
181 puck.bounceOffOf(bottomC);
182 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<plyr.length; i++this is the increment operator, which increases the variable by 1)
183 {open braces start code blocks and must be matched with a close brace
184 puck.bounceOffOf(plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
185 }close braces end code blocks and must match an earlier open brace
186 }close braces end code blocks and must match an earlier open brace
187 /** places player one on the left side of the feild and player 2 on the right side*/
188 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value locatePlayer()
189 {open braces start code blocks and must be matched with a close brace
190 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<plyr.length; i++this is the increment operator, which increases the variable by 1)
191 {open braces start code blocks and must be matched with a close brace
192 ifif executes the next statement only if the condition in parenthesis evaluates to true(i%this divides the left side by the right side and evaluates to the remainder2==this is the comparison operator which evaluates to true if both sides are the same0)
193 {open braces start code blocks and must be matched with a close brace
194 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(0.08, 0.65);
195 }close braces end code blocks and must match an earlier open brace
196 elseelse is what happens when the if condition is false
197 {open braces start code blocks and must be matched with a close brace
198 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(0.92, 0.65);
199 }close braces end code blocks and must match an earlier open brace
200 }close braces end code blocks and must match an earlier open brace
201 }close braces end code blocks and must match an earlier open brace
202 /** allows the players to move thier icons up and down*/
203 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value movePlayer()
204 {open braces start code blocks and must be matched with a close brace
205 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<plyr.length; i++this is the increment operator, which increases the variable by 1)
206 {open braces start code blocks and must be matched with a close brace
207 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sideplyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getY();
208 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed(i)==this is the comparison operator which evaluates to true if both sides are the same'w' &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 &&) plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getY()>=this evaluates to true if the left side is not less than the right side0.35)
209 {open braces start code blocks and must be matched with a close brace
210 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setY(y-0.035);
211 }close braces end code blocks and must match an earlier open brace
212 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed(i)==this is the comparison operator which evaluates to true if both sides are the same's' &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 &&) plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getY()<=this evaluates to true if the left side is not more than the right side0.93)
213 {open braces start code blocks and must be matched with a close brace
214 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setY(y+adds two numbers together or concatenates Strings together0.035);
215 }close braces end code blocks and must match an earlier open brace
216 }close braces end code blocks and must match an earlier open brace
217 }close braces end code blocks and must match an earlier open brace
218 /**creates the speed and angle forfor is a looping structure for repeatedly executing a block of code the puck to be released during level1*/
219 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value puckSpeed1()
220 {open braces start code blocks and must be matched with a close brace
221 intint is the type for whole numbers and it is short for integer a=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
222 ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same0)
223 {open braces start code blocks and must be matched with a close brace
224 movePuck.setVector2D(0.25, 0.0);
225 }close braces end code blocks and must match an earlier open brace
226 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(a==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 movePuck.setVector2D(-0.25,0.0);
229 }close braces end code blocks and must match an earlier open brace
230 }close braces end code blocks and must match an earlier open brace
231 /**creates the speed and angle forfor is a looping structure for repeatedly executing a block of code the puck to be released during level2*/
232 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value puckSpeed2()
233 {open braces start code blocks and must be matched with a close brace
234 intint is the type for whole numbers and it is short for integer a=this assignment operator makes the left side equal to the right siderandom.nextInt(4);
235 ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same0)
236 {open braces start code blocks and must be matched with a close brace
237 movePuck.setVector2D(0.3, -0.1);
238 }close braces end code blocks and must match an earlier open brace
239 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same1)
240 {open braces start code blocks and must be matched with a close brace
241 movePuck.setVector2D(-0.3,-0.1);
242 }close braces end code blocks and must match an earlier open brace
243 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same2)
244 {open braces start code blocks and must be matched with a close brace
245 movePuck.setVector2D(0.3,0.1);
246 }close braces end code blocks and must match an earlier open brace
247 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same3)
248 {open braces start code blocks and must be matched with a close brace
249 movePuck.setVector2D(-0.3,0.1);
250 }close braces end code blocks and must match an earlier open brace
251 }close braces end code blocks and must match an earlier open brace
252 /**creates the speed and angle forfor is a looping structure for repeatedly executing a block of code the puck to be released during level3*/
253 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value puckSpeed3()
254 {open braces start code blocks and must be matched with a close brace
255 intint is the type for whole numbers and it is short for integer a=this assignment operator makes the left side equal to the right siderandom.nextInt(4);
256 ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same0)
257 {open braces start code blocks and must be matched with a close brace
258 movePuck.setVector2D(0.4, -0.15);
259 }close braces end code blocks and must match an earlier open brace
260 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(a==this is the comparison operator which evaluates to true if both sides are the same1)
261 {open braces start code blocks and must be matched with a close brace
262 movePuck.setVector2D(-0.4,-0.15);
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(a==this is the comparison operator which evaluates to true if both sides are the same2)
265 {open braces start code blocks and must be matched with a close brace
266 movePuck.setVector2D(0.4,0.15);
267 }close braces end code blocks and must match an earlier open brace
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(a==this is the comparison operator which evaluates to true if both sides are the same3)
269 {open braces start code blocks and must be matched with a close brace
270 movePuck.setVector2D(-0.4,0.15);
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 /** when the puck crosses player 2's goal player 1 scores and the puck is reset and released based on the level*/
274 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value player1Scores()
275 {open braces start code blocks and must be matched with a close brace
276 ifif executes the next statement only if the condition in parenthesis evaluates to true(puck.getX()>=this evaluates to true if the left side is not less than the right side 1.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 &&)puck.getX()<=this evaluates to true if the left side is not more than the right side1.02 )
277 {open braces start code blocks and must be matched with a close brace
278 s1++this is the increment operator, which increases the variable by 1;
279 p1score.setText("Score:"+adds two numbers together or concatenates Strings togethers1);
280 puck.setLocation(0.5,0.65);
281 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same1)
282 {open braces start code blocks and must be matched with a close brace
283 puckSpeed1();
284 }close braces end code blocks and must match an earlier open brace
285 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same2)
286 {open braces start code blocks and must be matched with a close brace
287 puckSpeed2();
288 }close braces end code blocks and must match an earlier open brace
289 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same3)
290 {open braces start code blocks and must be matched with a close brace
291 puckSpeed3();
292 }close braces end code blocks and must match an earlier open brace
293 }close braces end code blocks and must match an earlier open brace
294 }close braces end code blocks and must match an earlier open brace
295 /** when the puck crosses player 1's goal player 2 scores and the puck is reset and released based on the level*/
296 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value player2Scores()
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(puck.getX()<=this evaluates to true if the left side is not more than the right side 0.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 &&) puck.getX()>=this evaluates to true if the left side is not less than the right side-0.02 )
299 {open braces start code blocks and must be matched with a close brace
300 s2++this is the increment operator, which increases the variable by 1;
301 p2score.setText("Score:"+adds two numbers together or concatenates Strings togethers2);
302 puck.setLocation(0.5,0.65);
303 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same1)
304 {open braces start code blocks and must be matched with a close brace
305 puckSpeed1();
306 }close braces end code blocks and must match an earlier open brace
307 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same2)
308 {open braces start code blocks and must be matched with a close brace
309 puckSpeed2();
310 }close braces end code blocks and must match an earlier open brace
311 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same3)
312 {open braces start code blocks and must be matched with a close brace
313 puckSpeed3();
314 }close braces end code blocks and must match an earlier open brace
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 /** advances the game to level 2 at 70 seconds*/
318 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value advanceToLevel2()
319 {open braces start code blocks and must be matched with a close brace
320 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same1 &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 &&) count<=this evaluates to true if the left side is not more than the right side70 &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 &&) count>=this evaluates to true if the left side is not less than the right side30)
321 {open braces start code blocks and must be matched with a close brace
322 level=this assignment operator makes the left side equal to the right side2;
323 stage.setText("Level:"+adds two numbers together or concatenates Strings togetherlevel);
324 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<plyr.length; i++this is the increment operator, which increases the variable by 1)
325 {open braces start code blocks and must be matched with a close brace
326 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.1);
327 }close braces end code blocks and must match an earlier open brace
328 }close braces end code blocks and must match an earlier open brace
329 }close braces end code blocks and must match an earlier open brace
330 /** advances the game to level 3 at 30 seconds*/
331 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value advanceToLevel3()
332 {open braces start code blocks and must be matched with a close brace
333 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same2 &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 &&) count<30)
334 {open braces start code blocks and must be matched with a close brace
335 level=this assignment operator makes the left side equal to the right side3;
336 stage.setText("Level:"+adds two numbers together or concatenates Strings togetherlevel);
337 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<plyr.length; i++this is the increment operator, which increases the variable by 1)
338 {open braces start code blocks and must be matched with a close brace
339 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setX(0.1);
340 plyr[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setX(0.9);
341 }close braces end code blocks and must match an earlier open brace
342 }close braces end code blocks and must match an earlier open brace
343 }close braces end code blocks and must match an earlier open brace
344 /** displayes the winner of the game at 0 seconds based on the returnreturn means to provide the result of the method and/or cease execution of the method immediately value of findWinner(), and stops the pucks movement.*/
345 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value endGameMessage()
346 {open braces start code blocks and must be matched with a close brace
347 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same3 &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 &&) count<0.5)
348 {open braces start code blocks and must be matched with a close brace
349 level=this assignment operator makes the left side equal to the right side4;
350 movePuck.setVector2D(0.0,0.0);
351 ifif executes the next statement only if the condition in parenthesis evaluates to true(winner==this is the comparison operator which evaluates to true if both sides are the same1 ||this is boolean or, meaning if either or both are true then the result is true winner==this is the comparison operator which evaluates to true if both sides are the same2)
352 {open braces start code blocks and must be matched with a close brace
353 gOMessage.setText("Player:"+adds two numbers together or concatenates Strings togetherwinner +adds two numbers together or concatenates Strings together" is the WINNER!!");
354 gOMessage.setSize(0.7);
355 }close braces end code blocks and must match an earlier open brace
356 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(winner==this is the comparison operator which evaluates to true if both sides are the same0)
357 {open braces start code blocks and must be matched with a close brace
358 gOMessage.setText("Tie");
359 gOMessage.setScale(0.2);
360 }close braces end code blocks and must match an earlier open brace
361 gOMessage.setVisible(truetrue is the boolean value that is the opposite of false);
362 }close braces end code blocks and must match an earlier open brace
363 }close braces end code blocks and must match an earlier open brace
364 /**recieves the two intint is the type for whole numbers and it is short for integer parameters forfor is a looping structure for repeatedly executing a block of code both players' scores and returns an intint is the type for whole numbers and it is short for integer that determines ifif executes the next statement only if the condition in parenthesis evaluates to true player 1 or player is the winner or a tie */
365 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer findWinner(intint is the type for whole numbers and it is short for integer s1, intint is the type for whole numbers and it is short for integer s2)
366 {open braces start code blocks and must be matched with a close brace
367 ifif executes the next statement only if the condition in parenthesis evaluates to true(s1>s2)
368 {open braces start code blocks and must be matched with a close brace
369 winner=this assignment operator makes the left side equal to the right side1;
370 }close braces end code blocks and must match an earlier open brace
371 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(s1<s2)
372 {open braces start code blocks and must be matched with a close brace
373 winner=this assignment operator makes the left side equal to the right side2;
374 }close braces end code blocks and must match an earlier open brace
375 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(s1==this is the comparison operator which evaluates to true if both sides are the sames2)
376 {open braces start code blocks and must be matched with a close brace
377 winner=this assignment operator makes the left side equal to the right side0;
378 }close braces end code blocks and must match an earlier open brace
379 returnreturn means to provide the result of the method and/or cease execution of the method immediately winner;
380 }close braces end code blocks and must match an earlier open brace
381 /**handle input and game events*/
382 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
383 {open braces start code blocks and must be matched with a close brace
384 handlePuckMotion();
385 movePlayer();
386 player1Scores();
387 player2Scores();
388 advanceToLevel2();
389 advanceToLevel3();
390 findWinner(s1,s2);
391 endGameMessage();
392 }close braces end code blocks and must match an earlier open brace
393 /**once game starts thisthis means the current object (the implicit parameter) reduces the timer by 1 every second until it reaches 0. I recieved help from Kevin Rohrer to get thisthis means the current object (the implicit parameter) to count properly.*/
394 classclass is a group of fields and methods used for making objects DelayedResponse extendsextends means to customize or extend the functionality of a class TimedAction
395 {open braces start code blocks and must be matched with a close brace
396 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
397 {open braces start code blocks and must be matched with a close brace
398 count--this is the decrement operator, which decreases the variable by 1;
399 clock.setText("Time Left:"+adds two numbers together or concatenates Strings togethercount);
400 ifif executes the next statement only if the condition in parenthesis evaluates to true(count>0.0)
401 schedule(thisthis means the current object (the implicit parameter),1.0);
402 }close braces end code blocks and must match an earlier open brace
403 }close braces end code blocks and must match an earlier open brace
404 {open braces start code blocks and must be matched with a close brace
405 schedule(newnew is used to create objects by calling the constructor DelayedResponse(),1.0);
406 }close braces end code blocks and must match an earlier open brace
407 }close braces end code blocks and must match an earlier open brace
|