|
001 packagepackage is used to name the directory or folder a class is in RobertKing.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 * Fang Engine
010 * @authorthis is the Javadoc tag for documenting who created the source code Rking
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
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
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 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
029 setHelpText("Move the dot to its same color without colliding with the opposite color");
030 }close braces end code blocks and must match an earlier open brace
031
032 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
033 {open braces start code blocks and must be matched with a close brace
034 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
035 {open braces start code blocks and must be matched with a close brace
036 timeLeft--this is the decrement operator, which decreases the variable by 1;
037 updateTimer();
038 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
039 {open braces start code blocks and must be matched with a close brace
040 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
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 }close braces end code blocks and must match an earlier open brace
044 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
045 {open braces start code blocks and must be matched with a close brace
046 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
047 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
048
049 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
050 dot.setScale(0.1);
051 dot.setLocation(0.5, 0.5);
052 dot.setColor(Color.RED);
053
054 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);
055 redDot.setScale(0.1);
056 redDot.setLocation(
057 random.nextDouble(),
058 random.nextDouble());
059 redDot.setColor(Color.RED);
060
061 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);
062 blueDot.setScale(0.1);
063 blueDot.setLocation(
064 random.nextDouble(),
065 random.nextDouble());
066 blueDot.setColor(Color.BLUE);
067
068 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);
069 scoreSprite.setHeight(0.1);
070 scoreSprite.rightJustify();
071 scoreSprite.topJustify();
072 scoreSprite.setLocation(1, 0);
073
074 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);
075 timerSprite.leftJustify();
076 timerSprite.topJustify();
077 timerSprite.setHeight(0.1);
078 timerSprite.setLocation(0, 0);
079 }close braces end code blocks and must match an earlier open brace
080
081 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
082 {open braces start code blocks and must be matched with a close brace
083 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
084 }close braces end code blocks and must match an earlier open brace
085
086 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
087 {open braces start code blocks and must be matched with a close brace
088 canvas.addSprite(dot);
089 canvas.addSprite(redDot);
090 canvas.addSprite(blueDot);
091 canvas.addSprite(scoreSprite);
092 canvas.addSprite(timerSprite);
093 }close braces end code blocks and must match an earlier open brace
094
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 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
101 {open braces start code blocks and must be matched with a close brace
102 sprite.setLocation(
103 random.nextDouble(),
104 random.nextDouble());
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 handleCollisions()
108 {open braces start code blocks and must be matched with a close brace
109 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
110 {open braces start code blocks and must be matched with a close brace
111 repositionRandomly(blueDot);
112 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
113 {open braces start code blocks and must be matched with a close brace
114 dot.setColor(Color.RED);
115 score++this is the increment operator, which increases the variable by 1;
116 }close braces end code blocks and must match an earlier open brace
117 elseelse is what happens when the if condition is false
118 {open braces start code blocks and must be matched with a close brace
119 score--this is the decrement operator, which decreases the variable by 1;
120 }close braces end code blocks and must match an earlier open brace
121 updateScore();
122 }close braces end code blocks and must match an earlier open brace
123
124 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
125 {open braces start code blocks and must be matched with a close brace
126 repositionRandomly(redDot);
127 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
128 {open braces start code blocks and must be matched with a close brace
129 dot.setColor(Color.BLUE);
130 score++this is the increment operator, which increases the variable by 1;
131 }close braces end code blocks and must match an earlier open brace
132 elseelse is what happens when the if condition is false
133 {open braces start code blocks and must be matched with a close brace
134 score--this is the decrement operator, which decreases the variable by 1;
135 }close braces end code blocks and must match an earlier open brace
136 updateScore();
137 }close braces end code blocks and must match an earlier open brace
138 }close braces end code blocks and must match an earlier open brace
139
140 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)
141 {open braces start code blocks and must be matched with a close brace
142 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
143 {open braces start code blocks and must be matched with a close brace
144 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
145 getPlayer().getMouse().getLocation();
146 dot.setLocation(mouse);
147 handleCollisions();
148 }close braces end code blocks and must match an earlier open brace
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
|