|
001 packagepackage is used to name the directory or folder a class is in Jam;
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 * This game is to teach kids about the
010 * names of shapes and words forfor is a looping structure for repeatedly executing a block of code numbers.
011 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
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 ShapeMatcher 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 /**background behind shape to match*/
016 privateprivate is used to restrict access to the current class only RectangleSprite highlight;
017 /**the shape to match click on*/
018 privateprivate is used to restrict access to the current class only PolygonSprite shapeToMatch;
019 /**how many sides are on the shape to match*/
020 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer sides;
021 /**a regular three-sided polygon*/
022 privateprivate is used to restrict access to the current class only PolygonSprite triangle;
023 /**a regular four-sided polygon*/
024 privateprivate is used to restrict access to the current class only PolygonSprite square;
025 /**a regular five-sided polygon*/
026 privateprivate is used to restrict access to the current class only PolygonSprite pentagon;
027 /**a regular six-sided polygon*/
028 privateprivate is used to restrict access to the current class only PolygonSprite hexagon;
029 /**name of the shape*/
030 privateprivate is used to restrict access to the current class only StringSprite shapeLabel;
031 /**number of sides as a word*/
032 privateprivate is used to restrict access to the current class only StringSprite sidesLabel;
033
034 /**right in a row*/
035 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer rightInRow;
036
037 /**sets up the game*/
038 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
039 {open braces start code blocks and must be matched with a close brace
040 rightInRow=this assignment operator makes the left side equal to the right side0;
041 sides=this assignment operator makes the left side equal to the right siderandom.nextInt(4)+adds two numbers together or concatenates Strings together3;
042 makeSprites();
043 addSprites();
044 setHelpText("<h1>Match the Shape</h1>"+adds two numbers together or concatenates Strings together
045 "Click on the shape that matches the words "+adds two numbers together or concatenates Strings together
046 "on the top and left and the shape in the "+adds two numbers together or concatenates Strings together
047 "upper left corner.<br><br>As you get better "+adds two numbers together or concatenates Strings together
048 "the game gets harder. Have fun!");
049 }close braces end code blocks and must match an earlier open brace
050
051 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeRandomShapes()
052 {open braces start code blocks and must be matched with a close brace
053 triangle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(3);
054 triangle.setScale(shapeToMatch.getScale()*2);
055 triangle.setLocation(random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2, random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2);
056 triangle.setColor(newnew is used to create objects by calling the constructor Color(random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
057 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
058 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f, 0.8f));
059
060 square=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(4);
061 square.setScale(shapeToMatch.getScale()*2);
062 square.setLocation(random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2, random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2);
063 square.setColor(newnew is used to create objects by calling the constructor Color(random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
064 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
065 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f, 0.8f));
066
067 pentagon=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(5);
068 pentagon.setScale(shapeToMatch.getScale()*2);
069 pentagon.setLocation(random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2, random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2);
070 pentagon.setColor(newnew is used to create objects by calling the constructor Color(random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
071 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
072 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f, 0.8f));
073
074 hexagon=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(6);
075 hexagon.setScale(shapeToMatch.getScale()*2);
076 hexagon.setLocation(random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2, random.nextDouble()*0.6+adds two numbers together or concatenates Strings together0.2);
077 hexagon.setColor(newnew is used to create objects by calling the constructor Color(random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
078 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f,
079 random.nextFloat()*0.8f+adds two numbers together or concatenates Strings together0.2f, 0.8f));
080 }close braces end code blocks and must match an earlier open brace
081
082 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTargetShapes()
083 {open braces start code blocks and must be matched with a close brace
084 highlight=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 1);
085 highlight.setScale(0.15);
086 highlight.setLocation(0.1, 0.1);
087 highlight.setColor(Color.YELLOW);
088
089 shapeToMatch=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(sides);
090 shapeToMatch.setScale(highlight.getScale()*0.9);
091 shapeToMatch.setLocation(highlight.getLocation());
092 shapeToMatch.setColor(Color.RED);
093
094 shapeLabel=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("triangle");
095 ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same4)
096 shapeLabel.setText("square");
097 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same5)
098 shapeLabel.setText("pentagon");
099 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same6)
100 shapeLabel.setText("hexagon");
101 shapeLabel.rightJustify();
102 shapeLabel.setLineHeight(highlight.getScale());
103 shapeLabel.topJustify();
104 shapeLabel.setLocation(0.95, 0.05);
105
106 sidesLabel=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("three");
107 ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same4)
108 sidesLabel.setText("four");
109 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same5)
110 sidesLabel.setText("five");
111 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same6)
112 sidesLabel.setText("six");
113 sidesLabel.leftJustify();
114 sidesLabel.setLineHeight(highlight.getScale());
115 sidesLabel.topJustify();
116 sidesLabel.setLocation(0.05, 0.95);
117 sidesLabel.rotateRevolutions(-0.25);
118 }close braces end code blocks and must match an earlier open brace
119
120 /**makes all the sprites*/
121 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
122 {open braces start code blocks and must be matched with a close brace
123 makeTargetShapes();
124 makeRandomShapes();
125 }close braces end code blocks and must match an earlier open brace
126
127 /**adds the sprites to the screen*/
128 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
129 {open braces start code blocks and must be matched with a close brace
130 canvas.addSprite(highlight, shapeToMatch);
131 canvas.addSprite(triangle, square, pentagon, hexagon);
132 canvas.addSprite(sidesLabel, shapeLabel);
133 }close braces end code blocks and must match an earlier open brace
134
135 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleTriangle()
136 {open braces start code blocks and must be matched with a close brace
137 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
138 ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same3)
139 {open braces start code blocks and must be matched with a close brace
140 ifif executes the next statement only if the condition in parenthesis evaluates to true(triangle.intersects(click))
141 {open braces start code blocks and must be matched with a close brace
142 rightInRow=this assignment operator makes the left side equal to the right siderightInRow+adds two numbers together or concatenates Strings together1;
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 rightInRow=this assignment operator makes the left side equal to the right side0;
147 }close braces end code blocks and must match an earlier open brace
148 }close braces end code blocks and must match an earlier open brace
149 }close braces end code blocks and must match an earlier open brace
150
151 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleSquare()
152 {open braces start code blocks and must be matched with a close brace
153 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
154 ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same4)
155 {open braces start code blocks and must be matched with a close brace
156 ifif executes the next statement only if the condition in parenthesis evaluates to true(square.intersects(click))
157 {open braces start code blocks and must be matched with a close brace
158 rightInRow=this assignment operator makes the left side equal to the right siderightInRow+adds two numbers together or concatenates Strings together1;
159 }close braces end code blocks and must match an earlier open brace
160 elseelse is what happens when the if condition is false
161 {open braces start code blocks and must be matched with a close brace
162 rightInRow=this assignment operator makes the left side equal to the right side0;
163 }close braces end code blocks and must match an earlier open brace
164 }close braces end code blocks and must match an earlier open brace
165
166 }close braces end code blocks and must match an earlier open brace
167
168 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handlePentagon()
169 {open braces start code blocks and must be matched with a close brace
170 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
171 ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same5)
172 {open braces start code blocks and must be matched with a close brace
173 ifif executes the next statement only if the condition in parenthesis evaluates to true(pentagon.intersects(click))
174 {open braces start code blocks and must be matched with a close brace
175 rightInRow=this assignment operator makes the left side equal to the right siderightInRow+adds two numbers together or concatenates Strings together1;
176 }close braces end code blocks and must match an earlier open brace
177 elseelse is what happens when the if condition is false
178 {open braces start code blocks and must be matched with a close brace
179 rightInRow=this assignment operator makes the left side equal to the right side0;
180 }close braces end code blocks and must match an earlier open brace
181 }close braces end code blocks and must match an earlier open brace
182
183 }close braces end code blocks and must match an earlier open brace
184
185 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleHexagon()
186 {open braces start code blocks and must be matched with a close brace
187 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
188 ifif executes the next statement only if the condition in parenthesis evaluates to true(sides==this is the comparison operator which evaluates to true if both sides are the same6)
189 {open braces start code blocks and must be matched with a close brace
190 ifif executes the next statement only if the condition in parenthesis evaluates to true(hexagon.intersects(click))
191 {open braces start code blocks and must be matched with a close brace
192 rightInRow=this assignment operator makes the left side equal to the right siderightInRow+adds two numbers together or concatenates Strings together1;
193 }close braces end code blocks and must match an earlier open brace
194 elseelse is what happens when the if condition is false
195 {open braces start code blocks and must be matched with a close brace
196 rightInRow=this assignment operator makes the left side equal to the right side0;
197 }close braces end code blocks and must match an earlier open brace
198 }close braces end code blocks and must match an earlier open brace
199
200 }close braces end code blocks and must match an earlier open brace
201
202 /**handle input and game events*/
203 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)
204 {open braces start code blocks and must be matched with a close brace
205 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
206 ifif executes the next statement only if the condition in parenthesis evaluates to true(click!=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)
207 {open braces start code blocks and must be matched with a close brace
208 handleTriangle();
209 handleSquare();
210 handlePentagon();
211 handleHexagon();
212 }close braces end code blocks and must match an earlier open brace
213 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightInRow>=this evaluates to true if the left side is not less than the right side3)
214 {open braces start code blocks and must be matched with a close brace
215 canvas.removeSprite(shapeToMatch);
216 }close braces end code blocks and must match an earlier open brace
217 elseelse is what happens when the if condition is false
218 {open braces start code blocks and must be matched with a close brace
219 canvas.addSprite(shapeToMatch);
220 }close braces end code blocks and must match an earlier open brace
221
222 }close braces end code blocks and must match an earlier open brace
223 }close braces end code blocks and must match an earlier open brace
|