|
001 packagepackage is used to name the directory or folder a class is in Charles;
002 //start auto-imports
003 importimport means to make the classes and/or packages available in this program java.util.*;
004 //end auto-imports
005
006 importimport means to make the classes and/or packages available in this program fang.*;
007 importimport means to make the classes and/or packages available in this program java.awt.*;
008 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
009
010 /**
011 * All about my game.
012 * @authorthis is the Javadoc tag for documenting who created the source code Charles
013 * @authorthis is the Javadoc tag for documenting who created the source code Chanelle
014 */
015 /** used the "getColorName()" method after looking at Frank Anderson's game*/
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 Breakout extendsextends means to customize or extend the functionality of a class Game
017 {open braces start code blocks and must be matched with a close brace
018 privateprivate is used to restrict access to the current class only ArrayList<Sprite> allBricks;
019 privateprivate is used to restrict access to the current class only LineSprite wall1, wall2, wall3;
020 privateprivate is used to restrict access to the current class only RectangleSprite box;
021 privateprivate is used to restrict access to the current class only OvalSprite ball, p1, p2, p3;
022 privateprivate is used to restrict access to the current class only PolygonSprite paddle;
023 privateprivate is used to restrict access to the current class only ProjectileTransformer ballTransformer;
024 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer p, life, l, drop;
025 privateprivate is used to restrict access to the current class only StringSprite score, lives, game;
026
027
028 /**Sets up the game*/
029 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
030 {open braces start code blocks and must be matched with a close brace
031 makeLong();
032 makeAndAddBoarder();
033 makeAndAddPaddle();
034 makeAndAddBall();
035 makeAndAddBrickSet1();
036 makeAndAddScoreBoard();
037 makeAndAddLives();
038 makeEndMessage();
039 ProjectileTransformer fall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.0, 0.1);
040 }close braces end code blocks and must match an earlier open brace
041 /**Creates the boarders that the ball bounces off of in the program*/
042 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBoarder()
043 {open braces start code blocks and must be matched with a close brace
044 wall1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(0.0,0.9, 0.0,0.0);
045 wall1.setLocation(0.01, 0.54);
046 wall1.setLineThickness(0.02);
047 wall1.setColor(Color.GREEN);
048 addSprite(wall1);
049
050 wall2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(0.0,0.9, 0.0,0.0);
051 wall2.setLocation(0.99, 0.54);
052 wall2.setLineThickness(0.02);
053 wall2.setColor(Color.GREEN);
054 addSprite(wall2);
055
056 wall3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(0.0,0.9, 0.99,0.9);
057 wall3.setLocation(0.5, 0.1);
058 wall3.setLineThickness(0.03);
059 wall3.setColor(Color.GREEN);
060 addSprite(wall3);
061 }close braces end code blocks and must match an earlier open brace
062 /**Makes the Color of the Ball and all three walls change randomly*/
063 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomColorBound()
064 {open braces start code blocks and must be matched with a close brace
065 ball.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
066 wall1.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
067 wall2.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
068 wall3.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
069 game.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
070 paddle.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
071 }close braces end code blocks and must match an earlier open brace
072
073 /**Creates a paddle to make the ball bounce back up toward the squares*/
074 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddPaddle()
075 {open braces start code blocks and must be matched with a close brace
076 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(0.35,0.5, 0.45,0.45, 0.55,0.45, 0.65,0.5);
077 paddle.setSize(0.2);
078 paddle.setLocation(0.5, 0.97);
079 paddle.setColor(Color.YELLOW);
080 addSprite(paddle);
081 }close braces end code blocks and must match an earlier open brace
082 /**Makes the paddle move with the mouse*/
083 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value movePaddle()
084 {open braces start code blocks and must be matched with a close brace
085 paddle.setX(getMouseX());
086 }close braces end code blocks and must match an earlier open brace
087 /**Creates a ball forfor is a looping structure for repeatedly executing a block of code the game and sets up projectile transformer forfor is a looping structure for repeatedly executing a block of code the ball to bounce*/
088 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBall()
089 {open braces start code blocks and must be matched with a close brace
090 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,1);
091 ball.setSize(0.035);
092 ball.setLocation(.5,.92);
093 ball.setColor(Palette.getColor("Fire Brick"));
094 addSprite(ball);
095 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
096 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
097 ifif executes the next statement only if the condition in parenthesis evaluates to true(x==this is the comparison operator which evaluates to true if both sides are the same0)
098 {open braces start code blocks and must be matched with a close brace
099 x=this assignment operator makes the left side equal to the right side0.5;
100 }close braces end code blocks and must match an earlier open brace
101 elseelse is what happens when the if condition is false
102 {open braces start code blocks and must be matched with a close brace
103 x=this assignment operator makes the left side equal to the right side-0.5;
104 }close braces end code blocks and must match an earlier open brace
105 ifif executes the next statement only if the condition in parenthesis evaluates to true(y==this is the comparison operator which evaluates to true if both sides are the same0)
106 {open braces start code blocks and must be matched with a close brace
107 y=this assignment operator makes the left side equal to the right side-0.25;
108 }close braces end code blocks and must match an earlier open brace
109 elseelse is what happens when the if condition is false
110 {open braces start code blocks and must be matched with a close brace
111 y=this assignment operator makes the left side equal to the right side-0.4;
112 }close braces end code blocks and must match an earlier open brace
113 ProjectileTransformer bounce=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(x, y);
114 ball.setTracker(bounce);
115 }close braces end code blocks and must match an earlier open brace
116 /**Creates the bricks forfor is a looping structure for repeatedly executing a block of code the ball to hit*/
117 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBrickSet1()
118 {open braces start code blocks and must be matched with a close brace
119 allBricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
120 intint is the type for whole numbers and it is short for integer bricksAcross=this assignment operator makes the left side equal to the right side8;
121 intint is the type for whole numbers and it is short for integer bricksDown=this assignment operator makes the left side equal to the right side4;
122 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 j=this assignment operator makes the left side equal to the right side0; j<bricksDown; j++this is the increment operator, which increases the variable by 1)
123 {open braces start code blocks and must be matched with a close brace
124 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 i=this assignment operator makes the left side equal to the right side1; i<=this evaluates to true if the left side is not more than the right sidebricksAcross; i++this is the increment operator, which increases the variable by 1)
125 {open braces start code blocks and must be matched with a close brace
126 RectangleSprite brick=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1,1);
127 brick.setSize(0.6/bricksAcross);
128 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side.5/bricksAcross+adds two numbers together or concatenates Strings together1.0/bricksAcross*(i-1);
129 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side.75/bricksAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.25)/bricksAcross;
130 y=this assignment operator makes the left side equal to the right sidey+adds two numbers together or concatenates Strings together0.1;
131 brick.setLocation(x,y);
132 brick.setColor(getColor("White"));
133 addSprite(brick);
134 allBricks.add(brick);
135 }close braces end code blocks and must match an earlier open brace
136 }close braces end code blocks and must match an earlier open brace
137 }close braces end code blocks and must match an earlier open brace
138 /**Creates a score board forfor is a looping structure for repeatedly executing a block of code the game*/
139 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddScoreBoard()
140 {open braces start code blocks and must be matched with a close brace
141 setScore(0);
142 score=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score:");
143 score.setSize(0.2);
144 score.setLocation(0.8,0.05);
145 score.setColor(Palette.getColor("Yellow"));
146 addSprite(score);
147 }close braces end code blocks and must match an earlier open brace
148 /**creates the display forfor is a looping structure for repeatedly executing a block of code the amount of lives the player has remaining*/
149 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddLives()
150 {open braces start code blocks and must be matched with a close brace
151 life=this assignment operator makes the left side equal to the right side3;
152 lives=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Lives:"+adds two numbers together or concatenates Strings togetherlife);
153 lives.setSize(0.2);
154 lives.setLocation(0.2,0.05);
155 lives.setColor(Palette.getColor("Yellow"));
156 addSprite(lives);
157 }close braces end code blocks and must match an earlier open brace
158 /** Creates the Game Over message that is displayed when player loses*/
159 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeEndMessage()
160 {open braces start code blocks and must be matched with a close brace
161 game=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("GAME OVER");
162 game.setLocation(0.5, 0.5);
163 game.setSize(0.5);
164 game.setVisible(falsefalse is a value for the boolean type and means not true);
165 addSprite(game);
166 }close braces end code blocks and must match an earlier open brace
167 /**Allows the ball to bounce off of the walls*/
168 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value ballBounce()
169 {open braces start code blocks and must be matched with a close brace
170 ball.bounceOffOf(wall1);
171 ball.bounceOffOf(wall2);
172 ball.bounceOffOf(wall3);
173 ball.bounceOffOf(paddle);
174 }close braces end code blocks and must match an earlier open brace
175 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeLong()
176 {open braces start code blocks and must be matched with a close brace
177 p1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,1);
178 p1.setSize(0.05);
179 p1.setColor(getColor("blue"));
180 p1.setVisible(falsefalse is a value for the boolean type and means not true);
181
182 }close braces end code blocks and must match an earlier open brace
183 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value dropLong()
184 {open braces start code blocks and must be matched with a close brace
185 p1.setLocation(0.5, 0.3);
186 p1.setVisible(truetrue is the boolean value that is the opposite of false);
187 ProjectileTransformer fall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.0, 0.1);
188 p1.setTracker(fall);
189 addSprite(p1);
190 }close braces end code blocks and must match an earlier open brace
191 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value dropLife()
192 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
193 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value dropVanish()
194 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
195 /** tells which power up to drop ifif executes the next statement only if the condition in parenthesis evaluates to true any*/
196 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value getDrops()
197 {open braces start code blocks and must be matched with a close brace
198 ifif executes the next statement only if the condition in parenthesis evaluates to true(drop==this is the comparison operator which evaluates to true if both sides are the same0)
199 {open braces start code blocks and must be matched with a close brace
200 dropLong();
201 }close braces end code blocks and must match an earlier open brace
202 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(drop==this is the comparison operator which evaluates to true if both sides are the same4)
203 {open braces start code blocks and must be matched with a close brace
204 dropLife();
205 }close braces end code blocks and must match an earlier open brace
206 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(drop==this is the comparison operator which evaluates to true if both sides are the same2)
207 {open braces start code blocks and must be matched with a close brace
208 dropVanish();
209 }close braces end code blocks and must match an earlier open brace
210 }close braces end code blocks and must match an earlier open brace
211 /** Handles the reaction of the player catching the power ups with the paddle*/
212 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleDrops()
213 {open braces start code blocks and must be matched with a close brace
214 ifif executes the next statement only if the condition in parenthesis evaluates to true(p1.intersects(paddle))
215 {open braces start code blocks and must be matched with a close brace
216 paddle.setScale(0.4);
217 }close braces end code blocks and must match an earlier open brace
218 }close braces end code blocks and must match an earlier open brace
219 /**Makes the bricks change color to yellow after first hit red after second and after third dissappear and adds points get*/
220 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleBallCollision()
221 {open braces start code blocks and must be matched with a close brace
222 forfor is a looping structure for repeatedly executing a block of code(Sprite single: allBricks)
223 {open braces start code blocks and must be matched with a close brace
224 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.isVisible() &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 &&) ball.intersects(single))
225 {open braces start code blocks and must be matched with a close brace
226 intint is the type for whole numbers and it is short for integer drop=this assignment operator makes the left side equal to the right siderandom.nextInt(6);
227
228 intint is the type for whole numbers and it is short for integer l=this assignment operator makes the left side equal to the right sidelife;
229 ifif executes the next statement only if the condition in parenthesis evaluates to true(l>=this evaluates to true if the left side is not less than the right side1 &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 &&) getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"White")
230 {open braces start code blocks and must be matched with a close brace
231 intint is the type for whole numbers and it is short for integer p=this assignment operator makes the left side equal to the right sidegetScore();
232 setScore(p+adds two numbers together or concatenates Strings together5);
233 ball.bounceOffOf(single);
234 single.setVisible(falsefalse is a value for the boolean type and means not true);
235 //single.setColor(getColor("yellow"));
236 }close braces end code blocks and must match an earlier open brace
237 /**ifif executes the next statement only if the condition in parenthesis evaluates to true(l>=this evaluates to true if the left side is not less than the right side1 &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 &&) getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"yellow")
238 {open braces start code blocks and must be matched with a close brace
239 intint is the type for whole numbers and it is short for integer p=this assignment operator makes the left side equal to the right sidegetScore();
240 setScore(p+adds two numbers together or concatenates Strings together5);
241 ball.bounceOffOf(single);
242 single.setColor(getColor("red"));
243 }close braces end code blocks and must match an earlier open brace
244 /**elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(l>=this evaluates to true if the left side is not less than the right side1 &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 &&) getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"red")
245 {open braces start code blocks and must be matched with a close brace
246 intint is the type for whole numbers and it is short for integer p=this assignment operator makes the left side equal to the right sidegetScore();
247 setScore(p+adds two numbers together or concatenates Strings together5);
248 ball.bounceOffOf(single);
249 single.setVisible(falsefalse is a value for the boolean type and means not true);
250 }close braces end code blocks and must match an earlier open brace
251 */
252 }close braces end code blocks and must match an earlier open brace
253 }close braces end code blocks and must match an earlier open brace
254 }close braces end code blocks and must match an earlier open brace
255 /**Returns the ball after hitting the bricks*/
256 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value droppedBall()
257 {open braces start code blocks and must be matched with a close brace
258 ifif executes the next statement only if the condition in parenthesis evaluates to true(ball.getLocation().y>=this evaluates to true if the left side is not less than the right side1.0 &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 &&) ball.getLocation().y<=this evaluates to true if the left side is not more than the right side1.01)
259 {open braces start code blocks and must be matched with a close brace
260 intint is the type for whole numbers and it is short for integer l=this assignment operator makes the left side equal to the right sidelife;
261 ifif executes the next statement only if the condition in parenthesis evaluates to true(l>=this evaluates to true if the left side is not less than the right side1)
262 {open braces start code blocks and must be matched with a close brace
263 life=this assignment operator makes the left side equal to the right sidel-1;
264 }close braces end code blocks and must match an earlier open brace
265 }close braces end code blocks and must match an earlier open brace
266 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(ball.getLocation().y>=this evaluates to true if the left side is not less than the right side1.02 &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 &&) getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
267 {open braces start code blocks and must be matched with a close brace
268 intint is the type for whole numbers and it is short for integer l=this assignment operator makes the left side equal to the right sidelife;
269 ifif executes the next statement only if the condition in parenthesis evaluates to true(l>=this evaluates to true if the left side is not less than the right side1)
270 {open braces start code blocks and must be matched with a close brace
271 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidegetMouseX();
272 ball.setLocation(x, 0.92);
273 ProjectileTransformer newBounce=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0, 0.5);
274 ball.setTracker(newBounce);
275 }close braces end code blocks and must match an earlier open brace
276 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(l<=this evaluates to true if the left side is not more than the right side0)
277 {open braces start code blocks and must be matched with a close brace
278 game.setVisible(truetrue is the boolean value that is the opposite of false);
279 }close braces end code blocks and must match an earlier open brace
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
283 /**Handle input and game events*/
284 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
285 {open braces start code blocks and must be matched with a close brace
286 handleDrops();
287 getDrops();
288 randomColorBound();
289 handleBallCollision();
290 movePaddle();
291 ballBounce();
292 droppedBall();
293 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
294 lives.setText("Lives:"+adds two numbers together or concatenates Strings togetherlife);
295 getDrops();
296 }close braces end code blocks and must match an earlier open brace
297 }close braces end code blocks and must match an earlier open brace
|