|
001 packagepackage is used to name the directory or folder a class is in Rohrer;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * the name of my game is Herding Cats
009 * the object of my game is to use your cursor to scare the cats in the correct direction to get them into the fence in the middle of the screen
010 * @authorthis is the Javadoc tag for documenting who created the source code Kevin Rohrer
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 Final_Project extendsextends means to customize or extend the functionality of a class Game
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 OutlineSprite screenOutline;
016 privateprivate is used to restrict access to the current class only Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays cats =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays9]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
017 privateprivate is used to restrict access to the current class only Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays fence =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays4]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
018 privateprivate is used to restrict access to the current class only ProjectileTransformer catsWander;
019 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer time =this assignment operator makes the left side equal to the right side 60;
020 privateprivate is used to restrict access to the current class only StringSprite timeDisplay =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite(":"+adds two numbers together or concatenates Strings togethertime);
021 privateprivate is used to restrict access to the current class only StringSprite lose =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("You Lose");
022 privateprivate is used to restrict access to the current class only StringSprite win =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("YOU WIN!!!");
023
024 /**runs the methods below to make or begin vareous aspects of 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 addFence();
028 screenOutline();
029 makeCats();
030 startWander();
031 setTimer();
032 helpScreen();
033 }close braces end code blocks and must match an earlier open brace
034 /**
035 * runs the boundarys method to keep the cats on the screen
036 * runs the push away method to push the cats away from cursor
037 * runs the winLose method when time hits 0
038 */
039 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
040 {open braces start code blocks and must be matched with a close brace
041 boundarys();
042 pushAway();
043 ifif executes the next statement only if the condition in parenthesis evaluates to true(time ==this is the comparison operator which evaluates to true if both sides are the same 0)
044 {open braces start code blocks and must be matched with a close brace
045 winLose();
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 /** finds ut ifif executes the next statement only if the condition in parenthesis evaluates to true the player wins or looses and displays the apropreate message*/
049 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value winLose()
050 {open braces start code blocks and must be matched with a close brace
051 intint is the type for whole numbers and it is short for integer catsOut =this assignment operator makes the left side equal to the right side 0;
052 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 side0; i<cats.length; i++this is the increment operator, which increases the variable by 1)
053 {open braces start code blocks and must be matched with a close brace
054 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getX();
055 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getY();
056 ifif executes the next statement only if the condition in parenthesis evaluates to true((x<0.7 &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 &&) x>0.3) &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 &&) (y<0.7 &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 &&) y>0.3))
057 {open braces start code blocks and must be matched with a close brace
058 catsOut++this is the increment operator, which increases the variable by 1;
059 }close braces end code blocks and must match an earlier open brace
060 }close braces end code blocks and must match an earlier open brace
061 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(getColor("Saddle Brown"));
062 ifif executes the next statement only if the condition in parenthesis evaluates to true(catsOut < 9) // lose
063 {open braces start code blocks and must be matched with a close brace
064 lose.setLocation(.5, .3);
065 lose.setWidth(.7);
066 lose.setColor(getColor("White"));
067 addSprite(lose);
068 }close braces end code blocks and must match an earlier open brace
069 ifif executes the next statement only if the condition in parenthesis evaluates to true(catsOut ==this is the comparison operator which evaluates to true if both sides are the same 9) // win
070 {open braces start code blocks and must be matched with a close brace
071 win.setLocation(.5, .3);
072 win.setWidth(.7);
073 win.setColor(getColor("White"));
074 addSprite(win);
075 }close braces end code blocks and must match an earlier open brace
076 }close braces end code blocks and must match an earlier open brace
077 /** adds the countdown clock string sprite and schedules the timed action to count down the "time" variable*/
078 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setTimer()
079 {open braces start code blocks and must be matched with a close brace
080 timeDisplay.setWidth(.1);
081 timeDisplay.leftJustify();
082 timeDisplay.setLocation(.008, .05);
083 timeDisplay.setColor(getColor("White"));
084 addSprite(timeDisplay);
085
086 schedule(newnew is used to create objects by calling the constructor countDown(), 1);
087 }close braces end code blocks and must match an earlier open brace
088 /** counts down "time" every second and sets the text of the string sprite to show the countdown clock*/
089 classclass is a group of fields and methods used for making objects countDown extendsextends means to customize or extend the functionality of a class TimedAction
090 {open braces start code blocks and must be matched with a close brace
091 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
092 {open braces start code blocks and must be matched with a close brace
093 time--this is the decrement operator, which decreases the variable by 1;
094 timeDisplay.setText(":"+adds two numbers together or concatenates Strings togethertime);
095 ifif executes the next statement only if the condition in parenthesis evaluates to true(time >0)
096 schedule(thisthis means the current object (the implicit parameter),1);
097 }close braces end code blocks and must match an earlier open brace
098 }close braces end code blocks and must match an earlier open brace
099 /** finds out ifif executes the next statement only if the condition in parenthesis evaluates to true the cats are close to cursor and returns truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true they are in correct distance and falsefalse is a value for the boolean type and means not true ifif executes the next statement only if the condition in parenthesis evaluates to true they are not*/
100 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false outlinePush(intint is the type for whole numbers and it is short for integer i, Location2D mousePosition, Location2D catPosition)
101 {open braces start code blocks and must be matched with a close brace
102 ifif executes the next statement only if the condition in parenthesis evaluates to true((mousePosition.distance(catPosition) < .1 &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 &&) i<3) ||this is boolean or, meaning if either or both are true then the result is true
103 (mousePosition.distance(catPosition) < .15 &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 &&) i>2 &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 &&) i<6) ||this is boolean or, meaning if either or both are true then the result is true
104 (mousePosition.distance(catPosition) < .2 &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 &&) i>5))
105 {open braces start code blocks and must be matched with a close brace
106 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
107 }close braces end code blocks and must match an earlier open brace
108 elseelse is what happens when the if condition is false
109 {open braces start code blocks and must be matched with a close brace
110 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
111 }close braces end code blocks and must match an earlier open brace
112 }close braces end code blocks and must match an earlier open brace
113 /** checks to see ifif executes the next statement only if the condition in parenthesis evaluates to true a cat is in contact with any of the fences and returns truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true there are collisions and the fence is brown and falsefalse is a value for the boolean type and means not true ifif executes the next statement only if the condition in parenthesis evaluates to true there is no collisions or the fence is green*/
114 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false fencePush(intint is the type for whole numbers and it is short for integer i)
115 {open braces start code blocks and must be matched with a close brace
116 ifif executes the next statement only if the condition in parenthesis evaluates to true(cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays) ==this is the comparison operator which evaluates to true if both sides are the same truetrue 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 &&) getColorName(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Saddle Brown" ||this is boolean or, meaning if either or both are true then the result is true
117 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays) ==this is the comparison operator which evaluates to true if both sides are the same truetrue 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 &&) getColorName(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Saddle Brown" ||this is boolean or, meaning if either or both are true then the result is true
118 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays2]brackets are typically used to declare, initialize and index (indicate which element of) arrays) ==this is the comparison operator which evaluates to true if both sides are the same truetrue 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 &&) getColorName(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays2]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Saddle Brown" ||this is boolean or, meaning if either or both are true then the result is true
119 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays3]brackets are typically used to declare, initialize and index (indicate which element of) arrays) ==this is the comparison operator which evaluates to true if both sides are the same truetrue 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 &&) getColorName(fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays3]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Saddle Brown")
120 {open braces start code blocks and must be matched with a close brace
121 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
122 }close braces end code blocks and must match an earlier open brace
123 elseelse is what happens when the if condition is false
124 {open braces start code blocks and must be matched with a close brace
125 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
126 }close braces end code blocks and must match an earlier open brace
127 }close braces end code blocks and must match an earlier open brace
128 /** changes transformer so that the cats repel from the cursor when it gets close to the cats thisthis means the current object (the implicit parameter) also speeds up the cats when the cursor repels them*/
129 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value pushAway() // to solve problem of pushing them out of screen make so that it only pushes away if they are not in colision of outline
130 {open braces start code blocks and must be matched with a close brace
131 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 side0; i<cats.length; i++this is the increment operator, which increases the variable by 1)
132 {open braces start code blocks and must be matched with a close brace
133 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<fence.length; j++this is the increment operator, which increases the variable by 1)
134 {open braces start code blocks and must be matched with a close brace
135 Location2D mousePosition =this assignment operator makes the left side equal to the right side getMouse2D();
136 Location2D catPosition =this assignment operator makes the left side equal to the right side cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getLocation();
137 catsWander =this assignment operator makes the left side equal to the right side (ProjectileTransformer)cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getTransformer();
138 Vector2D toCat =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Vector2D(getMouse2D(), cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getLocation());
139 Vector2D originalDirection =this assignment operator makes the left side equal to the right side catsWander.getVector2D();
140
141 ifif executes the next statement only if the condition in parenthesis evaluates to true(outlinePush(i, mousePosition, catPosition) ==this is the comparison operator which evaluates to true if both sides are the same truetrue 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 &&) cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(screenOutline) ==this is the comparison operator which evaluates to true if both sides are the same falsefalse is a value for the boolean type and means not true &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 &&) fencePush(i) ==this is the comparison operator which evaluates to true if both sides are the same falsefalse is a value for the boolean type and means not true)
142 {open braces start code blocks and must be matched with a close brace
143 originalDirection.setDirectionDegrees(toCat.getDirectionDegrees() +adds two numbers together or concatenates Strings together (100.0*Math.random()-50.0));
144 originalDirection.setSpeed(.2);
145 catsWander.setVector2D(originalDirection);
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 originalDirection.setSpeed(.05);
150 }close braces end code blocks and must match an earlier open brace
151 }close braces end code blocks and must match an earlier open brace
152 }close braces end code blocks and must match an earlier open brace
153 }close braces end code blocks and must match an earlier open brace
154 /** adds transformer to cat and schedules the timed action that keeps the cat wandering */
155 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value startWander()
156 {open braces start code blocks and must be matched with a close brace
157 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 side0; i<cats.length; i++this is the increment operator, which increases the variable by 1)
158 {open braces start code blocks and must be matched with a close brace
159 catsWander =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ProjectileTransformer((20.0*Math.random()-10.0)/100.0, (20.0*Math.random()-10.0)/100.0);
160 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.addTransformer(catsWander);
161 }close braces end code blocks and must match an earlier open brace
162 schedule(newnew is used to create objects by calling the constructor changeDirection(), .1);
163 }close braces end code blocks and must match an earlier open brace
164 /** changes the direction of the cats slightly multiple times a second to give the image that the cat is wandering */
165 classclass is a group of fields and methods used for making objects changeDirection extendsextends means to customize or extend the functionality of a class TimedAction
166 {open braces start code blocks and must be matched with a close brace
167 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
168 {open braces start code blocks and must be matched with a close brace
169 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 side0; i<cats.length; i++this is the increment operator, which increases the variable by 1)
170 {open braces start code blocks and must be matched with a close brace
171 catsWander =this assignment operator makes the left side equal to the right side (ProjectileTransformer)cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getTransformer();
172 Vector2D direction =this assignment operator makes the left side equal to the right side catsWander.getVector2D();
173 direction.turn((50.0*Math.random()-25.0));
174 direction.setSpeed(.05);
175 catsWander.setVector2D(direction);
176 }close braces end code blocks and must match an earlier open brace
177 schedule(thisthis means the current object (the implicit parameter),.1);
178 }close braces end code blocks and must match an earlier open brace
179 }close braces end code blocks and must match an earlier open brace
180 /**creates and adds the screen outline */
181 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value screenOutline()
182 {open braces start code blocks and must be matched with a close brace
183 PolygonSprite screen =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PolygonSprite(0,0, 1,0, 1,1, 0,1);
184 screenOutline =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OutlineSprite(screen);
185 screenOutline.setSize(1.2);
186 screenOutline.setLineThickness(0.1);
187 screenOutline.setLocation(0.5, 0.5);
188 screenOutline.setColor(getColor("Grey"));
189 addSprite(screenOutline);
190 }close braces end code blocks and must match an earlier open brace
191 /** Creates and adds all four sides of the fence the cats will be herded into */
192 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addFence() // redesign to use Paramiters
193 {open braces start code blocks and must be matched with a close brace
194 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(10,1);
195 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(.5,.375);
196
197 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(10,1);
198 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(.5,.625);
199
200 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays2]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1,10);
201 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays2]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(.625,.5);
202
203 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays3]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1,10);
204 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays3]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(.375,.5);
205
206 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 side0; i<fence.length; i++this is the increment operator, which increases the variable by 1)
207 {open braces start code blocks and must be matched with a close brace
208 fence[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setSize(.3);
209 fence[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(getColor("Saddle Brown"));
210
211 addSprite(fence[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
212 }close braces end code blocks and must match an earlier open brace
213 fence[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(getColor("Green"));
214 }close braces end code blocks and must match an earlier open brace
215 /** makes and adds 3 of each color cats to the screen at random places outside of the fence */
216 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeCats()
217 {open braces start code blocks and must be matched with a close brace
218 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 0; i<cats.length; i++this is the increment operator, which increases the variable by 1)
219 {open braces start code blocks and must be matched with a close brace
220 ifif executes the next statement only if the condition in parenthesis evaluates to true(i<3)
221 {open braces start code blocks and must be matched with a close brace
222 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Green_Cat_Icon.jpg");
223 }close braces end code blocks and must match an earlier open brace
224 ifif executes the next statement only if the condition in parenthesis evaluates to true(i>2 &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 &&) i<6)
225 {open braces start code blocks and must be matched with a close brace
226 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Orange_Cat_Icon.jpg");
227 }close braces end code blocks and must match an earlier open brace
228 ifif executes the next statement only if the condition in parenthesis evaluates to true(i>5)
229 {open braces start code blocks and must be matched with a close brace
230 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Red_Cat_Icon.jpg");
231 }close braces end code blocks and must match an earlier open brace
232 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setSize(.05);
233 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side(1+adds two numbers together or concatenates Strings together(doubledouble is the type for numbers that can contain decimal fractions)(8*Math.random()))/10.0;
234 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side(1+adds two numbers together or concatenates Strings together(doubledouble is the type for numbers that can contain decimal fractions)(8*Math.random()))/10.0;
235 whilewhile is a looping structure for executing code repeatedly((x<0.7 &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 &&) x>0.3) &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 &&) (y<0.7 &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 &&) y>0.3))
236 {open braces start code blocks and must be matched with a close brace
237 x =this assignment operator makes the left side equal to the right side(1+adds two numbers together or concatenates Strings together(doubledouble is the type for numbers that can contain decimal fractions)(8*Math.random()))/10.0;
238 y =this assignment operator makes the left side equal to the right side(1+adds two numbers together or concatenates Strings together(doubledouble is the type for numbers that can contain decimal fractions)(8*Math.random()))/10.0;
239 }close braces end code blocks and must match an earlier open brace
240 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x,y);
241
242 addSprite(cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
243 }close braces end code blocks and must match an earlier open brace
244 }close braces end code blocks and must match an earlier open brace
245 /** sets the boundarys to keep the cats in the screen cats also bounce off of the fence only ifif executes the next statement only if the condition in parenthesis evaluates to true it is brown */
246 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value boundarys()
247 {open braces start code blocks and must be matched with a close brace
248 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 side0; i<cats.length; i++this is the increment operator, which increases the variable by 1)
249 {open braces start code blocks and must be matched with a close brace
250 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.bounceOffOf(screenOutline);
251 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<fence.length; j++this is the increment operator, which increases the variable by 1)
252 {open braces start code blocks and must be matched with a close brace
253 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(fence[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Saddle Brown")
254 cats[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.bounceOffOf(fence[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
255 }close braces end code blocks and must match an earlier open brace
256 }close braces end code blocks and must match an earlier open brace
257 }close braces end code blocks and must match an earlier open brace
258 /** creates the text to go into the help screen*/
259 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helpScreen()
260 {open braces start code blocks and must be matched with a close brace
261 String helpText=this assignment operator makes the left side equal to the right side
262 "the object of the game is to herd all 9 cats into the fence in the middle of the window before the time runs out<br>"+adds two numbers together or concatenates Strings together
263 "you have 60 seconds to get the cats into the fence, the cats can only pass over the green fence<br>"+adds two numbers together or concatenates Strings together
264 "after the 60 seconds have passed the green fence will turn brown and the game will dicide if you have won or lost<br>"+adds two numbers together or concatenates Strings together
265 "you win if all the cats are inside the fence when the timer runs out<br>"+adds two numbers together or concatenates Strings together
266 "you lose if the timer runs out before you get all the cats inside the fence<br>"+adds two numbers together or concatenates Strings together
267 "if you get all the cats into the fence before the time runs out you must keep them in the fence untill the timer reaches 0<br>"+adds two numbers together or concatenates Strings together
268 "be carefull of the corners of the screen, if you push the cats into the corners than they will glitch and be pushed off the screen<br>"+adds two numbers together or concatenates Strings together
269 "Enjoy.";
270 setHelpText(helpText);
271 }close braces end code blocks and must match an earlier open brace
272 }close braces end code blocks and must match an earlier open brace
|