|
001 packagepackage is used to name the directory or folder a class is in jay;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * My version of Whackadot!this is the not operator, which changes true to false and false to true
009 * @authorthis is the Javadoc tag for documenting who created the source code Jay
010 */
011 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 Whackadot extendsextends means to customize or extend the functionality of a class Game
012 {open braces start code blocks and must be matched with a close brace
013 privateprivate is used to restrict access to the current class only Sprite dot;
014 privateprivate is used to restrict access to the current class only Sprite redDot;
015 privateprivate is used to restrict access to the current class only Sprite blueDot;
016 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
017 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;
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 timeLeft;
019 privateprivate is used to restrict access to the current class only ImageSprite sprite;
020 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
021
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
023 {open braces start code blocks and must be matched with a close brace
024 score=this assignment operator makes the left side equal to the right side0;
025 timeLeft=this assignment operator makes the left side equal to the right side10;
026 makeSprites();
027 addSprites();
028 schedule(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
029 setHelpText("Lots of help text here later");
030 }close braces end code blocks and must match an earlier open brace
031 classclass is a group of fields and methods used for making objects TimeUpdater extendsextends means to customize or extend the functionality of a class TimedAction
032 {open braces start code blocks and must be matched with a close brace
033 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
034 {open braces start code blocks and must be matched with a close brace
035 timeLeft--this is the decrement operator, which decreases the variable by 1;
036 updateTimer();
037 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
038 {open braces start code blocks and must be matched with a close brace
039 schedule(thisthis means the current object (the implicit parameter), 1);
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 }close braces end code blocks and must match an earlier open brace
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 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);
046 dot.setScale(0.1);
047 dot.setLocation(0.5, 0.5);
048 dot.setColor(Color.RED);
049 }close braces end code blocks and must match an earlier open brace
050 {open braces start code blocks and must be matched with a close brace
051 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);
052 redDot.setScale(0.1);
053 redDot.setLocation(
054 randomDouble(),
055 randomDouble());
056 redDot.setColor(getColor("red"));
057
058 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);
059 blueDot.setScale(0.1);
060 blueDot.setLocation(
061 randomDouble(),
062 randomDouble());
063 blueDot.setColor(getColor("blue"));
064
065 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");
066 scoreSprite.setHeight(0.1);
067 scoreSprite.rightJustify();
068 scoreSprite.topJustify();
069 scoreSprite.setLocation(1, 0);
070 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);
071 timerSprite.leftJustify();
072 timerSprite.topJustify();
073 timerSprite.setHeight(0.1);
074 timerSprite.setLocation(0, 0);
075 sprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("HNI_0011.JPG");
076 sprite.setScale(1.0);
077 sprite.setLocation(0.5,0.5);
078
079 addSprite(sprite);
080 }close braces end code blocks and must match an earlier open brace
081 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
082 {open braces start code blocks and must be matched with a close brace
083 addSprite(dot);
084 addSprite(redDot);
085 addSprite(blueDot);
086 addSprite(scoreSprite);
087 addSprite(timerSprite);
088 }close braces end code blocks and must match an earlier open brace
089
090 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
091 {open braces start code blocks and must be matched with a close brace
092 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
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 repositionRandomly(Sprite sprite)
095 {open braces start code blocks and must be matched with a close brace
096 sprite.setLocation(
097 randomDouble(),
098 randomDouble());
099 }close braces end code blocks and must match an earlier open brace
100 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
101 {open braces start code blocks and must be matched with a close brace
102 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
103 }close braces end code blocks and must match an earlier open brace
104
105 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
106 {open braces start code blocks and must be matched with a close brace
107 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
108 {open braces start code blocks and must be matched with a close brace
109 repositionRandomly(blueDot);
110 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(getColor("blue")))
111 {open braces start code blocks and must be matched with a close brace
112 dot.setColor(getColor("red"));
113 score++this is the increment operator, which increases the variable by 1;
114 }close braces end code blocks and must match an earlier open brace
115 elseelse is what happens when the if condition is false
116 {open braces start code blocks and must be matched with a close brace
117 score--this is the decrement operator, which decreases the variable by 1;
118 }close braces end code blocks and must match an earlier open brace
119 updateScore();
120
121 }close braces end code blocks and must match an earlier open brace
122 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
123 {open braces start code blocks and must be matched with a close brace
124 repositionRandomly(redDot);
125 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(getColor("red")))
126 {open braces start code blocks and must be matched with a close brace
127 dot.setColor(getColor("blue"));
128 score++this is the increment operator, which increases the variable by 1;
129 }close braces end code blocks and must match an earlier open brace
130 elseelse is what happens when the if condition is false
131 {open braces start code blocks and must be matched with a close brace
132 score--this is the decrement operator, which decreases the variable by 1;
133 }close braces end code blocks and must match an earlier open brace
134 updateScore();
135
136 }close braces end code blocks and must match an earlier open brace
137 }close braces end code blocks and must match an earlier open brace
138
139 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
140 {open braces start code blocks and must be matched with a close brace
141 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
142 {open braces start code blocks and must be matched with a close brace
143 Location2D mouse=this assignment operator makes the left side equal to the right side
144 getMouse2D();
145 dot.setLocation(mouse);
146 handleCollisions();
147 }close braces end code blocks and must match an earlier open brace
148 }close braces end code blocks and must match an earlier open brace
149
150
151 }close braces end code blocks and must match an earlier open brace
|