|
001 packagepackage is used to name the directory or folder a class is in Valerie.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
006 /**This is a fun, simple game I made using
007 * the FANG Engine.
008 * @authorthis is the Javadoc tag for documenting who created the source code Valerie
009 */
010
011 importimport means to make the classes and/or packages available in this program java.awt.*;
012 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
013
014 /**
015 * All about my game here.
016 * @authorthis is the Javadoc tag for documenting who created the source code Valerie Hagen
017 */
018
019 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
020 {open braces start code blocks and must be matched with a close brace
021
022 privateprivate is used to restrict access to the current class only ImageSprite dot;
023
024 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
025 {open braces start code blocks and must be matched with a close brace
026 score=this assignment operator makes the left side equal to the right side0;
027 timeLeft=this assignment operator makes the left side equal to the right side10;
028 makeSprites();
029 addSprites();
030 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
031 setHelp("resources/WackadotHelp.html");
032 toggleAudible();
033
034
035 }close braces end code blocks and must match an earlier open brace
036 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
037 {open braces start code blocks and must be matched with a close brace
038 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
039 {open braces start code blocks and must be matched with a close brace
040 timeLeft--this is the decrement operator, which decreases the variable by 1;
041 updateTimer();
042 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
043 {open braces start code blocks and must be matched with a close brace
044 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
045 }close braces end code blocks and must match an earlier open brace
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 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
049 {open braces start code blocks and must be matched with a close brace
050 {open braces start code blocks and must be matched with a close brace
051 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
052 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
053
054 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("Dog.gif"));
055 dot.setScale(0.1);
056 dot.setLocation(0.5, 0.5);
057 dot.setColor(Color.RED);
058
059
060 redDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Dog.gif"));
061 redDot.setScale(0.1);
062 redDot.setLocation(
063 random.nextDouble(),
064 random.nextDouble());
065 redDot.setColor(Color.RED);
066
067
068 blueDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Earth.gif"));
069 blueDot.setScale(0.1);
070 blueDot.setLocation(
071 random.nextDouble(),
072 random.nextDouble());
073 blueDot.setColor(Color.BLUE);
074
075
076 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);
077 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score: 0");
078 scoreSprite.setHeight(0.1);
079 scoreSprite.rightJustify();
080 scoreSprite.topJustify();
081 scoreSprite.setLocation(1, 0);
082
083 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);
084 timerSprite.leftJustify();
085 timerSprite.topJustify();
086 timerSprite.setHeight(0.1);
087 timerSprite.setLocation(0, 0);
088 }close braces end code blocks and must match an earlier open brace
089 }close braces end code blocks and must match an earlier open brace
090 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
091 {open braces start code blocks and must be matched with a close brace
092 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
093 }close braces end code blocks and must match an earlier open brace
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(redDot);
098 canvas.addSprite(blueDot);
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 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 togethertimeLeft);
106 }close braces end code blocks and must match an earlier open brace
107
108 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
109 {open braces start code blocks and must be matched with a close brace
110 sprite.setLocation(
111 random.nextDouble(),
112 random.nextDouble());
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 handleCollisions()
116 {open braces start code blocks and must be matched with a close brace
117 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
118 {open braces start code blocks and must be matched with a close brace
119 repositionRandomly(blueDot);
120 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
121 {open braces start code blocks and must be matched with a close brace
122 dot.setImage(Wiki.getMedia("Dog.gif"));
123 dot.setColor(Color.RED);
124 score++this is the increment operator, which increases the variable by 1;
125 sound.play(0.25);
126 }close braces end code blocks and must match an earlier open brace
127 elseelse is what happens when the if condition is false
128 {open braces start code blocks and must be matched with a close brace
129 score--this is the decrement operator, which decreases the variable by 1;
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(redDot))
134 {open braces start code blocks and must be matched with a close brace
135 repositionRandomly(redDot);
136 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
137 {open braces start code blocks and must be matched with a close brace
138 dot.setImage(Wiki.getMedia("Earth.gif"));
139 dot.setColor(Color.BLUE);
140 score++this is the increment operator, which increases the variable by 1;
141 sound.play(0.25);
142
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 score--this is the decrement operator, which decreases the variable by 1;
147 }close braces end code blocks and must match an earlier open brace
148 updateScore();
149 }close braces end code blocks and must match an earlier open brace
150 }close braces end code blocks and must match an earlier open brace
151 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)
152 {open braces start code blocks and must be matched with a close brace
153 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
154 {open braces start code blocks and must be matched with a close brace
155 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
156 getPlayer(0).getMouse().getLocation();
157 dot.setLocation(mouse);
158 handleCollisions();
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 privateprivate is used to restrict access to the current class only ImageSprite redDot;
162 privateprivate is used to restrict access to the current class only ImageSprite blueDot;
163
164 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
165
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
168 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;
169 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
170
171 Sound 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("Pop.wav"));
172
173 privateprivate is used to restrict access to the current class only ImageSprite sprite;
174 }close braces end code blocks and must match an earlier open brace
175
176
|