|
001 packagepackage is used to name the directory or folder a class is in ChrisGarrett.wackadot;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007
008 /**This is a fun, simple game I made using
009 * the FANG Engine.
010 * @authorthis is the Javadoc tag for documenting who created the source code Christopher Garrett
011 */
012
013 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 Wackadot extendsextends means to customize or extend the functionality of a class GameLoop
014 {open braces start code blocks and must be matched with a close brace
015 privateprivate is used to restrict access to the current class only Sprite dot3;
016 privateprivate is used to restrict access to the current class only Sprite dot;
017 privateprivate is used to restrict access to the current class only Sprite dot2;
018 privateprivate is used to restrict access to the current class only Sprite redDot;
019 privateprivate is used to restrict access to the current class only Sprite blueDot;
020 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
021 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer score;
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 timeLeft;
023 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
024
025
026 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
027 {open braces start code blocks and must be matched with a close brace
028 timeLeft=this assignment operator makes the left side equal to the right side25;
029 score=this assignment operator makes the left side equal to the right side0;
030 makeSprites();
031 addSprites();
032 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
033 }close braces end code blocks and must match an earlier open brace
034 classclass is a group of fields and methods used for making objects TimeUpdater implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
035 {open braces start code blocks and must be matched with a close brace
036 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
037 {open braces start code blocks and must be matched with a close brace
038 timeLeft--this is the decrement operator, which decreases the variable by 1;
039 updateTimer();
040 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
041 {open braces start code blocks and must be matched with a close brace
042 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
043 }close braces end code blocks and must match an earlier open brace
044 }close braces end code blocks and must match an earlier open brace
045 }close braces end code blocks and must match an earlier open brace
046
047 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
048 {open braces start code blocks and must be matched with a close brace
049 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
050 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
051
052 dot3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
053 dot3.setScale(0.2);
054 dot3.setLocation(
055 random.nextDouble(),
056 random.nextDouble());
057 dot3.setColor(Color.ORANGE);
058
059 dot2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
060 dot2.setScale(0.3);
061 dot2.setLocation(
062 random.nextDouble(),
063 random.nextDouble());
064 dot2.setColor(Color.GREEN);
065
066 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
067 dot.setScale(0.1);
068 dot.setLocation(0.5, 0.5);
069 dot.setColor(Color.RED);
070
071 redDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
072 redDot.setScale(0.1);
073 redDot.setLocation(
074 random.nextDouble(),
075 random.nextDouble());
076 redDot.setColor(Color.RED);
077
078 blueDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
079 blueDot.setScale(0.5);
080 blueDot.setLocation(
081 random.nextDouble(),
082 random.nextDouble());
083 blueDot.setColor(Color.BLUE);
084 scoreSprite=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 togetherscore);
085 scoreSprite.setHeight(0.1);
086 scoreSprite.rightJustify();
087 scoreSprite.topJustify();
088 scoreSprite.setLocation(1, 0);
089 timerSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
090 timerSprite.leftJustify();
091 timerSprite.topJustify();
092 timerSprite.setHeight(0.1);
093 timerSprite.setLocation(0, 0);
094 }close braces end code blocks and must match an earlier open brace
095
096
097 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
098 {open braces start code blocks and must be matched with a close brace
099 canvas.addSprite(blueDot);
100 canvas.addSprite(dot);
101 canvas.addSprite(dot2);
102 canvas.addSprite(dot3);
103 canvas.addSprite(redDot);
104 canvas.addSprite(scoreSprite);
105 canvas.addSprite(timerSprite);
106 }close braces end code blocks and must match an earlier open brace
107
108 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
109 {open braces start code blocks and must be matched with a close brace
110 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
111 }close braces end code blocks and must match an earlier open brace
112
113 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advanceFrame(doubledouble is the type for numbers that can contain decimal fractions timePassed)
114 {open braces start code blocks and must be matched with a close brace
115 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
116 {open braces start code blocks and must be matched with a close brace
117 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
118 getPlayer().getMouse().getLocation();
119 dot.setLocation(mouse);
120 handleCollisions();
121 }close braces end code blocks and must match an earlier open brace
122 }close braces end code blocks and must match an earlier open brace
123 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
124 {open braces start code blocks and must be matched with a close brace
125 sprite.setLocation(
126 random.nextDouble(),
127 random.nextDouble());
128 }close braces end code blocks and must match an earlier open brace
129 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
130 {open braces start code blocks and must be matched with a close brace
131 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
132 }close braces end code blocks and must match an earlier open brace
133
134 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
135 {open braces start code blocks and must be matched with a close brace
136 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
137 {open braces start code blocks and must be matched with a close brace
138 repositionRandomly(blueDot);
139 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
140 {open braces start code blocks and must be matched with a close brace
141 dot.setColor(Color.GREEN);
142 score++this is the increment operator, which increases the variable by 1;
143 }close braces end code blocks and must match an earlier open brace
144 elseelse is what happens when the if condition is false
145 {open braces start code blocks and must be matched with a close brace
146 score--this is the decrement operator, which decreases the variable by 1;
147 }close braces end code blocks and must match an earlier open brace
148 updateScore();
149 }close braces end code blocks and must match an earlier open brace
150 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
151 {open braces start code blocks and must be matched with a close brace
152 repositionRandomly(redDot);
153 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
154 {open braces start code blocks and must be matched with a close brace
155 dot.setColor(Color.BLUE);
156 score++this is the increment operator, which increases the variable by 1;
157 }close braces end code blocks and must match an earlier open brace
158 elseelse is what happens when the if condition is false
159 {open braces start code blocks and must be matched with a close brace
160 score--this is the decrement operator, which decreases the variable by 1;
161 }close braces end code blocks and must match an earlier open brace
162 updateScore();
163 }close braces end code blocks and must match an earlier open brace
164 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(dot2))
165 {open braces start code blocks and must be matched with a close brace
166 repositionRandomly(dot2);
167 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.GREEN))
168 {open braces start code blocks and must be matched with a close brace
169 dot.setColor(Color.ORANGE);
170 score++this is the increment operator, which increases the variable by 1;
171 }close braces end code blocks and must match an earlier open brace
172 elseelse is what happens when the if condition is false
173 {open braces start code blocks and must be matched with a close brace
174 score--this is the decrement operator, which decreases the variable by 1;
175 }close braces end code blocks and must match an earlier open brace
176 updateScore();
177 }close braces end code blocks and must match an earlier open brace
178 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(dot3))
179 {open braces start code blocks and must be matched with a close brace
180 repositionRandomly(dot3);
181 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.ORANGE))
182 {open braces start code blocks and must be matched with a close brace
183 dot.setColor(Color.RED);
184 score++this is the increment operator, which increases the variable by 1;
185 }close braces end code blocks and must match an earlier open brace
186 elseelse is what happens when the if condition is false
187 {open braces start code blocks and must be matched with a close brace
188 score--this is the decrement operator, which decreases the variable by 1;
189 }close braces end code blocks and must match an earlier open brace
190 updateScore();
191 }close braces end code blocks and must match an earlier open brace
192 }close braces end code blocks and must match an earlier open brace
193 }close braces end code blocks and must match an earlier open brace
194
|