|
001 packagepackage is used to name the directory or folder a class is in scg.ch09;
002
003 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
004
005 importimport means to make the classes and/or packages available in this program fang2.core.Game;
006 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
007 importimport means to make the classes and/or packages available in this program fang2.sprites.StringSprite;
008
009 /**
010 * A "space invaders" clone-like game. The goal is to rescue the
011 * swimmers in the water before they reach the edge of the water. This
012 * game is both a game and a level. When the player clears a level, the
013 * game will advance to the next level. The next level is a newnew is used to create objects by calling the constructor copy of
014 * thisthis means the current object (the implicit parameter) game (so setup and advance will be called automatically) with a
015 * different swimmer speed.
016 */
017 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 RescueMission
018 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
019 // Named Constants --------------------------------------------
020 /** number of rows and columns in the game */
021 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer ROWS =this assignment operator makes the left side equal to the right side 4;
022 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer COLUMNS =this assignment operator makes the left side equal to the right side 6;
023
024 /** add to level forfor is a looping structure for repeatedly executing a block of code fast swimmer's score */
025 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer FASTSWIMMER_BASE_SCORE =this assignment operator makes the left side equal to the right side 9;
026
027 /** how much should the swimmers speed up on each newnew is used to create objects by calling the constructor level */
028 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions LEVEL_SPEEDUP =this assignment operator makes the left side equal to the right side 1.10;
029
030 /** defaultdefault is what is executed when no cases are matched speeds forfor is a looping structure for repeatedly executing a block of code the moving objects */
031 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions RESCUER_DX =this assignment operator makes the left side equal to the right side 1.0;
032 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions RESCUER_DY =this assignment operator makes the left side equal to the right side 0.0;
033 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions RING_DX =this assignment operator makes the left side equal to the right side 0.0;
034 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions RING_DY =this assignment operator makes the left side equal to the right side -0.3;
035 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions SWIMMER_DX =this assignment operator makes the left side equal to the right side 0.2;
036 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions SWIMMER_DY =this assignment operator makes the left side equal to the right side 0.0;
037
038 // Object Fields ----------------------------------------------
039 /** the fast swimmer (across the top) forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) game; reused */
040 privateprivate is used to restrict access to the current class only FastSwimmer fastSwimmer;
041
042 /** the starting score of thisthis means the current object (the implicit parameter) game */
043 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer initialScore;
044
045 /** What level number is thisthis means the current object (the implicit parameter)? */
046 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer level;
047
048 /** the scale of the swimmers (and everything elseelse is what happens when the if condition is false) */
049 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions objectScale;
050
051 /** the rescuer who will save the people */
052 privateprivate is used to restrict access to the current class only Rescuer rescuer;
053
054 /** the rescuer's tool with which to rescue the characters */
055 privateprivate is used to restrict access to the current class only RescueRing ring;
056
057 /** a sprite to display the current score */
058 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
059
060 /** Initial speed forfor is a looping structure for repeatedly executing a block of code all the regular swimmers */
061 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions swimmerDX;
062 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions swimmerDY;
063
064 /** 2-dimensional container of Swimmer's */
065 privateprivate is used to restrict access to the current class only ArrayList<ArrayList<Swimmer>>this performs a bit-wise right shift swimmers;
066
067 /** The water background */
068 privateprivate is used to restrict access to the current class only RectangleSprite water;
069 // Constructors -----------------------------------------------
070
071 /**
072 * Create the first level in the game: level 1, score starts at 0,
073 * speed is defaultdefault is what is executed when no cases are matched
074 */
075 publicpublic is used to indicate unrestricted access (any other class can have access) RescueMission() {open braces start code blocks and must be matched with a close brace
076 thisthis means the current object (the implicit parameter)(1, 0, SWIMMER_DX, SWIMMER_DY);
077 }close braces end code blocks and must match an earlier open brace
078
079 /**
080 * Create a newnew is used to create objects by calling the constructor level in the game with the given speed
081 *
082 * @paramthis is the Javadoc tag for documenting the purpose of parameters initialScore the starting score forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) level
083 * @paramthis is the Javadoc tag for documenting the purpose of parameters swimmerDX horizontal component of swimmer velocity forfor is a looping structure for repeatedly executing a block of code
084 * thisthis means the current object (the implicit parameter) level
085 * @paramthis is the Javadoc tag for documenting the purpose of parameters swimmerDY vertical component of swimmer velocity forfor is a looping structure for repeatedly executing a block of code
086 * thisthis means the current object (the implicit parameter) level
087 */
088 publicpublic is used to indicate unrestricted access (any other class can have access) RescueMission(intint is the type for whole numbers and it is short for integer level, intint is the type for whole numbers and it is short for integer initialScore, doubledouble is the type for numbers that can contain decimal fractions swimmerDX,
089 doubledouble is the type for numbers that can contain decimal fractions swimmerDY) {open braces start code blocks and must be matched with a close brace
090 thisthis means the current object (the implicit parameter).scoreSprite =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
091 thisthis means the current object (the implicit parameter).level =this assignment operator makes the left side equal to the right side level;
092 thisthis means the current object (the implicit parameter).swimmerDX =this assignment operator makes the left side equal to the right side swimmerDX;
093 thisthis means the current object (the implicit parameter).swimmerDY =this assignment operator makes the left side equal to the right side swimmerDY;
094 thisthis means the current object (the implicit parameter).initialScore =this assignment operator makes the left side equal to the right side initialScore;
095 }close braces end code blocks and must match an earlier open brace
096
097 // Methods ----------------------------------------------------
098 /**
099 * Advance to the next frame.
100 *
101 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT seconds since the last frame
102 */
103 @Override
104 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
105 moveEverything(dT);
106 bounceEverything();
107 rescueIfPossible();
108 ifif executes the next statement only if the condition in parenthesis evaluates to true (checkIsLevelOver()) {open braces start code blocks and must be matched with a close brace
109 addGame(newnew is used to create objects by calling the constructor RescueMission(level +adds two numbers together or concatenates Strings together 1, getScore(),
110 swimmerDX * LEVEL_SPEEDUP, swimmerDY * LEVEL_SPEEDUP));
111 finishGame();
112 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (checkIsGameOver()) {open braces start code blocks and must be matched with a close brace
113 addGame(newnew is used to create objects by calling the constructor EndOfGame(getScore()));
114 finishGame();
115 }close braces end code blocks and must match an earlier open brace
116 }close braces end code blocks and must match an earlier open brace
117
118 /**
119 * Set the score. {open braces start code blocks and must be matched with a close brace@link Game#setScore(intint is the type for whole numbers and it is short for integer)}close braces end code blocks and must match an earlier open brace is built-in to {open braces start code blocks and must be matched with a close brace@link
120 * Game}close braces end code blocks and must match an earlier open brace; thisthis means the current object (the implicit parameter) method passes the newnew is used to create objects by calling the constructor score up to the parent classclass is a group of fields and methods used for making objects's
121 * method. Then it also updates the display of the score on the
122 * screen.
123 *
124 * @paramthis is the Javadoc tag for documenting the purpose of parameters score the newnew is used to create objects by calling the constructor score value
125 */
126 @Override
127 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setScore(intint is the type for whole numbers and it is short for integer score) {open braces start code blocks and must be matched with a close brace
128 super.setScore(score);
129 // if the scoreSprite not yet used, create and store value
130 ifif executes the next statement only if the condition in parenthesis evaluates to true (scoreSprite ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
131 scoreSprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite();
132 scoreSprite.setScale(0.10);
133 scoreSprite.rightJustify();
134 scoreSprite.topJustify();
135 scoreSprite.setLocation(1.0, 0.0);
136 scoreSprite.setColor(getColor("gray"));
137 addSprite(scoreSprite);
138 }close braces end code blocks and must match an earlier open brace
139 scoreSprite.setText(Integer.toString(getScore()));
140 }close braces end code blocks and must match an earlier open brace
141
142 /**
143 * Setup the rescue game: create victims and the rescuer.
144 */
145 @Override
146 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
147 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions victimRowScale =this assignment operator makes the left side equal to the right side 0.5 / ROWS;
148 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions victimColumnScale =this assignment operator makes the left side equal to the right side 0.7 / COLUMNS;
149
150 // set the scale to make everything about the same size
151 objectScale =this assignment operator makes the left side equal to the right side Math.min(victimRowScale, victimColumnScale);
152
153 setupWater();
154 setupSwimmers();
155 setupRescuer();
156 setupFastSwimmer();
157 setScore(initialScore);// display the score
158 }close braces end code blocks and must match an earlier open brace
159
160 /**
161 * Bounce all sprites: use each sprite's bounceOffEdges method to have
162 * it dodo is part of the do-while looping structure (post condition loop) whatever it should dodo is part of the do-while looping structure (post condition loop).
163 */
164 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bounceEverything() {open braces start code blocks and must be matched with a close brace
165 fastSwimmer.bounceOffEdges();
166 rescuer.bounceOffEdges();
167 ring.bounceOffEdges();
168 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 row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
169 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 column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
170 Swimmer curr =this assignment operator makes the left side equal to the right side swimmers.get(row).get(column);
171 ifif executes the next statement only if the condition in parenthesis evaluates to true (curr !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
172 curr.bounceOffEdges();
173 }close braces end code blocks and must match an earlier open brace
174 }close braces end code blocks and must match an earlier open brace
175 }close braces end code blocks and must match an earlier open brace
176 Swimmer.clearBumpTheWall();
177 }close braces end code blocks and must match an earlier open brace
178
179 /**
180 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true the game is over (swimmers reach bottom); falsefalse is a value for the boolean type and means not true
181 * otherwise
182 */
183 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false checkIsGameOver() {open braces start code blocks and must be matched with a close brace
184 returnreturn means to provide the result of the method and/or cease execution of the method immediately ((getLowestSwimmer() !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
185 (getLowestSwimmer().getMaxY() >=this evaluates to true if the left side is not less than the right side water.getMaxY()));
186 }close braces end code blocks and must match an earlier open brace
187
188 /**
189 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true no unrescued swimmers; falsefalse is a value for the boolean type and means not true otherwise
190 */
191 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false checkIsLevelOver() {open braces start code blocks and must be matched with a close brace
192 returnreturn means to provide the result of the method and/or cease execution of the method immediately (remainingSwimmerCount() ==this is the comparison operator which evaluates to true if both sides are the same 0);
193 }close braces end code blocks and must match an earlier open brace
194
195 /**
196 * Get the left-most swimmer in the lowest row of swimmers. Works by
197 * running across the rows from bottom to top, returning a reference
198 * to the first non-nullnull is the value used to refer to a non-existant object Swimmer.
199 *
200 * @returnnull reference to the lowest non-nullnull is the value used to refer to a non-existant object swimmer, left-most in its
201 * row (ifif executes the next statement only if the condition in parenthesis evaluates to true there are more than one in the row); nullnull is the value used to refer to a non-existant object ifif executes the next statement only if the condition in parenthesis evaluates to true there
202 * are no Swimmers remaining
203 */
204 privateprivate is used to restrict access to the current class only Swimmer getLowestSwimmer() {open braces start code blocks and must be matched with a close brace
205 Swimmer lowest =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
206 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 row =this assignment operator makes the left side equal to the right side 0; ((lowest ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (row !=this is the not equals operator which evaluates to true if both sides are different ROWS)); ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
207 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 column =this assignment operator makes the left side equal to the right side 0; ((lowest ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS));
208 ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
209 Swimmer curr =this assignment operator makes the left side equal to the right side swimmers.get(row).get(column);
210 ifif executes the next statement only if the condition in parenthesis evaluates to true (curr !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
211 lowest =this assignment operator makes the left side equal to the right side curr;
212 }close braces end code blocks and must match an earlier open brace
213 }close braces end code blocks and must match an earlier open brace
214 }close braces end code blocks and must match an earlier open brace
215 returnreturn means to provide the result of the method and/or cease execution of the method immediately lowest;
216 }close braces end code blocks and must match an earlier open brace
217
218 /**
219 * Move all the moving objects on the screen. Moving objects are the
220 * Swimmers, the Rescuer, the RescueRing, and the FastSwimmer. Note
221 * that none of these (except Swimmer's in the array) will be nullnull is the value used to refer to a non-existant object so
222 * we just call advance on each and they move according to their own
223 * state and rules.
224 *
225 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT seconds since last frame
226 */
227 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveEverything(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
228 fastSwimmer.advance(dT);
229 rescuer.advance(dT);
230 ring.advance(dT);
231 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 row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
232 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 column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
233 Swimmer curr =this assignment operator makes the left side equal to the right side swimmers.get(row).get(column);
234 ifif executes the next statement only if the condition in parenthesis evaluates to true (curr !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
235 curr.advance(dT);
236 }close braces end code blocks and must match an earlier open brace
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 }close braces end code blocks and must match an earlier open brace
240
241 /**
242 * Determine the number of swimmers remaining to be rescued. This is
243 * the same as counting the number of entries in swimmers which are
244 * non-nullnull is the value used to refer to a non-existant object. This is a counting problem.
245 *
246 * @returnnull the number of swimmers awaiting rescue
247 */
248 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer remainingSwimmerCount() {open braces start code blocks and must be matched with a close brace
249 intint is the type for whole numbers and it is short for integer numberOfSwimmers =this assignment operator makes the left side equal to the right side 0;
250 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 row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
251 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 column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
252 Swimmer curr =this assignment operator makes the left side equal to the right side swimmers.get(row).get(column);
253 ifif executes the next statement only if the condition in parenthesis evaluates to true (curr !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
254 ++this is the increment operator, which increases the variable by 1numberOfSwimmers;
255 }close braces end code blocks and must match an earlier open brace
256 }close braces end code blocks and must match an earlier open brace
257 }close braces end code blocks and must match an earlier open brace
258 returnreturn means to provide the result of the method and/or cease execution of the method immediately numberOfSwimmers;
259 }close braces end code blocks and must match an earlier open brace
260
261 /**
262 * Rescue the fast swimmer.
263 */
264 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value rescueFastSwimmer() {open braces start code blocks and must be matched with a close brace
265 setScore(getScore() +adds two numbers together or concatenates Strings together fastSwimmer.getScore());
266 fastSwimmer.startWaiting();
267 ring.startReady();
268 }close braces end code blocks and must match an earlier open brace
269
270 /**
271 * Check ifif executes the next statement only if the condition in parenthesis evaluates to true any swimmer is rescued.
272 */
273 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value rescueIfPossible() {open braces start code blocks and must be matched with a close brace
274 ifif executes the next statement only if the condition in parenthesis evaluates to true (ring.isFlying()) {open braces start code blocks and must be matched with a close brace
275 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 row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
276 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 column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
277 Swimmer curr =this assignment operator makes the left side equal to the right side swimmers.get(row).get(column);
278 ifif executes the next statement only if the condition in parenthesis evaluates to true (ring.isRescuing(curr)) {open braces start code blocks and must be matched with a close brace
279 rescueSwimmer(row, column);
280 }close braces end code blocks and must match an earlier open brace
281 }close braces end code blocks and must match an earlier open brace
282 }close braces end code blocks and must match an earlier open brace
283 }close braces end code blocks and must match an earlier open brace
284 ifif executes the next statement only if the condition in parenthesis evaluates to true (fastSwimmer.isSwimming() &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 &&) ring.isRescuing(fastSwimmer)) {open braces start code blocks and must be matched with a close brace
285 rescueFastSwimmer();
286 }close braces end code blocks and must match an earlier open brace
287 }close braces end code blocks and must match an earlier open brace
288
289 /**
290 * Rescue the Swimmer at the given position in the array. Removes the
291 * sprite from the game screen and sets the spot where it was in the
292 * list of lists to nullnull is the value used to refer to a non-existant object.
293 *
294 * @paramthis is the Javadoc tag for documenting the purpose of parameters row row in which rescued Swimmer resides
295 * @paramthis is the Javadoc tag for documenting the purpose of parameters column column in which the rescued Swimmer resides
296 */
297 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value rescueSwimmer(intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column) {open braces start code blocks and must be matched with a close brace
298 Swimmer curr =this assignment operator makes the left side equal to the right side swimmers.get(row).get(column);
299 setScore(getScore() +adds two numbers together or concatenates Strings together curr.getScore());
300 removeSprite(curr);
301 swimmers.get(row).set(column, nullnull is the value used to refer to a non-existant object);
302 ring.startReady();
303 }close braces end code blocks and must match an earlier open brace
304
305 /**
306 * Initialize the fast swimmer. This is the one which periodically
307 * moves across the top of the screen and is worth a lot of points
308 */
309 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupFastSwimmer() {open braces start code blocks and must be matched with a close brace
310 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions fastSwimmerDX =this assignment operator makes the left side equal to the right side 2 * swimmerDX;
311 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions fastSwimmerDY =this assignment operator makes the left side equal to the right side 2 * swimmerDY;
312 fastSwimmer =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor FastSwimmer(FASTSWIMMER_BASE_SCORE +adds two numbers together or concatenates Strings together level,
313 fastSwimmerDX, fastSwimmerDY);
314 fastSwimmer.setColor(getColor("SCG Red"));
315 fastSwimmer.setScale(objectScale);
316 addSprite(fastSwimmer);
317 }close braces end code blocks and must match an earlier open brace
318
319 /**
320 * Construct the rescuer. Adds the rope, the rescuer, and the ring to
321 * the screen. Note the order: rope first so that when it connects the
322 * midpoints of the two other sprites it is below them, appearing to
323 * come out of them at an appropriate angle.
324 */
325 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupRescuer() {open braces start code blocks and must be matched with a close brace
326 rescuer =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Rescuer(RESCUER_DX, RESCUER_DY, RING_DX, RING_DY);
327 rescuer.setColor(getColor("yellow green"));
328 rescuer.setScale(objectScale);
329 rescuer.setLocation(0.8, 0.9);
330
331 ring =this assignment operator makes the left side equal to the right side rescuer.getRescueRing();
332
333 addSprite(ring.getRope());
334 addSprite(rescuer);
335 addSprite(ring);
336 }close braces end code blocks and must match an earlier open brace
337
338 /**
339 * Populate the the victims ArrayList. victims is an ArrayList of
340 * ArrayLists; create the container forfor is a looping structure for repeatedly executing a block of code containers then, forfor is a looping structure for repeatedly executing a block of code each row,
341 * create a container forfor is a looping structure for repeatedly executing a block of code Victim objects. Thus there is one call to
342 * newnew is used to create objects by calling the constructor before the outer loop (will be called once) and one call to newnew is used to create objects by calling the constructor
343 * inside the outer loop (will be called once per row); these calls
344 * are newnew is used to create objects by calling the constructor ArrayList calls. Then, inside the inner loop, a newnew is used to create objects by calling the constructor Victim
345 * is created and added to the current row.
346 */
347 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupSwimmers() {open braces start code blocks and must be matched with a close brace
348 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions swimmerOffset =this assignment operator makes the left side equal to the right side objectScale / 2.0;
349 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions lowestRowY =this assignment operator makes the left side equal to the right side swimmerOffset +adds two numbers together or concatenates Strings together (ROWS * objectScale);
350 swimmers =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<ArrayList<Swimmer>>this performs a bit-wise right shift();
351 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 row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
352 ArrayList<Swimmer> currentRow =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<Swimmer>();
353 doubledouble is the type for numbers that can contain decimal fractions rowY =this assignment operator makes the left side equal to the right side lowestRowY - (row * objectScale);
354 intint is the type for whole numbers and it is short for integer rowScore =this assignment operator makes the left side equal to the right side row +adds two numbers together or concatenates Strings together 1;// higher row = higher score
355 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 column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
356 Swimmer current =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Swimmer(rowScore, swimmerDX, swimmerDY);
357 current.setScale(objectScale);
358 current.setLocation(swimmerOffset +adds two numbers together or concatenates Strings together (column * objectScale),
359 rowY);
360 addSprite(current);
361 currentRow.add(current);
362 }close braces end code blocks and must match an earlier open brace
363 swimmers.add(currentRow);
364 }close braces end code blocks and must match an earlier open brace
365 }close braces end code blocks and must match an earlier open brace
366
367 /**
368 * Setup the water.
369 */
370 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupWater() {open braces start code blocks and must be matched with a close brace
371 water =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1.0, 0.9);
372 water.setColor(getColor("cyan"));
373 water.setLocation(0.5, 0.45);
374 addSprite(water);
375 }close braces end code blocks and must match an earlier open brace
376 }close braces end code blocks and must match an earlier open brace
377
378 //Uploaded on Mon Mar 29 21:41:46 EDT 2010
|