From ggc
|
001 packagepackage is used to name the directory or folder a class is in ThomasJohanningmeier.wackadot;
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 is based on the game Wackadot.
010 * Author: Thomas Johanningmeier
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 extendsextends means to customize or extend the functionality of a class GameLoop
013 {open braces start code blocks and must be matched with a close brace
014 privateprivate is used to restrict access to the current class only ImageSprite dot;
015 privateprivate is used to restrict access to the current class only Sound sound;
016 privateprivate is used to restrict access to the current class only Sound sound2;
017 privateprivate is used to restrict access to the current class only ImageSprite sprite;
018
019 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
020 {open braces start code blocks and must be matched with a close brace
021 score=this assignment operator makes the left side equal to the right side0;
022 timeLeft=this assignment operator makes the left side equal to the right side30;
023 makeSprites();
024 addSprites();
025 scheduleRelative(newnew is used to create objects by calling the constructor TimerUpdater(), 1);
026 setHelp("resources/WackadotHelp.html");
027 makeSounds();
028 toggleAudible();
029 }close braces end code blocks and must match an earlier open brace
030 classclass is a group of fields and methods used for making objects TimerUpdater implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
031 {open braces start code blocks and must be matched with a close brace
032 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
033 {open braces start code blocks and must be matched with a close brace
034 timeLeft--this is the decrement operator, which decreases the variable by 1;
035 updateTimer();
036 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
037 {open braces start code blocks and must be matched with a close brace
038 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
039 }close braces end code blocks and must match an earlier open brace
040 }close braces end code blocks and must match an earlier open brace
041 }close braces end code blocks and must match an earlier open brace
042
043 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
044 {open braces start code blocks and must be matched with a close brace
045 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
046 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
047
048 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("bomb.gif"));
049 dot.setScale(0.25);
050 dot.setLocation(0.5, 0.5);
051 dot.setColor(Color.GREEN);
052
053 greenDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("bomb.gif"));
054 greenDot.setScale(0.25);
055 greenDot.setLocation(
056 random.nextDouble(),
057 random.nextDouble());
058 greenDot.setColor(Color.GREEN);
059
060 yellowDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("coin1.gif"));
061 yellowDot.setScale(0.25);
062 yellowDot.setLocation(
063 random.nextDouble(),
064 random.nextDouble());
065 yellowDot.setColor(Color.YELLOW);
066
067 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score: "+adds two numbers together or concatenates Strings togetherscore);
068 scoreSprite.setHeight(0.1);
069 scoreSprite.rightJustify();
070 scoreSprite.topJustify();
071 scoreSprite.setLocation(1, 0);
072
073 timerSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
074 timerSprite.setHeight(0.1);
075 timerSprite.leftJustify();
076 timerSprite.topJustify();
077 timerSprite.setLocation(0, 0);
078
079 }close braces end code blocks and must match an earlier open brace
080 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSounds()
081 {open braces start code blocks and must be matched with a close brace
082 sound=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("cash_register.wav"));
083 sound2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("boo.wav"));
084 }close braces end code blocks and must match an earlier open brace
085 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
086 {open braces start code blocks and must be matched with a close brace
087 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
088 }close braces end code blocks and must match an earlier open brace
089 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
090 {open braces start code blocks and must be matched with a close brace
091 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
092 }close braces end code blocks and must match an earlier open brace
093
094 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
095 {open braces start code blocks and must be matched with a close brace
096 canvas.addSprite(dot);
097 canvas.addSprite(greenDot);
098 canvas.addSprite(yellowDot);
099 canvas.addSprite(scoreSprite);
100 canvas.addSprite(timerSprite);
101 }close braces end code blocks and must match an earlier open brace
102
103 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
104 {open braces start code blocks and must be matched with a close brace
105
106 sprite.setLocation(
107 random.nextDouble(),
108 random.nextDouble());
109 }close braces end code blocks and must match an earlier open brace
110
111 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
112 {open braces start code blocks and must be matched with a close brace
113 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(yellowDot))
114 {open braces start code blocks and must be matched with a close brace
115
116 repositionRandomly(yellowDot);
117 ifif executes the next statement only if the condition in parenthesis evaluates to true (dot.getColor().equals(Color.YELLOW))
118
119 {open braces start code blocks and must be matched with a close brace
120 dot.setImage(Wiki.getMedia("bomb.gif"));
121 dot.setColor(Color.GREEN);
122 score++this is the increment operator, which increases the variable by 1;
123 sound.play();
124
125 }close braces end code blocks and must match an earlier open brace
126 elseelse is what happens when the if condition is false
127 {open braces start code blocks and must be matched with a close brace
128 score--this is the decrement operator, which decreases the variable by 1;
129 sound2.play();
130 }close braces end code blocks and must match an earlier open brace
131 updateScore();
132 }close braces end code blocks and must match an earlier open brace
133 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(greenDot))
134 {open braces start code blocks and must be matched with a close brace
135
136 repositionRandomly(greenDot);
137 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.GREEN))
138
139 {open braces start code blocks and must be matched with a close brace
140 dot.setImage(Wiki.getMedia("coin1.gif"));
141 dot.setColor(Color.YELLOW);
142 score++this is the increment operator, which increases the variable by 1;
143 sound.play();
144 }close braces end code blocks and must match an earlier open brace
145 elseelse is what happens when the if condition is false
146 {open braces start code blocks and must be matched with a close brace
147 score--this is the decrement operator, which decreases the variable by 1;
148 sound2.play();
149 }close braces end code blocks and must match an earlier open brace
150 updateScore();
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 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)
154 {open braces start code blocks and must be matched with a close brace
155 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
156 {open braces start code blocks and must be matched with a close brace
157 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
158 getPlayer().getMouse().getLocation();
159 dot.setLocation(mouse);
160 handleCollisions();
161 }close braces end code blocks and must match an earlier open brace
162 }close braces end code blocks and must match an earlier open brace
163 privateprivate is used to restrict access to the current class only Sprite greenDot;
164 privateprivate is used to restrict access to the current class only Sprite yellowDot;
165 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
166 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;
167 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;
168 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
169 }close braces end code blocks and must match an earlier open brace
|
Compiler Errors:
----------
1. ERROR in ThomasJohanningmeier/wackadot/Wackadot.java (at line 48)
dot=new ImageSprite(Wiki.getMedia("bomb.gif"));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in ThomasJohanningmeier/wackadot/Wackadot.java (at line 53)
greenDot=new ImageSprite(Wiki.getMedia("bomb.gif"));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method setImage(String) in the type ImageSprite is not applicable for the arguments (URL)
----------
5 problems (5 errors)
Download/View ThomasJohanningmeier/wackadot/Wackadot.java