|
001 packagepackage is used to name the directory or folder a class is in Nick;
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 /**
009 * A simple, fun game I made using the FANG Engine.
010 * @authorthis is the Javadoc tag for documenting who created the source code Nmckee
011 */
012 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Wackadot extendsextends means to customize or extend the functionality of a class GameLoop
013 {open braces start code blocks and must be matched with a close brace
014 privateprivate is used to restrict access to the current class only Sprite dot;
015 privateprivate is used to restrict access to the current class only Sprite redDot;
016 privateprivate is used to restrict access to the current class only Sprite blueDot;
017 privateprivate is used to restrict access to the current class only Sprite gDot;
018 privateprivate is used to restrict access to the current class only Sprite orangeDot;
019 privateprivate is used to restrict access to the current class only Sprite whiteDot;
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 score=this assignment operator makes the left side equal to the right side0;
029 timeLeft=this assignment operator makes the left side equal to the right side20;
030 makeSprites();
031 addSprites();
032 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
033 setHelp("resources/WackadotHelp.html");
034 }close braces end code blocks and must match an earlier open brace
035
036 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
037 Sound sound=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("trainwhistle.wav")
038 {open braces start code blocks and must be matched with a close brace
039 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
040 {open braces start code blocks and must be matched with a close brace
041 timeLeft--this is the decrement operator, which decreases the variable by 1;
042 updateTimer();
043 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
044 {open braces start code blocks and must be matched with a close brace
045 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
046 }close braces end code blocks and must match an earlier open brace
047 }close braces end code blocks and must match an earlier open brace
048 }close braces end code blocks and must match an earlier open brace
049
050 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
051 {open braces start code blocks and must be matched with a close brace
052 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
053 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
054
055 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
056 dot.setScale(0.05);
057 dot.setLocation(0.5, 0.5);
058 dot.setColor(Color.RED);
059
060 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);
061 redDot.setScale(0.1);
062 redDot.setLocation(
063 random.nextDouble(),
064 random.nextDouble());
065 redDot.setColor(Color.RED);
066
067 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);
068 blueDot.setScale(0.2);
069 blueDot.setLocation(
070 random.nextDouble(),
071 random.nextDouble());
072 blueDot.setColor(Color.BLUE);
073
074 gDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
075 gDot.setScale(0.3);
076 gDot.setLocation(
077 random.nextDouble(),
078 random.nextDouble());
079 gDot.setColor(Color.GREEN);
080
081 orangeDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
082 orangeDot.setScale(0.4);
083 orangeDot.setLocation(
084 random.nextDouble(),
085 random.nextDouble());
086 orangeDot.setColor(Color.ORANGE);
087
088 whiteDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
089 whiteDot.setScale(0.3);
090 whiteDot.setLocation(
091 random.nextDouble(),
092 random.nextDouble());
093 whiteDot.setColor(Color.WHITE);
094
095 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);
096 scoreSprite.setHeight(0.1);
097 scoreSprite.rightJustify();
098 scoreSprite.topJustify();
099 scoreSprite.setLocation(1, 0);
100
101 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);
102 timerSprite.leftJustify();
103 timerSprite.topJustify();
104 timerSprite.setHeight(0.1);
105 timerSprite.setLocation(0, 0);
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 addSprites()
109 {open braces start code blocks and must be matched with a close brace
110 canvas.addSprite(dot);
111 canvas.addSprite(redDot);
112 canvas.addSprite(blueDot);
113 canvas.addSprite(gDot);
114 canvas.addSprite(orangeDot);
115 canvas.addSprite(whiteDot);
116 canvas.addSprite(scoreSprite);
117 canvas.addSprite(timerSprite);
118 }close braces end code blocks and must match an earlier open brace
119
120 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
121 {open braces start code blocks and must be matched with a close brace
122 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
123 }close braces end code blocks and must match an earlier open brace
124
125 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
126 {open braces start code blocks and must be matched with a close brace
127 sprite.setLocation(
128 random.nextDouble(),
129 random.nextDouble());
130 }close braces end code blocks and must match an earlier open brace
131
132 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
133 {open braces start code blocks and must be matched with a close brace
134 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
135 }close braces end code blocks and must match an earlier open brace
136
137 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
138 {open braces start code blocks and must be matched with a close brace
139 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
140 {open braces start code blocks and must be matched with a close brace
141 repositionRandomly(blueDot);
142 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
143 {open braces start code blocks and must be matched with a close brace
144 dot.setColor(Color.ORANGE);
145 score++this is the increment operator, which increases the variable by 1;
146 }close braces end code blocks and must match an earlier open brace
147 elseelse is what happens when the if condition is false
148 {open braces start code blocks and must be matched with a close brace
149 score--this is the decrement operator, which decreases the variable by 1;
150 }close braces end code blocks and must match an earlier open brace
151 updateScore();
152 }close braces end code blocks and must match an earlier open brace
153 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
154 {open braces start code blocks and must be matched with a close brace
155 repositionRandomly(redDot);
156 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
157 {open braces start code blocks and must be matched with a close brace
158 dot.setColor(Color.GREEN);
159 score++this is the increment operator, which increases the variable by 1;
160 }close braces end code blocks and must match an earlier open brace
161 elseelse is what happens when the if condition is false
162 {open braces start code blocks and must be matched with a close brace
163 score--this is the decrement operator, which decreases the variable by 1;
164 }close braces end code blocks and must match an earlier open brace
165 updateScore();
166 }close braces end code blocks and must match an earlier open brace
167
168 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(gDot))
169 {open braces start code blocks and must be matched with a close brace
170 repositionRandomly(gDot);
171 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.GREEN))
172 {open braces start code blocks and must be matched with a close brace
173 dot.setColor(Color.BLUE);
174 score++this is the increment operator, which increases the variable by 1;
175 }close braces end code blocks and must match an earlier open brace
176 elseelse is what happens when the if condition is false
177 {open braces start code blocks and must be matched with a close brace
178 score--this is the decrement operator, which decreases the variable by 1;
179 }close braces end code blocks and must match an earlier open brace
180 updateScore();
181 }close braces end code blocks and must match an earlier open brace
182
183 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(orangeDot))
184 {open braces start code blocks and must be matched with a close brace
185 repositionRandomly(orangeDot);
186 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.ORANGE))
187 {open braces start code blocks and must be matched with a close brace
188 dot.setColor(Color.WHITE);
189 score++this is the increment operator, which increases the variable by 1;
190 }close braces end code blocks and must match an earlier open brace
191 elseelse is what happens when the if condition is false
192 {open braces start code blocks and must be matched with a close brace
193 score--this is the decrement operator, which decreases the variable by 1;
194 }close braces end code blocks and must match an earlier open brace
195 updateScore();
196 }close braces end code blocks and must match an earlier open brace
197
198 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(whiteDot))
199 {open braces start code blocks and must be matched with a close brace
200 repositionRandomly(whiteDot);
201 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.WHITE))
202 {open braces start code blocks and must be matched with a close brace
203 dot.setColor(Color.RED);
204 score++this is the increment operator, which increases the variable by 1;
205 }close braces end code blocks and must match an earlier open brace
206 elseelse is what happens when the if condition is false
207 {open braces start code blocks and must be matched with a close brace
208 score--this is the decrement operator, which decreases the variable by 1;
209 }close braces end code blocks and must match an earlier open brace
210 updateScore();
211 }close braces end code blocks and must match an earlier open brace
212 }close braces end code blocks and must match an earlier open brace
213
214 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)
215 {open braces start code blocks and must be matched with a close brace
216 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
217 {open braces start code blocks and must be matched with a close brace
218 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
219 getPlayer().getMouse().getLocation();
220 dot.setLocation(mouse);
221 handleCollisions();
222 }close braces end code blocks and must match an earlier open brace
223
224 }close braces end code blocks and must match an earlier open brace
225
226 }close braces end code blocks and must match an earlier open brace
|