|
001 packagepackage is used to name the directory or folder a class is in HemendraPullay.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 * @authorthis is the Javadoc tag for documenting who created the source code Hpullay
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 Sprite dot;
015 privateprivate is used to restrict access to the current class only Sprite redDot;
016 privateprivate is used to restrict access to the current class only Sprite 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 ImageSprite sprite;
022 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("Excuseme.wav"));
023 Sound sound1=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"));
024
025
026 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
027 {open braces start code blocks and must be matched with a close brace
028 score=this assignment operator makes the left side equal to the right side0;
029 timeLeft=this assignment operator makes the left side equal to the right side60;
030 makeSprites();
031 addSprites();
032 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
033 sound.play();
034 }close braces end code blocks and must match an earlier open brace
035
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
049 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
050 {open braces start code blocks and must be matched with a close brace
051
052 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("Evo.jpg"));
053 sprite.setScale(.9);
054 sprite.setLocation(.5,.5);
055
056 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
057 dot.setScale(0.1);
058 dot.setLocation(0.5, 0.5);
059 dot.setColor(Color.RED);
060
061 redDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
062 redDot.setScale(0.1);
063 redDot.setLocation(
064 random.nextDouble(),
065 random.nextDouble());
066 redDot.setColor(Color.RED);
067
068 blueDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
069 blueDot.setScale(0.1);
070 blueDot.setLocation(
071 random.nextDouble(),
072 random.nextDouble());
073
074 blueDot.setColor(Color.BLUE);
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
078 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");
079 scoreSprite.setHeight(0.1);
080 scoreSprite.rightJustify();
081 scoreSprite.topJustify();
082 scoreSprite.setLocation(1, 0);
083
084 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);
085 timerSprite.leftJustify();
086 timerSprite.topJustify();
087 timerSprite.setHeight(0.1);
088 timerSprite.setLocation(0, 0);
089
090
091
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 updateScore()
095 {open braces start code blocks and must be matched with a close brace
096 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
097 }close braces end code blocks and must match an earlier open brace
098
099
100 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
101 {open braces start code blocks and must be matched with a close brace
102 canvas.addSprite(sprite);
103 canvas.addSprite(dot);
104 canvas.addSprite(redDot);
105 canvas.addSprite(blueDot);
106 canvas.addSprite(scoreSprite);
107 canvas.addSprite(timerSprite);
108 }close braces end code blocks and must match an earlier open brace
109
110 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
111 {open braces start code blocks and must be matched with a close brace
112 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
113 }close braces end code blocks and must match an earlier open brace
114
115 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)
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(timeLeft>0)
118 {open braces start code blocks and must be matched with a close brace
119 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
120 getPlayer().getMouse().getLocation();
121 dot.setLocation(mouse);
122 handleCollisions();
123 }close braces end code blocks and must match an earlier open brace
124 }close braces end code blocks and must match an earlier open brace
125
126 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
127 {open braces start code blocks and must be matched with a close brace
128 sprite.setLocation(
129 random.nextDouble(),
130 random.nextDouble());
131 }close braces end code blocks and must match an earlier open brace
132
133 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
134 {open braces start code blocks and must be matched with a close brace
135 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
136 {open braces start code blocks and must be matched with a close brace
137 repositionRandomly(blueDot);
138 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
139 {open braces start code blocks and must be matched with a close brace
140 dot.setColor(Color.RED);
141 score++this is the increment operator, which increases the variable by 1;
142 }close braces end code blocks and must match an earlier open brace
143 elseelse is what happens when the if condition is false
144 {open braces start code blocks and must be matched with a close brace
145 sound1.play();
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 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
151 {open braces start code blocks and must be matched with a close brace
152 repositionRandomly(redDot);
153 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
154 {open braces start code blocks and must be matched with a close brace
155 dot.setColor(Color.BLUE);
156 score++this is the increment operator, which increases the variable by 1;
157 }close braces end code blocks and must match an earlier open brace
158 elseelse is what happens when the if condition is false
159 {open braces start code blocks and must be matched with a close brace
160 score--this is the decrement operator, which decreases the variable by 1;
161 }close braces end code blocks and must match an earlier open brace
162 updateScore();
163 }close braces end code blocks and must match an earlier open brace
164 }close braces end code blocks and must match an earlier open brace
165
166
167 }close braces end code blocks and must match an earlier open brace
|