|
001 packagepackage is used to name the directory or folder a class is in scg.ch01.spacesprites;
002
003 importimport means to make the classes and/or packages available in this program java.awt.Color;
004 importimport means to make the classes and/or packages available in this program java.awt.event.KeyEvent;
005
006 importimport means to make the classes and/or packages available in this program fang2.attributes.Location2D;
007 importimport means to make the classes and/or packages available in this program fang2.attributes.Vector2D;
008 importimport means to make the classes and/or packages available in this program fang2.core.Alarm;
009 importimport means to make the classes and/or packages available in this program fang2.core.Game;
010 importimport means to make the classes and/or packages available in this program fang2.core.Sprite;
011 importimport means to make the classes and/or packages available in this program fang2.sprites.PolygonSprite;
012 importimport means to make the classes and/or packages available in this program fang2.transformers.*;
013
014 /**
015 * A triangular spaceship sprite. It can be positioned on the screen,
016 * created in a variety of colors, and the like. By defaultdefault is what is executed when no cases are matched it is
017 * controlled by the keyboard but it can also be constructed as a
018 * non-player controlled space craft. Also, by defaultdefault is what is executed when no cases are matched, it wraps around
019 * the screen at the edges.
020 */
021 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 Ship
022 extendsextends means to customize or extend the functionality of a class PolygonSprite
023 implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm, HitTarget, Shootable, Shooter {open braces start code blocks and must be matched with a close brace
024 /** how much speed up does the acceleration add forfor is a looping structure for repeatedly executing a block of code the ship? */
025 privateprivate is used to restrict access to the current class only 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 ACCELERATION_SCREENS_PER_SECOND_SQUARED =this assignment operator makes the left side equal to the right side
026 2.0;
027
028 /** the alarm interval in seconds; used forfor is a looping structure for repeatedly executing a block of code counting down timers */
029 privateprivate is used to restrict access to the current class only 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 ALARM_INTERVAL =this assignment operator makes the left side equal to the right side 0.25;
030
031 /** the turning speed of thisthis means the current object (the implicit parameter) ship; in radians/second */
032 privateprivate is used to restrict access to the current class only 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 ANGULAR_VELOCITY_DEGREES_PER_SECOND =this assignment operator makes the left side equal to the right side 300;
033
034 /** number of lives a ship gets by defaultdefault is what is executed when no cases are matched */
035 privateprivate is used to restrict access to the current class only 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 DEFAULT_LIFE_COUNT =this assignment operator makes the left side equal to the right side 3;
036
037 /** defaultdefault is what is executed when no cases are matched size (in screen fraction) of a newly created ship */
038 privateprivate is used to restrict access to the current class only 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 DEFAULT_SCALE =this assignment operator makes the left side equal to the right side 0.1;
039
040 /** the color of the ship (ifif executes the next statement only if the condition in parenthesis evaluates to true there is no other color specified */
041 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) Color DEFAULT_SHIP_COLOR =this assignment operator makes the left side equal to the right side Game.getColor(
042 "SCG Red");
043
044 /** gun location relative to ship location */
045 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) Location2D GUN_LOCATION =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Location2D(0.7, 0);
046
047 /** what is the speed limit forfor is a looping structure for repeatedly executing a block of code the ship? */
048 privateprivate is used to restrict access to the current class only 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 MAX_VELOCITY_SCREENS_PER_SECOND =this assignment operator makes the left side equal to the right side 0.25;
049 // ----- Data for individual ships -----
050 // ---------- Collision Control
051
052 /** classes of sprites which can hit us tracked here */
053 privateprivate is used to restrict access to the current class only HitClassTransformer collisionClasses;
054
055 /** specific sprites which can hit us tracked here */
056 privateprivate is used to restrict access to the current class only HitSpriteTransformer collisions;
057
058 // ---------- Gameplay Variables: use setShootingDelay and
059 // setImmunityDelay to change timing; extraLife to
060 // add an extra life
061 /** seconds, after hit, whilewhile is a looping structure for executing code repeatedly ship is immune from damage */
062 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions immunityDelay;
063
064 /** time, in seconds, remaining on current immunity */
065 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions immunityDelayRemaining;
066 // ---------- Score/Lives remaining display
067
068 /** number of remaining lives */
069 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) ScoreSprite lives;
070
071 /** game we are part of */
072 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) Game myGame;
073
074 /** score (forfor is a looping structure for repeatedly executing a block of code the projectiles) */
075 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) ScoreSprite score;
076
077 /** time, in seconds, between shots */
078 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions shootingDelay;
079
080 /** time, in seconds, remaining before we can shoot again */
081 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions shootingDelayRemaining;
082
083 // --------- Targeting Data: sprite/class for projectiles
084 /** the specific sprite thisthis means the current object (the implicit parameter) ship's projectiles hit */
085 privateprivate is used to restrict access to the current class only Sprite target;
086
087 /** the classclass is a group of fields and methods used for making objects of objects thisthis means the current object (the implicit parameter) ship's projectiles hit */
088 privateprivate is used to restrict access to the current class only Class<? extendsextends means to customize or extend the functionality of a class Sprite> targetClass;
089
090 // ----- Command Definitions (methods) -----
091 /**
092 * Construct a {open braces start code blocks and must be matched with a close brace@link Ship}close braces end code blocks and must match an earlier open brace associated with the given game.
093 *
094 * @paramthis is the Javadoc tag for documenting the purpose of parameters myGame the game to which thisthis means the current object (the implicit parameter) ship belongs
095 */
096 publicpublic is used to indicate unrestricted access (any other class can have access) Ship(Game myGame) {open braces start code blocks and must be matched with a close brace
097 thisthis means the current object (the implicit parameter)(myGame, DEFAULT_SHIP_COLOR, DEFAULT_SCALE, DEFAULT_LIFE_COUNT);
098 addAllTransformers();
099 }close braces end code blocks and must match an earlier open brace
100
101 /**
102 * Construct a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link Ship}close braces end code blocks and must match an earlier open brace associated with the given game and
103 * having the given color.
104 *
105 * @paramthis is the Javadoc tag for documenting the purpose of parameters myGame the {open braces start code blocks and must be matched with a close brace@link Game}close braces end code blocks and must match an earlier open brace to which the ship belongs
106 * @paramthis is the Javadoc tag for documenting the purpose of parameters color the {open braces start code blocks and must be matched with a close brace@link Color}close braces end code blocks and must match an earlier open brace to display the ship
107 */
108 publicpublic is used to indicate unrestricted access (any other class can have access) Ship(Game myGame, Color color) {open braces start code blocks and must be matched with a close brace
109 thisthis means the current object (the implicit parameter)(myGame, color, DEFAULT_SCALE, DEFAULT_LIFE_COUNT);
110 }close braces end code blocks and must match an earlier open brace
111
112 /**
113 * Construct a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link Ship}close braces end code blocks and must match an earlier open brace associated with the given game, using
114 * the given scale and color.
115 *
116 * @paramthis is the Javadoc tag for documenting the purpose of parameters myGame the {open braces start code blocks and must be matched with a close brace@link Game}close braces end code blocks and must match an earlier open brace to which it is associated
117 * @paramthis is the Javadoc tag for documenting the purpose of parameters color the color to fill the ship with
118 * @paramthis is the Javadoc tag for documenting the purpose of parameters scale the scale (in percentages of a screen)
119 * @paramthis is the Javadoc tag for documenting the purpose of parameters lives the number of lives the ship has
120 */
121 publicpublic is used to indicate unrestricted access (any other class can have access) Ship(Game myGame, Color color, doubledouble is the type for numbers that can contain decimal fractions scale, intint is the type for whole numbers and it is short for integer lives) {open braces start code blocks and must be matched with a close brace
122 super(0.5, 0, -0.5, -0.25, -0.5, 0.25);
123 thisthis means the current object (the implicit parameter).myGame =this assignment operator makes the left side equal to the right side myGame;
124 thisthis means the current object (the implicit parameter).setScale(scale);
125 thisthis means the current object (the implicit parameter).setColor(color);
126
127 thisthis means the current object (the implicit parameter).lives =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ScoreSprite(lives);
128 thisthis means the current object (the implicit parameter).lives.hide();
129 Game.getCurrentGame().addSprite(lives);
130
131 thisthis means the current object (the implicit parameter).score =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ScoreSprite(0);
132 thisthis means the current object (the implicit parameter).score.translateX(0.5);// move score over
133 thisthis means the current object (the implicit parameter).score.setColor(myGame.getColor("gray"));
134 thisthis means the current object (the implicit parameter).score.hide();
135
136 thisthis means the current object (the implicit parameter).addTransformer(newnew is used to create objects by calling the constructor WrapTransformer());
137 thisthis means the current object (the implicit parameter).myGame.scheduleRelative(thisthis means the current object (the implicit parameter), ALARM_INTERVAL);
138 }close braces end code blocks and must match an earlier open brace
139
140 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act() {open braces start code blocks and must be matched with a close brace
141 ifif executes the next statement only if the condition in parenthesis evaluates to true (immunityDelayRemaining > 0.0) {open braces start code blocks and must be matched with a close brace
142 immunityDelayRemaining -=this decreases the variable on the left by the value on the right ALARM_INTERVAL;
143 }close braces end code blocks and must match an earlier open brace
144 ifif executes the next statement only if the condition in parenthesis evaluates to true (shootingDelayRemaining > 0.0) {open braces start code blocks and must be matched with a close brace
145 shootingDelayRemaining -=this decreases the variable on the left by the value on the right ALARM_INTERVAL;
146 }close braces end code blocks and must match an earlier open brace
147 Game.getCurrentGame().scheduleRelative(thisthis means the current object (the implicit parameter), ALARM_INTERVAL);
148 }close braces end code blocks and must match an earlier open brace
149
150 /**
151 * Construct all of the transformers that make thisthis means the current object (the implicit parameter) ship move
152 * according to the keyboard
153 */
154 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addAllTransformers() {open braces start code blocks and must be matched with a close brace
155 addKeyboardTransformers();
156 addShooterTransformers();
157 }close braces end code blocks and must match an earlier open brace
158
159 /**
160 * Add a whole classclass is a group of fields and methods used for making objects of sprites as "rocks" that damages thisthis means the current object (the implicit parameter) ship
161 *
162 * @paramthis is the Javadoc tag for documenting the purpose of parameters targetClass the {open braces start code blocks and must be matched with a close brace@link Sprite}close braces end code blocks and must match an earlier open brace derived classclass is a group of fields and methods used for making objects to shoot at
163 */
164 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addCollision(Class<? extendsextends means to customize or extend the functionality of a class Sprite> targetClass) {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 (collisionClasses ==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
166 collisionClasses =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor HitClassTransformer(thisthis means the current object (the implicit parameter), targetClass);
167 addTransformer(collisionClasses);
168 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
169 collisionClasses.add(targetClass);
170 }close braces end code blocks and must match an earlier open brace
171 }close braces end code blocks and must match an earlier open brace
172
173 /**
174 * Add a specific sprite as a "rock" that damages thisthis means the current object (the implicit parameter) ship
175 *
176 * @paramthis is the Javadoc tag for documenting the purpose of parameters target the {open braces start code blocks and must be matched with a close brace@link Sprite}close braces end code blocks and must match an earlier open brace to shoot
177 */
178 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addCollision(Sprite target) {open braces start code blocks and must be matched with a close brace
179 ifif executes the next statement only if the condition in parenthesis evaluates to true (collisions ==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
180 collisions =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor HitSpriteTransformer(target);
181 addTransformer(collisions);
182 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
183 collisions.add(target);
184 }close braces end code blocks and must match an earlier open brace
185 }close braces end code blocks and must match an earlier open brace
186
187 /**
188 * Associate the ship with rotation and acceleration by pressing the
189 * right keys.
190 */
191 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addKeyboardTransformers() {open braces start code blocks and must be matched with a close brace
192 AccelerationAheadTransformer velocity =this assignment operator makes the left side equal to the right side
193 newnew is used to create objects by calling the constructor AccelerationAheadTransformer(
194 ACCELERATION_SCREENS_PER_SECOND_SQUARED);
195 velocity.setMaximumMagnitude(MAX_VELOCITY_SCREENS_PER_SECOND);
196
197 KeyboardTransformer driveKeys =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor KeyboardTransformer(velocity);
198 driveKeys.addPlusKey(KeyEvent.VK_UP);
199 driveKeys.addPlusKey(KeyEvent.VK_KP_UP);
200 // uncomment (remove "//") following lines to provide backup
201 // acceleration driveKeys.addMinusKey(KeyEvent.VK_DOWN);
202 // driveKeys.addMinusKey(KeyEvent.VK_KP_DOWN);
203 thisthis means the current object (the implicit parameter).addTransformer(driveKeys);
204
205 SpinTransformer turn =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor SpinTransformer(
206 ANGULAR_VELOCITY_DEGREES_PER_SECOND);
207 turn.setResetToNominal(truetrue is the boolean value that is the opposite of false);
208
209 KeyboardTransformer turnKeys =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor KeyboardTransformer(turn);
210 turnKeys.addPlusKey(KeyEvent.VK_RIGHT);
211 turnKeys.addPlusKey(KeyEvent.VK_KP_RIGHT);
212 turnKeys.addMinusKey(KeyEvent.VK_LEFT);
213 turnKeys.addMinusKey(KeyEvent.VK_KP_LEFT);
214 thisthis means the current object (the implicit parameter).addTransformer(turnKeys);
215 }close braces end code blocks and must match an earlier open brace
216
217 /**
218 * Associate the ship with shooting by pressing the correct key.
219 */
220 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addShooterTransformers() {open braces start code blocks and must be matched with a close brace
221 ShooterTransformer bang =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ShooterTransformer();
222 KeyboardTransformer shoot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor KeyboardTransformer(bang);
223 shoot.addPlusKey(KeyEvent.VK_SPACE);
224 thisthis means the current object (the implicit parameter).addTransformer(shoot);
225 }close braces end code blocks and must match an earlier open brace
226
227 /**
228 * Give the ship an extra life. Usually the player's ship.
229 */
230 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value extraLife() {open braces start code blocks and must be matched with a close brace
231 lives.increment();
232 }close braces end code blocks and must match an earlier open brace
233
234 /**
235 * @returnnull the immunityDelay
236 */
237 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getImmunityDelay() {open braces start code blocks and must be matched with a close brace
238 returnreturn means to provide the result of the method and/or cease execution of the method immediately immunityDelay;
239 }close braces end code blocks and must match an earlier open brace
240
241 /**
242 * Get the score sprite holding the life count forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) ship.
243 *
244 * @returnnull the {open braces start code blocks and must be matched with a close brace@link ScoreSprite}close braces end code blocks and must match an earlier open brace counting lives.
245 */
246 publicpublic is used to indicate unrestricted access (any other class can have access) ScoreSprite getLives() {open braces start code blocks and must be matched with a close brace
247 returnreturn means to provide the result of the method and/or cease execution of the method immediately lives;
248 }close braces end code blocks and must match an earlier open brace
249
250 /**
251 * Get a bullet. Used to shoot the guns.
252 */
253 publicpublic is used to indicate unrestricted access (any other class can have access) LittleRoundProjectile getProjectile() {open braces start code blocks and must be matched with a close brace
254 ifif executes the next statement only if the condition in parenthesis evaluates to true (shootingDelayRemaining <=this evaluates to true if the left side is not more than the right side 0) {open braces start code blocks and must be matched with a close brace
255 // Calculate where the shot should originate.
256 // gunLocation is location, relative to original sized sprite
257 // rotate, scale, add to our location
258 Vector2D rotatedX =this assignment operator makes the left side equal to the right side getFacingVector().normalize();
259 Vector2D rotatedY =this assignment operator makes the left side equal to the right side rotatedX.getNormal();
260 Location2D shotDelta =this assignment operator makes the left side equal to the right side GUN_LOCATION.multiply(getScale());
261 Location2D shotLocation =this assignment operator makes the left side equal to the right side getLocation().add(rotatedX.multiply(
262 shotDelta.getX()).addTo(
263 rotatedY.multiply(shotDelta.getY())));
264
265 LittleRoundProjectile projectile =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LittleRoundProjectile(
266 score);
267 projectile.setLocation(shotLocation);
268 projectile.setRotation(getRotation());// shoot straight ahead
269 projectile.addTransformer(newnew is used to create objects by calling the constructor SpeedAheadTransformer(1.0));
270 projectile.addTimeToLive(0.9);
271 projectile.scale(1.5);
272 projectile.setColor(Game.getColor("orange red"));
273 ifif executes the next statement only if the condition in parenthesis evaluates to true (targetClass !=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
274 projectile.addTarget(targetClass);
275 }close braces end code blocks and must match an earlier open brace
276 ifif executes the next statement only if the condition in parenthesis evaluates to true (target !=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
277 projectile.addTarget(target);
278 }close braces end code blocks and must match an earlier open brace
279 shootingDelayRemaining =this assignment operator makes the left side equal to the right side shootingDelay;
280 returnreturn means to provide the result of the method and/or cease execution of the method immediately projectile;
281 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
282 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
283 }close braces end code blocks and must match an earlier open brace
284 }close braces end code blocks and must match an earlier open brace
285
286 /**
287 * Get the score display sprite
288 *
289 * @returnnull the score display
290 */
291 publicpublic is used to indicate unrestricted access (any other class can have access) ScoreSprite getScore() {open braces start code blocks and must be matched with a close brace
292 returnreturn means to provide the result of the method and/or cease execution of the method immediately score;
293 }close braces end code blocks and must match an earlier open brace
294
295 /**
296 * @returnnull the shootingDelay
297 */
298 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getShootingDelay() {open braces start code blocks and must be matched with a close brace
299 returnreturn means to provide the result of the method and/or cease execution of the method immediately shootingDelay;
300 }close braces end code blocks and must match an earlier open brace
301
302 /**
303 * @returnnull the target
304 */
305 publicpublic is used to indicate unrestricted access (any other class can have access) Sprite getTarget() {open braces start code blocks and must be matched with a close brace
306 returnreturn means to provide the result of the method and/or cease execution of the method immediately target;
307 }close braces end code blocks and must match an earlier open brace
308
309 /**
310 * @returnnull the targetClass
311 */
312 publicpublic is used to indicate unrestricted access (any other class can have access) Class<? extendsextends means to customize or extend the functionality of a class Sprite> getTargetClass() {open braces start code blocks and must be matched with a close brace
313 returnreturn means to provide the result of the method and/or cease execution of the method immediately targetClass;
314 }close braces end code blocks and must match an earlier open brace
315
316 /**
317 * Hide the remaining lives counter
318 */
319 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value hideLives() {open braces start code blocks and must be matched with a close brace
320 lives.hide();
321 }close braces end code blocks and must match an earlier open brace
322
323 /**
324 * Hide the score display on the screen
325 */
326 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value hideScore() {open braces start code blocks and must be matched with a close brace
327 score.hide();
328 }close braces end code blocks and must match an earlier open brace
329
330 /**
331 * What happens when thisthis means the current object (the implicit parameter) object collides with some other object it is
332 * programmed to interact with? Check forfor is a looping structure for repeatedly executing a block of code immunity; ifif executes the next statement only if the condition in parenthesis evaluates to true not immune,
333 * make it react to us (so two ships hitting each react once) avoid
334 * recursion trap by setting immunityDelay before call to other object
335 * (it will make us react but next time we are immune so it only goes:
336 * A.react -> B.react -> A.react (when A and B are thisthis means the current object (the implicit parameter) and other on
337 * the first call.
338 */
339 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false react(Sprite other) {open braces start code blocks and must be matched with a close brace
340 ifif executes the next statement only if the condition in parenthesis evaluates to true (immunityDelayRemaining <=this evaluates to true if the left side is not more than the right side 0.0) {open braces start code blocks and must be matched with a close brace
341 immunityDelayRemaining =this assignment operator makes the left side equal to the right side 1.0;
342 HitTarget ht =this assignment operator makes the left side equal to the right side (HitTarget) other;
343 ifif executes the next statement only if the condition in parenthesis evaluates to true (ht !=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
344 ht.react(thisthis means the current object (the implicit parameter));
345 }close braces end code blocks and must match an earlier open brace
346 subtractALife();
347 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
348 }close braces end code blocks and must match an earlier open brace
349 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
350 }close braces end code blocks and must match an earlier open brace
351
352 /**
353 * @paramthis is the Javadoc tag for documenting the purpose of parameters immunityDelay the immunityDelay to set
354 */
355 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setImmunityDelay(doubledouble is the type for numbers that can contain decimal fractions immunityDelay) {open braces start code blocks and must be matched with a close brace
356 thisthis means the current object (the implicit parameter).immunityDelay =this assignment operator makes the left side equal to the right side immunityDelay;
357 }close braces end code blocks and must match an earlier open brace
358
359 /**
360 * @paramthis is the Javadoc tag for documenting the purpose of parameters shootingDelay the shootingDelay to set
361 */
362 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setShootingDelay(doubledouble is the type for numbers that can contain decimal fractions shootingDelay) {open braces start code blocks and must be matched with a close brace
363 thisthis means the current object (the implicit parameter).shootingDelay =this assignment operator makes the left side equal to the right side shootingDelay;
364 }close braces end code blocks and must match an earlier open brace
365
366 /**
367 * @paramthis is the Javadoc tag for documenting the purpose of parameters targetClass the targetClass to set
368 */
369 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setTarget(Class<? extendsextends means to customize or extend the functionality of a class Sprite> targetClass) {open braces start code blocks and must be matched with a close brace
370 thisthis means the current object (the implicit parameter).targetClass =this assignment operator makes the left side equal to the right side targetClass;
371 }close braces end code blocks and must match an earlier open brace
372
373 /**
374 * @paramthis is the Javadoc tag for documenting the purpose of parameters target the target to set
375 */
376 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setTarget(Sprite target) {open braces start code blocks and must be matched with a close brace
377 thisthis means the current object (the implicit parameter).target =this assignment operator makes the left side equal to the right side target;
378 }close braces end code blocks and must match an earlier open brace
379
380 /**
381 * What happens when thisthis means the current object (the implicit parameter) ship is shot?
382 */
383 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value shot(Sprite shooter) {open braces start code blocks and must be matched with a close brace
384 subtractALife();
385 }close braces end code blocks and must match an earlier open brace
386
387 /**
388 * Make the lives counter visible.
389 */
390 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value showLives() {open braces start code blocks and must be matched with a close brace
391 lives.show();
392 }close braces end code blocks and must match an earlier open brace
393
394 /**
395 * Make the score display visible
396 */
397 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value showScore() {open braces start code blocks and must be matched with a close brace
398 score.show();
399 }close braces end code blocks and must match an earlier open brace
400
401 /**
402 * Remove a life. Decrement the life counter and ifif executes the next statement only if the condition in parenthesis evaluates to true the life count
403 * goes to 0, remove the ship from the game. Also reset the immunity
404 * timer.
405 */
406 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value subtractALife() {open braces start code blocks and must be matched with a close brace
407 lives.decrement();
408
409 ifif executes the next statement only if the condition in parenthesis evaluates to true (lives.getScore() <=this evaluates to true if the left side is not more than the right side 0) {open braces start code blocks and must be matched with a close brace
410 lives.removeFromCanvas();
411 removeFromCanvas();
412 }close braces end code blocks and must match an earlier open brace
413
414 immunityDelayRemaining =this assignment operator makes the left side equal to the right side immunityDelay;
415 }close braces end code blocks and must match an earlier open brace
416 }close braces end code blocks and must match an earlier open brace
417
418 //Uploaded on Mon Mar 29 21:40:58 EDT 2010
|