From ggc
|
001 packagepackage is used to name the directory or folder a class is in Gerdes;
002
003 importimport means to make the classes and/or packages available in this program 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 *
010 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins/Michael Gerdes
011 */
012 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Wackadot
013 {open braces start code blocks and must be matched with a close brace
014 /**Field declaration variables*/
015 privateprivate is used to restrict access to the current class only Sprite dot;
016 privateprivate is used to restrict access to the current class only Sprite redDot;
017 privateprivate is used to restrict access to the current class only Sprite blueDot;
018 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
019
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 score;
021 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer timeLeft;
022 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
023
024 /**Main method declaration and definitions*/
025 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame() /**mainThe main method is the place where applications begin executing. method declaring initial values*/
026 {open braces start code blocks and must be matched with a close brace
027 score =this assignment operator makes the left side equal to the right side 0;
028 /**Sets the initial score to zero*/
029 timeLeft =this assignment operator makes the left side equal to the right side 20;
030 /**Sets the initial time to ten*/
031 makeSprites();
032 /**Makes sprite objects*/
033 addSprites();
034 /**Adds the sprite object to the screen*/
035 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(),1);
036 /**Schedules the alarm method of the TimeUpdater classclass is a group of fields and methods used for making objects to be called one second from the start of the game*/
037 setHelpText("Lots of help text here later");
038 }close braces end code blocks and must match an earlier open brace
039 classclass is a group of fields and methods used for making objects TimeUpdater implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
040 {open braces start code blocks and must be matched with a close brace
041 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
042 {open braces start code blocks and must be matched with a close brace
043 timeLeft--this is the decrement operator, which decreases the variable by 1;
044 updateTimer();
045 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft > 0)
046 {open braces start code blocks and must be matched with a close brace
047 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
048 }close braces end code blocks and must match an earlier open brace
049 }close braces end code blocks and must match an earlier open brace
050 }close braces end code blocks and must match an earlier open brace
051
052 /**Method declaration and definitions forfor is a looping structure for repeatedly executing a block of code making the Sprite objects*/
053 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
054 /**method delcaration*/
055 {open braces start code blocks and must be matched with a close brace
056 dot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
057 /**constructing the field variable dot*/
058 dot.setScale(0.1);
059 /**sizing the dot one tenth of the screen*/
060 dot.setLocation(0.5, 0.5); /**placing the dot in the middle of the screen*/
061 dot.setColor(Color.RED); /**setting the color of the dot*/
062
063 redDot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1); /**constructing a newnew is used to create objects by calling the constructor local variable redDot*/
064 redDot.setScale(0.1);
065 /**sizing the dot on the screen*/
066 redDot.setLocation(random.nextDouble(),random.nextDouble());
067 redDot.setColor(Color.RED);
068
069 blueDot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
070 /**constructs the variable blueDot parameters*/
071 blueDot.setScale(0.1);
072 blueDot.setLocation(random.nextDouble(),random.nextDouble());
073 blueDot.setColor(Color.BLUE);
074
075 scoreSprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Score: " +adds two numbers together or concatenates Strings together score);
076 /**constructs the local variable scoreSprite*/
077 scoreSprite.setHeight(0.1);
078 /**the text will be 1/10 of the screen high.*/
079 scoreSprite.rightJustify();
080 /**the text will be the rightmost location*/
081 scoreSprite.topJustify();
082 /**the text will be the topmost location*/
083 scoreSprite.setLocation(1,0);
084 /**top right where the score will be*/
085
086 timerSprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Timer: " +adds two numbers together or concatenates Strings together timeLeft);
087 timerSprite.leftJustify();
088 timerSprite.topJustify();
089 timerSprite.setHeight(0.1);
090 timerSprite.setLocation(0,0);
091 }close braces end code blocks and must match an earlier open brace
092 /**Method declaration and definitions forfor is a looping structure for repeatedly executing a block of code adding the Sprite objects*/
093 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites() /**method declaration*/
094 {open braces start code blocks and must be matched with a close brace
095 canvas.addSprite(dot); /**method calls/definitions*/
096 canvas.addSprite(redDot);
097 canvas.addSprite(blueDot);
098 canvas.addSprite(scoreSprite);
099 canvas.addSprite(timerSprite);
100 }close braces end code blocks and must match an earlier open brace
101
102 /**Method declaration and definition forfor is a looping structure for repeatedly executing a block of code the time clock*/
103 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
104 {open braces start code blocks and must be matched with a close brace
105 timerSprite.setText("Timer: " +adds two numbers together or concatenates Strings together timeLeft);
106 }close braces end code blocks and must match an earlier open brace
107
108 /**Method declaration and definition forfor is a looping structure for repeatedly executing a block of code randomly positioning the dot*/
109 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
110 {open braces start code blocks and must be matched with a close brace
111 sprite.setLocation(random.nextDouble(),random.nextDouble());
112 }close braces end code blocks and must match an earlier open brace
113
114 /**Method declaration and definition forfor is a looping structure for repeatedly executing a block of code updating the score*/
115 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
116 {open braces start code blocks and must be matched with a close brace
117 scoreSprite.setText("Score: " +adds two numbers together or concatenates Strings together score);
118 }close braces end code blocks and must match an earlier open brace
119
120 /**Method declaration and definitions forfor is a looping structure for repeatedly executing a block of code dot collisions*/
121 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
122 {open braces start code blocks and must be matched with a close brace
123 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot)) /**If the dot intersects the blue dot*/
124 {open braces start code blocks and must be matched with a close brace
125 repositionRandomly(blueDot); /**then randomly reposition the blue dot*/
126 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE)) /**Also ifif executes the next statement only if the condition in parenthesis evaluates to true they are the same color*/
127 {open braces start code blocks and must be matched with a close brace
128 dot.setColor(Color.RED); /**then turn the blue dot into a red dot*/
129 score++this is the increment operator, which increases the variable by 1;
130 /**and increase the score by one*/
131 }close braces end code blocks and must match an earlier open brace
132 elseelse is what happens when the if condition is false
133 /**Else the dots dodo is part of the do-while looping structure (post condition loop) not change color*/
134 {open braces start code blocks and must be matched with a close brace
135 score--this is the decrement operator, which decreases the variable by 1;
136 /**and decrease the score by one*/
137 }close braces end code blocks and must match an earlier open brace
138 updateScore();
139 /**Update the current score*/
140 }close braces end code blocks and must match an earlier open brace
141 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot)) /**ifif executes the next statement only if the condition in parenthesis evaluates to true the dot intersects the red dot*/
142 {open braces start code blocks and must be matched with a close brace
143 repositionRandomly(redDot);
144 /**then randomly reposition the red dot*/
145 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED)) /**also ifif executes the next statement only if the condition in parenthesis evaluates to true they are the same color*/
146 {open braces start code blocks and must be matched with a close brace
147 dot.setColor(Color.BLUE); /**then turn the red dot into a blue dot*/
148 score++this is the increment operator, which increases the variable by 1;
149 /**and increase the score by one*/
150 }close braces end code blocks and must match an earlier open brace
151 elseelse is what happens when the if condition is false
152 /**or elseelse is what happens when the if condition is false the dots change color*/
153 {open braces start code blocks and must be matched with a close brace
154 score--this is the decrement operator, which decreases the variable by 1;
155 /**decrease the score by one*/
156 }close braces end code blocks and must match an earlier open brace
157 updateScore();
158 /**and keep the current score*/
159 }close braces end code blocks and must match an earlier open brace
160 }close braces end code blocks and must match an earlier open brace
161
162 /**Method declaration and definitions forfor is a looping structure for repeatedly executing a block of code moving the dot object*/
163 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) /**method declaration*/
164 {open braces start code blocks and must be matched with a close brace
165 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft > 0)
166 {open braces start code blocks and must be matched with a close brace
167 Point2D.Double mouse =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getLocation();
168 /** give the object mouse a value*/
169 dot.setLocation(mouse);
170 /**calls the helper method to move the dot where ever the mouse moves*/
171 handleCollisions();
172 /**calls the helper method forfor is a looping structure for repeatedly executing a block of code handling collisions*/
173 }close braces end code blocks and must match an earlier open brace
174 }close braces end code blocks and must match an earlier open brace
175 }close braces end code blocks and must match an earlier open brace
|
Compiler Errors:
----------
1. ERROR in Gerdes/Wackadot.java (at line 35)
scheduleRelative(new TimeUpdater(),1);
^^^^^^^^^^^^^^^^
The method scheduleRelative(Wackadot.TimeUpdater, int) is undefined for the type Wackadot
----------
2. ERROR in Gerdes/Wackadot.java (at line 37)
setHelpText("Lots of help text here later");
^^^^^^^^^^^
The method getPlayer() is undefined for the type Wackadot
----------
15 problems (15 errors)
Download/View Gerdes/Wackadot.java