From ggc
|
001 packagepackage is used to name the directory or folder a class is in Stephanie.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 /**This is a fun, simple game I made using
009 * the FANG Engine.
010 * @authorthis is the Javadoc tag for documenting who created the source code Stephanie
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 ImageSprite redDot;
016 privateprivate is used to restrict access to the current class only ImageSprite blueDot;
017 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
018 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;
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 timeLeft;
020 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
021 privateprivate is used to restrict access to the current class only Sound sound=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("DingLower.wav");
022 privateprivate is used to restrict access to the current class only Sound sound2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Drums.wav");
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 setHelpText("Try to get the same images hit. If you make the right ones hit, you get a point. Watch out, if you hit the wrong image you lose a point.");
032 }close braces end code blocks and must match an earlier open brace
033
034 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
035 {open braces start code blocks and must be matched with a close brace
036 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
037 {open braces start code blocks and must be matched with a close brace
038 timeLeft--this is the decrement operator, which decreases the variable by 1;
039 updateTimer();
040 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
041 {open braces start code blocks and must be matched with a close brace
042 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
043 sound.play();
044 }close braces end code blocks and must match an earlier open brace
045 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>5)
046 {open braces start code blocks and must be matched with a close brace
047 sound2.play();
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 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
053 {open braces start code blocks and must be matched with a close brace
054 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Heart1.gif");
055 dot.setScale(0.1);
056 dot.setLocation(0.5, 0.5);
057 dot.setColor(Color.RED);
058
059 redDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Heart1.gif");
060 redDot.setScale(0.1);
061 redDot.setLocation(
062 random.nextDouble(),
063 random.nextDouble());
064 redDot.setColor(Color.RED);
065
066 blueDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Smiley.jpg");
067 blueDot.setScale(0.1);
068 blueDot.setLocation(
069 random.nextDouble(),
070 random.nextDouble());
071 blueDot.setColor(Color.BLUE);
072
073
074 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);
075 scoreSprite.setHeight(0.1);
076 scoreSprite.rightJustify();
077 scoreSprite.topJustify();
078 scoreSprite.setLocation(1, 0);
079 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);
080 timerSprite.leftJustify();
081 timerSprite.topJustify();
082 timerSprite.setHeight(0.1);
083 timerSprite.setLocation(0, 0);
084
085 }close braces end code blocks and must match an earlier open brace
086
087 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
088 {open braces start code blocks and must be matched with a close brace
089 canvas.addSprite(dot);
090 canvas.addSprite(redDot);
091 canvas.addSprite(blueDot);
092 canvas.addSprite(scoreSprite);
093 canvas.addSprite(timerSprite);
094 }close braces end code blocks and must match an earlier open brace
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
096 {open braces start code blocks and must be matched with a close brace
097 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
098 }close braces end code blocks and must match an earlier open brace
099
100
101 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
102 {open braces start code blocks and must be matched with a close brace
103 sprite.setLocation(
104 random.nextDouble(),
105 random.nextDouble());
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 updateScore()
109 {open braces start code blocks and must be matched with a close brace
110 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
111 }close braces end code blocks and must match an earlier open brace
112
113 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
114 {open braces start code blocks and must be matched with a close brace
115 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
116 {open braces start code blocks and must be matched with a close brace
117 repositionRandomly(blueDot);
118 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
119 {open braces start code blocks and must be matched with a close brace
120 dot.setImage("Heart1.gif");
121 dot.setColor(Color.RED);
122 score++this is the increment operator, which increases the variable by 1;
123 }close braces end code blocks and must match an earlier open brace
124 elseelse is what happens when the if condition is false
125 {open braces start code blocks and must be matched with a close brace
126 score--this is the decrement operator, which decreases the variable by 1;
127 }close braces end code blocks and must match an earlier open brace
128 updateScore();
129
130 }close braces end code blocks and must match an earlier open brace
131 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
132 {open braces start code blocks and must be matched with a close brace
133 repositionRandomly(redDot);
134 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
135 {open braces start code blocks and must be matched with a close brace
136 dot.setImage("Smiley.jpg");
137 dot.setColor(Color.BLUE);
138 score++this is the increment operator, which increases the variable by 1;
139 }close braces end code blocks and must match an earlier open brace
140 elseelse is what happens when the if condition is false
141 {open braces start code blocks and must be matched with a close brace
142 score--this is the decrement operator, which decreases the variable by 1;
143 }close braces end code blocks and must match an earlier open brace
144 updateScore();
145
146 }close braces end code blocks and must match an earlier open brace
147 }close braces end code blocks and must match an earlier open brace
148
149
150 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)
151 {open braces start code blocks and must be matched with a close brace
152 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
153 {open braces start code blocks and must be matched with a close brace
154 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
155 getPlayer().getMouse().getLocation();
156 dot.setLocation(mouse);
157 handleCollisions();
158 }close braces end code blocks and must match an earlier open brace
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
|
Download/View Stephanie/wackadot/Wackadot.java