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