|
001 packagepackage is used to name the directory or folder a class is in Newman;
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 Moriah
013 */
014 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 Assignment7 extendsextends means to customize or extend the functionality of a class Game
015 {open braces start code blocks and must be matched with a close brace
016 privateprivate is used to restrict access to the current class only ArrayList<Sprite> allBricks;
017 privateprivate is used to restrict access to the current class only RectangleSprite brick;
018 privateprivate is used to restrict access to the current class only OvalSprite paddle;
019 privateprivate is used to restrict access to the current class only OvalSprite ball;
020 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile;
021 privateprivate is used to restrict access to the current class only OutlineSprite wall, wall2, wall3;
022 privateprivate is used to restrict access to the current class only StringSprite score;
023
024 /**sets up the game*/
025 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
026 {open braces start code blocks and must be matched with a close brace
027 makeAndAddBricks();
028 makeAndAddPaddle();
029 makeAndAddBall();
030 makeAndAddWall();
031 makeAndAddScore();
032 projectile=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(.1,.25);
033 ball.setTracker(projectile);
034
035
036 }close braces end code blocks and must match an earlier open brace
037 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBricks()
038 {open braces start code blocks and must be matched with a close brace
039 allBricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
040 intint is the type for whole numbers and it is short for integer brickAcross=this assignment operator makes the left side equal to the right side9;
041 intint is the type for whole numbers and it is short for integer brickDown=this assignment operator makes the left side equal to the right side3;
042 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 side 1; i<=this evaluates to true if the left side is not more than the right sidebrickAcross; i++this is the increment operator, which increases the variable by 1)
043 {open braces start code blocks and must be matched with a close brace
044 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 side 0; j<=this evaluates to true if the left side is not more than the right sidebrickDown; j++this is the increment operator, which increases the variable by 1)
045 {open braces start code blocks and must be matched with a close brace
046 brick=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(4, 3);
047 brick.setSize(0.75/brickAcross);
048 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side.95/brickAcross+adds two numbers together or concatenates Strings together0.9/brickAcross*(i-1);
049 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.5/brickAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.5)/brickAcross;
050 brick.setLocation(x, y);
051 brick.setColor(Palette.getColor("Purple"));
052 brick.setVisible(truetrue is the boolean value that is the opposite of false);
053 allBricks.add(brick);
054 addSprite(brick);
055 }close braces end code blocks and must match an earlier open brace
056 }close braces end code blocks and must match an earlier open brace
057
058
059
060 }close braces end code blocks and must match an earlier open brace
061 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddPaddle()
062 {open braces start code blocks and must be matched with a close brace
063 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(3,1);
064 paddle.setSize(.25);
065 paddle.setLocation(.5,.9);
066 paddle.setColor(Palette.getColor("Green"));
067 addSprite(paddle);
068 }close braces end code blocks and must match an earlier open brace
069 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBall()
070 {open braces start code blocks and must be matched with a close brace
071 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(2,2);
072 ball.setSize(.045);
073 ball.setLocation(.5,.65);
074 ball.setColor(Palette.getColor("Hot Pink"));
075 addSprite(ball);
076 }close braces end code blocks and must match an earlier open brace
077 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddWall()
078 {open braces start code blocks and must be matched with a close brace
079 wall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 1, 0));
080 wall.setSize(2);
081 wall.setLocation(0,0);
082 wall.setColor(Palette.getColor("Light Blue"));
083 addSprite(wall);
084
085 wall2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 0, 1));
086 wall2.setSize(2);
087 wall2.setLocation(1,0);
088 wall2.setColor(Palette.getColor("Light Blue"));
089 addSprite(wall2);
090
091 wall3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0,0 , 1));
092 wall3.setSize(2);
093 wall3.setLocation(0,0);
094 wall3.setColor(Palette.getColor("Light Blue"));
095 addSprite(wall3);
096
097 }close braces end code blocks and must match an earlier open brace
098
099 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value movePaddle()
100 {open braces start code blocks and must be matched with a close brace
101 paddle.setX(getMouseX());
102
103 }close braces end code blocks and must match an earlier open brace
104
105 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
106 {open braces start code blocks and must be matched with a close brace
107 ball.bounceOffOf(brick);
108 ball.bounceOffOf(paddle);
109 ball.bounceOffOf(wall);
110 ball.bounceOffOf(wall2);
111 ball.bounceOffOf(wall3);
112 handleBallBricksCollisions();
113 }close braces end code blocks and must match an earlier open brace
114
115 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddScore()
116 {open braces start code blocks and must be matched with a close brace
117 score=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("0");
118 score.setSize(0.15);
119 score.setColor(getColor("white"));
120 score.setLocation(0.9, 0.8);
121 addSprite(score);
122
123 }close braces end code blocks and must match an earlier open brace
124 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleBallBricksCollisions()
125 {open braces start code blocks and must be matched with a close brace
126 forfor is a looping structure for repeatedly executing a block of code(Sprite single: allBricks)
127 {open braces start code blocks and must be matched with a close brace
128 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.isVisible()==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false &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 &&) single.intersects(ball))
129 {open braces start code blocks and must be matched with a close brace
130 ball.bounceOffOf(single);
131
132 single.setVisible(falsefalse is a value for the boolean type and means not true);
133 intint is the type for whole numbers and it is short for integer startscores =this assignment operator makes the left side equal to the right side getScore();
134 setScore(startscores+adds two numbers together or concatenates Strings together5);
135
136 }close braces end code blocks and must match an earlier open brace
137
138 }close braces end code blocks and must match an earlier open brace
139 }close braces end code blocks and must match an earlier open brace
140
141
142
143
144 /**handle input and game events*/
145 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
146 {open braces start code blocks and must be matched with a close brace
147 movePaddle();
148 handleCollisions();
149 handleBallBricksCollisions();
150 score.setText(""+adds two numbers together or concatenates Strings togethergetScore());
151
152
153 }close braces end code blocks and must match an earlier open brace
154 }close braces end code blocks and must match an earlier open brace
|