From FANG
|
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 fang2.core.Game;
004 importimport means to make the classes and/or packages available in this program fang2.core.Sprite;
005 importimport means to make the classes and/or packages available in this program fang2.sprites.OvalSprite;
006 importimport means to make the classes and/or packages available in this program fang2.transformers.HitClassTransformer;
007 importimport means to make the classes and/or packages available in this program fang2.transformers.HitSpriteTransformer;
008 importimport means to make the classes and/or packages available in this program fang2.transformers.HitTarget;
009 importimport means to make the classes and/or packages available in this program fang2.transformers.Shootable;
010 importimport means to make the classes and/or packages available in this program fang2.transformers.TimeLimitedTransformer;
011 importimport means to make the classes and/or packages available in this program fang2.transformers.WrapTransformer;
012
013 importimport means to make the classes and/or packages available in this program java.awt.Color;
014
015 /** A standardized projectile. */
016 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 LittleRoundProjectile
017 extendsextends means to customize or extend the functionality of a class OvalSprite
018 implementsimplements means providing method bodies for the methods declared in the corresponding interface HitTarget {open braces start code blocks and must be matched with a close brace
019 /** the defaultdefault is what is executed when no cases are matched color forfor is a looping structure for repeatedly executing a block of code LRP */
020 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_LRP_COLOR =this assignment operator makes the left side equal to the right side Game.getColor(
021 "orange");
022 /** the defaultdefault is what is executed when no cases are matched size of the LRP in screens */
023 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_LRP_DIAMETER =this assignment operator makes the left side equal to the right side 0.02;
024
025 /** the transformer we use to keep track of hitting a target */
026 privateprivate is used to restrict access to the current class only HitSpriteTransformer targets;
027
028 /**
029 * the transformer we use to keep track of specific sprites as targets
030 */
031 privateprivate is used to restrict access to the current class only HitClassTransformer targetClasses;
032
033 /** where thisthis means the current object (the implicit parameter) projectile records a score (forfor is a looping structure for repeatedly executing a block of code a hit) */
034 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) ScoreSprite score;
035
036 /**
037 * Construct a newnew is used to create objects by calling the constructor little round projectile with the given size (in
038 * screens) and the given color.
039 *
040 * @paramthis is the Javadoc tag for documenting the purpose of parameters diameterInScreens size, in screens, of the projectile
041 * @paramthis is the Javadoc tag for documenting the purpose of parameters color the color the projectile should have
042 */
043 publicpublic is used to indicate unrestricted access (any other class can have access) LittleRoundProjectile(doubledouble is the type for numbers that can contain decimal fractions diameterInScreens, Color color, ScoreSprite score) {open braces start code blocks and must be matched with a close brace
044 super(diameterInScreens, diameterInScreens);
045 setColor(color);
046 thisthis means the current object (the implicit parameter).score =this assignment operator makes the left side equal to the right side score;
047 addTransformer(newnew is used to create objects by calling the constructor WrapTransformer());
048 }close braces end code blocks and must match an earlier open brace
049
050 /**
051 * Construct a newnew is used to create objects by calling the constructor little round projectile with the given size (in
052 * screens) and the defaultdefault is what is executed when no cases are matched color.
053 *
054 * @paramthis is the Javadoc tag for documenting the purpose of parameters diameterInScreens size, in screens, of the projectile
055 */
056 publicpublic is used to indicate unrestricted access (any other class can have access) LittleRoundProjectile(doubledouble is the type for numbers that can contain decimal fractions diameterInScreens, ScoreSprite score) {open braces start code blocks and must be matched with a close brace
057 thisthis means the current object (the implicit parameter)(diameterInScreens, DEFAULT_LRP_COLOR, score);
058 }close braces end code blocks and must match an earlier open brace
059
060 /**
061 * Construct a newnew is used to create objects by calling the constructor little round projectile with the defaultdefault is what is executed when no cases are matched
062 * appearance: orange, 0.02 screens across.
063 */
064 publicpublic is used to indicate unrestricted access (any other class can have access) LittleRoundProjectile(ScoreSprite score) {open braces start code blocks and must be matched with a close brace
065 thisthis means the current object (the implicit parameter)(DEFAULT_LRP_DIAMETER, DEFAULT_LRP_COLOR, score);
066 }close braces end code blocks and must match an earlier open brace
067
068
069 /**
070 * Add a whole classclass is a group of fields and methods used for making objects of sprites as valid targets forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) projectile
071 * @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
072 */
073 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addTarget(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
074 ifif executes the next statement only if the condition in parenthesis evaluates to true (targetClasses ==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
075 targetClasses =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);
076 addTransformer(targetClasses);
077 }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
078 targetClasses.add(targetClass);
079 }close braces end code blocks and must match an earlier open brace
080 }close braces end code blocks and must match an earlier open brace
081
082 /**
083 * Add a specific sprite as a valid target forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) projectile
084 * @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
085 */
086 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addTarget(Sprite target) {open braces start code blocks and must be matched with a close brace
087 ifif executes the next statement only if the condition in parenthesis evaluates to true (targets ==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
088 targets =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor HitSpriteTransformer(target);
089 addTransformer(targets);
090 }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
091 targets.add(target);
092 }close braces end code blocks and must match an earlier open brace
093 }close braces end code blocks and must match an earlier open brace
094
095 /**
096 * Set it so that thisthis means the current object (the implicit parameter) projectile only remains viable forfor is a looping structure for repeatedly executing a block of code a fixed amount of time.
097 * @paramthis is the Javadoc tag for documenting the purpose of parameters seconds
098 */
099 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addTimeToLive(doubledouble is the type for numbers that can contain decimal fractions seconds) {open braces start code blocks and must be matched with a close brace
100 addTransformer(newnew is used to create objects by calling the constructor TimeLimitedTransformer(0.9));
101 }close braces end code blocks and must match an earlier open brace
102
103 /**
104 * What to dodo is part of the do-while looping structure (post condition loop) when we hit a target!this is the not operator, which changes true to false and false to true
105 */
106 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 target) {open braces start code blocks and must be matched with a close brace
107 ifif executes the next statement only if the condition in parenthesis evaluates to true (target instanceofinstanceof is an operator for determining if the types are compatible Shootable) {open braces start code blocks and must be matched with a close brace
108 Shootable shootable =this assignment operator makes the left side equal to the right side (Shootable) target;
109 shootable.shot(thisthis means the current object (the implicit parameter));
110 score.increment();
111 }close braces end code blocks and must match an earlier open brace
112
113 removeFromCanvas();
114 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;
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 //Uploaded on Mon Mar 29 21:41:15 EDT 2010
|
Download/View scg/ch01/spacesprites/LittleRoundProjectile.java