|
001 packagepackage is used to name the directory or folder a class is in scg.ch13.highscore;
002
003 importimport means to make the classes and/or packages available in this program java.io.File;
004 importimport means to make the classes and/or packages available in this program java.io.FileNotFoundException;
005 importimport means to make the classes and/or packages available in this program java.io.PrintWriter;
006 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
007 importimport means to make the classes and/or packages available in this program java.util.Collections;
008 importimport means to make the classes and/or packages available in this program java.util.Scanner;
009
010 importimport means to make the classes and/or packages available in this program scg.ch13.core.BlockDrop;
011
012 importimport means to make the classes and/or packages available in this program fang2.core.Game;
013 importimport means to make the classes and/or packages available in this program fang2.sprites.InputStringField;
014 importimport means to make the classes and/or packages available in this program fang2.sprites.StringSprite;
015
016 /**
017 * This is the "attract" mode of {open braces start code blocks and must be matched with a close brace@link BlockDrop}close braces end code blocks and must match an earlier open brace. It reads in the high
018 * score file and displays the ten high score cyclically.
019 */
020 @SuppressWarnings("serial")
021 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 HighScoreLevel
022 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
023 /** the defaultdefault is what is executed when no cases are matched score file */
024 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) String DEFAULT_SCORE_FILENAME =this assignment operator makes the left side equal to the right side
025 "highScoreFile.txt";
026
027 /** maximum number of high scores to store */
028 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer MAX_HIGHSCORE_COUNT =this assignment operator makes the left side equal to the right side 10;
029
030 /** the score with which the previous {open braces start code blocks and must be matched with a close brace@link BlockDrop}close braces end code blocks and must match an earlier open brace ended */
031 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer currentScore;
032
033 /** the high score file name */
034 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) String fname;
035
036 /** string input forfor is a looping structure for repeatedly executing a block of code user to provide their name */
037 privateprivate is used to restrict access to the current class only InputStringField getUserName;
038
039 /** the list of HighScore objects */
040 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) ArrayList<HighScore> highScores;
041
042 /** game state variable: are we waiting forfor is a looping structure for repeatedly executing a block of code user to enter name? */
043 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false needHighScoreName;
044
045 /** scrolling message box containing high scores */
046 privateprivate is used to restrict access to the current class only ScrollingMessageBox showScores;
047
048 /**
049 * Construct a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link HighScoreLevel}close braces end code blocks and must match an earlier open brace game level using defaultdefault is what is executed when no cases are matched
050 * high score file name and a negative score.
051 */
052 publicpublic is used to indicate unrestricted access (any other class can have access) HighScoreLevel() {open braces start code blocks and must be matched with a close brace
053 thisthis means the current object (the implicit parameter)(-1);
054 }close braces end code blocks and must match an earlier open brace
055
056 /**
057 * Construct a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link HighScoreLevel}close braces end code blocks and must match an earlier open brace game level using defaultdefault is what is executed when no cases are matched
058 * high score file name and the given score
059 *
060 * @paramthis is the Javadoc tag for documenting the purpose of parameters currentScore the score of the current game; a negative
061 * number indicates there is no high score
062 */
063 publicpublic is used to indicate unrestricted access (any other class can have access) HighScoreLevel(intint is the type for whole numbers and it is short for integer currentScore) {open braces start code blocks and must be matched with a close brace
064 thisthis means the current object (the implicit parameter)(currentScore, DEFAULT_SCORE_FILENAME);
065 }close braces end code blocks and must match an earlier open brace
066
067 /**
068 * Construct the {open braces start code blocks and must be matched with a close brace@link HighScoreLevel}close braces end code blocks and must match an earlier open brace game level. The level reads a
069 * named high score file forfor is a looping structure for repeatedly executing a block of code displaying scores.
070 *
071 * @paramthis is the Javadoc tag for documenting the purpose of parameters currentScore the score of the current game; a negative
072 * number indicates there is no high score
073 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname name of the high score file
074 */
075 publicpublic is used to indicate unrestricted access (any other class can have access) HighScoreLevel(intint is the type for whole numbers and it is short for integer currentScore, String fname) {open braces start code blocks and must be matched with a close brace
076 thisthis means the current object (the implicit parameter).fname =this assignment operator makes the left side equal to the right side fname;
077 thisthis means the current object (the implicit parameter).currentScore =this assignment operator makes the left side equal to the right side currentScore;
078 highScores =this assignment operator makes the left side equal to the right side loadHighScores(fname);
079 whilewhile is a looping structure for executing code repeatedly (highScores.size() < MAX_HIGHSCORE_COUNT) {open braces start code blocks and must be matched with a close brace
080 highScores.add(newnew is used to create objects by calling the constructor HighScore(0, ""));
081 }close braces end code blocks and must match an earlier open brace
082 Collections.sort(highScores, Collections.reverseOrder());
083 }close braces end code blocks and must match an earlier open brace
084
085 /**
086 * Dispatch advance call depending on game state.
087 *
088 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT time, in seconds, since last advance call
089 */
090 @Override
091 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
092 ifif executes the next statement only if the condition in parenthesis evaluates to true (needHighScoreName) {open braces start code blocks and must be matched with a close brace
093 advanceGetHighScoreName(dT);
094 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
095 advanceScrollingScores(dT);
096 }close braces end code blocks and must match an earlier open brace
097 }close braces end code blocks and must match an earlier open brace
098
099 /**
100 * Setup the sprites forfor is a looping structure for repeatedly executing a block of code the level.
101 */
102 @Override
103 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
104 showScores =this assignment operator makes the left side equal to the right side makeShowScoresSprite();
105 addSprite(showScores);
106
107 StringSprite title =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite();// level title
108 title.setText("BlockDrop High Scores");
109 title.setLineHeight(0.1);
110 title.setLocation(0.5, 0.1);
111 title.setColor(getColor("red"));
112 addSprite(title);
113
114 StringSprite instruction =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite();// prompt user
115 instruction.setText("<Space> or Level (1-9) to Start");
116 instruction.setLineHeight(0.05);
117 instruction.setLocation(0.5, 0.20);
118 instruction.setColor(getColor("red").darker());
119 addSprite(instruction);
120
121 getUserName =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
122 ifif executes the next statement only if the condition in parenthesis evaluates to true (isAHighScore(currentScore)) {open braces start code blocks and must be matched with a close brace
123 needHighScoreName =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
124 getUserName =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor InputStringField(1.0, 0.2);
125 getUserName.setLocation(0.5, 0.4);
126 getUserName.setLabelText("Your Name");
127 addSprite(getUserName);
128 showScores.hide();
129 }close braces end code blocks and must match an earlier open brace
130 }close braces end code blocks and must match an earlier open brace
131
132 /**
133 * Advance one frame whilewhile is a looping structure for executing code repeatedly the player is typing in their name.
134 *
135 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT seconds since last call to advance
136 */
137 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value advanceGetHighScoreName(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
138 ifif executes the next statement only if the condition in parenthesis evaluates to true (getUserName.hasEnteredText()) {open braces start code blocks and must be matched with a close brace
139 String currentName =this assignment operator makes the left side equal to the right side getUserName.getEnteredText();
140 insertScore(currentScore, currentName);
141
142 removeSprite(getUserName);
143 getUserName =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
144
145 showScores.show();
146 needHighScoreName =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
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 * Pump (call advance on) the scrolling high scores. Check ifif executes the next statement only if the condition in parenthesis evaluates to true player
152 * has started the real game. Real game starts on pressing <space> or
153 * the number of the level on which you want to start.
154 *
155 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT seconds since last call to advance
156 */
157 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value advanceScrollingScores(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
158 showScores.advance(dT);
159 ifif executes the next statement only if the condition in parenthesis evaluates to true (keyPressed()) {open braces start code blocks and must be matched with a close brace
160 charchar is the type for a single letter or symbol and it is short for character key =this assignment operator makes the left side equal to the right side getKeyPressed();
161 ifif executes the next statement only if the condition in parenthesis evaluates to true ((key ==this is the comparison operator which evaluates to true if both sides are the same ' ') ||this is boolean or, meaning if either or both are true then the result is true (('1' <=this evaluates to true if the left side is not more than the right side key) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (key <=this evaluates to true if the left side is not more than the right side '9'))) {open braces start code blocks and must be matched with a close brace
162 intint is the type for whole numbers and it is short for integer level =this assignment operator makes the left side equal to the right side 1;
163 ifif executes the next statement only if the condition in parenthesis evaluates to true (('2' <=this evaluates to true if the left side is not more than the right side key) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (key <=this evaluates to true if the left side is not more than the right side '9')) {open braces start code blocks and must be matched with a close brace
164 level =this assignment operator makes the left side equal to the right side key - '0';
165 }close braces end code blocks and must match an earlier open brace
166 addGame(newnew is used to create objects by calling the constructor BlockDrop(level));
167 finishGame();
168 }close braces end code blocks and must match an earlier open brace
169 }close braces end code blocks and must match an earlier open brace
170 }close braces end code blocks and must match an earlier open brace
171
172 /**
173 * Add the given high score and resort the list. The list is sorted in
174 * reverse order (using {open braces start code blocks and must be matched with a close brace@link Collections}close braces end code blocks and must match an earlier open brace classclass is a group of fields and methods used for making objects staticstatic means that an instance is not required for access (class level access) methods)
175 *
176 * @paramthis is the Javadoc tag for documenting the purpose of parameters score score to add
177 * @paramthis is the Javadoc tag for documenting the purpose of parameters name name associated with the score
178 */
179 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value insertScore(intint is the type for whole numbers and it is short for integer score, String name) {open braces start code blocks and must be matched with a close brace
180 highScores.set(highScores.size() - 1, newnew is used to create objects by calling the constructor HighScore(score, name));
181 Collections.sort(highScores, Collections.reverseOrder());
182 saveHighScores();
183 ifif executes the next statement only if the condition in parenthesis evaluates to true (showScores !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
184 removeSprite(showScores);
185 }close braces end code blocks and must match an earlier open brace
186 showScores =this assignment operator makes the left side equal to the right side makeShowScoresSprite();
187 addSprite(showScores);
188 }close braces end code blocks and must match an earlier open brace
189
190 /**
191 * Is the given score a high score? Since the list of scores is
192 * sorted, a high score is any one that is bigger than the last score
193 * in the list.
194 *
195 * @paramthis is the Javadoc tag for documenting the purpose of parameters score score to check
196 *
197 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true the given score belongs on the list; falsefalse is a value for the boolean type and means not true
198 * otherwise
199 */
200 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false isAHighScore(intint is the type for whole numbers and it is short for integer score) {open braces start code blocks and must be matched with a close brace
201 intint is the type for whole numbers and it is short for integer lowestScoreIndex =this assignment operator makes the left side equal to the right side highScores.size() - 1;
202 returnreturn means to provide the result of the method and/or cease execution of the method immediately (score > highScores.get(lowestScoreIndex).getScore());
203 }close braces end code blocks and must match an earlier open brace
204
205 /**
206 * Load the given high score file. Lines in the high score file are
207 * score, space, name. Uses {open braces start code blocks and must be matched with a close brace@link Scanner}close braces end code blocks and must match an earlier open brace version of the {open braces start code blocks and must be matched with a close brace@link
208 * HighScore}close braces end code blocks and must match an earlier open brace constructor.
209 *
210 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname name of the file to load.
211 *
212 * @returnnull a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link ArrayList}close braces end code blocks and must match an earlier open brace of {open braces start code blocks and must be matched with a close brace@link HighScore}close braces end code blocks and must match an earlier open brace values.
213 */
214 privateprivate is used to restrict access to the current class only ArrayList<HighScore> loadHighScores(String fname) {open braces start code blocks and must be matched with a close brace
215 ArrayList<HighScore> hs =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<HighScore>();
216 File highScoreFile =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor File(fname);
217 trytry is for executing a code block that may experience exceptions (errors) {open braces start code blocks and must be matched with a close brace
218 Scanner highScoreInput =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(highScoreFile);
219 whilewhile is a looping structure for executing code repeatedly (highScoreInput.hasNextInt()) {open braces start code blocks and must be matched with a close brace
220 hs.add(newnew is used to create objects by calling the constructor HighScore(highScoreInput));
221 }close braces end code blocks and must match an earlier open brace
222 highScoreInput.close();
223 }close braces end code blocks and must match an earlier open brace catchcatch means to handle an exception that may occur (FileNotFoundException e) {open braces start code blocks and must be matched with a close brace
224 // It is okay if there is no such file; we will just ignore this
225 }close braces end code blocks and must match an earlier open brace
226 returnreturn means to provide the result of the method and/or cease execution of the method immediately hs;
227 }close braces end code blocks and must match an earlier open brace
228
229 /**
230 * Make a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link ScrollingMessageBox}close braces end code blocks and must match an earlier open brace containing the list of high
231 * scores. ALL positioning and stuff should go here so that {open braces start code blocks and must be matched with a close brace@link
232 * #insertScore(intint is the type for whole numbers and it is short for integer, String)}close braces end code blocks and must match an earlier open brace can build a proper replacement after a
233 * newnew is used to create objects by calling the constructor high score is added.
234 *
235 * @returnnull a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link ScrollingMessageBox}close braces end code blocks and must match an earlier open brace with high scores
236 */
237 privateprivate is used to restrict access to the current class only ScrollingMessageBox makeShowScoresSprite() {open braces start code blocks and must be matched with a close brace
238 ScrollingMessageBox ss =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ScrollingMessageBox();
239 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different highScores.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
240 intint is the type for whole numbers and it is short for integer displayIndex =this assignment operator makes the left side equal to the right side i +adds two numbers together or concatenates Strings together 1;
241 ss.add(highScores.get(i).toDisplayString(displayIndex));
242 }close braces end code blocks and must match an earlier open brace
243
244 // position the score showing sprite where we want it
245 ss.setColor(getColor("pink"));
246 ss.setScale(0.67);
247 ss.setLocation(0.5, 0.67);
248
249 returnreturn means to provide the result of the method and/or cease execution of the method immediately ss;
250 }close braces end code blocks and must match an earlier open brace
251
252 /**
253 * Save the current high score values to the file from which the high
254 * scores were loaded.
255 */
256 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value saveHighScores() {open braces start code blocks and must be matched with a close brace
257 File saveFile =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor File(fname);
258 PrintWriter saveFileWriter;
259 trytry is for executing a code block that may experience exceptions (errors) {open braces start code blocks and must be matched with a close brace
260 saveFileWriter =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PrintWriter(saveFile);
261 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different highScores.size(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
262 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truehighScores.get(i).isEmpty()) {open braces start code blocks and must be matched with a close brace
263 saveFileWriter.println(highScores.get(i));
264 }close braces end code blocks and must match an earlier open brace
265 }close braces end code blocks and must match an earlier open brace
266 saveFileWriter.close();
267 }close braces end code blocks and must match an earlier open brace catchcatch means to handle an exception that may occur (FileNotFoundException e) {open braces start code blocks and must be matched with a close brace
268 System.err.println("Unable to open " +adds two numbers together or concatenates Strings together fname +adds two numbers together or concatenates Strings together
269 " for output; high score file not saved");
270 }close braces end code blocks and must match an earlier open brace
271 }close braces end code blocks and must match an earlier open brace
272 // ----- NESTED PRIVATE CLASSES -----
273
274 /**
275 * Nested privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects. A classclass is a group of fields and methods used for making objects which is privateprivate is used to restrict access to the current class only to just thisthis means the current object (the implicit parameter) classclass is a group of fields and methods used for making objects.
276 * No other classclass is a group of fields and methods used for making objects in the game need know anything about it. This game
277 * level displays a scrolling list of high scores. This classclass is a group of fields and methods used for making objects keeps
278 * the name, the score, and a {open braces start code blocks and must be matched with a close brace@link StringSprite}close braces end code blocks and must match an earlier open brace grouped together.
279 * The classclass is a group of fields and methods used for making objects extendsextends means to customize or extend the functionality of a class {open braces start code blocks and must be matched with a close brace@link StringSprite}close braces end code blocks and must match an earlier open brace (so it can be added to the
280 * game and displayed directly). It also implementsimplements means providing method bodies for the methods declared in the corresponding interface the {open braces start code blocks and must be matched with a close brace@link
281 * Comparable}close braces end code blocks and must match an earlier open brace interfaceinterface is a named collection of declared methods; thisthis means the current object (the implicit parameter) interfaceinterface is a named collection of declared methods lets us use a built-in Java
282 * sort rather than having to write our own again.
283 */
284 privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects HighScore
285 implementsimplements means providing method bodies for the methods declared in the corresponding interface Comparable<HighScore> {open braces start code blocks and must be matched with a close brace
286 /** number of characters used in the full-width name */
287 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer SIGNIFICANT_CHARACTERS =this assignment operator makes the left side equal to the right side 10;
288
289 /** padding string, appended to name and then name is chopped */
290 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) String SIGNIFICANT_PADDING =this assignment operator makes the left side equal to the right side
291 " ................";
292
293 /** the name associated with thisthis means the current object (the implicit parameter) score */
294 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) String name;
295
296 /** the score */
297 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer score;
298
299 /**
300 * Create a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link HighScore}close braces end code blocks and must match an earlier open brace object with the given values.
301 *
302 * @paramthis is the Javadoc tag for documenting the purpose of parameters score the newnew is used to create objects by calling the constructor high score's score
303 * @paramthis is the Javadoc tag for documenting the purpose of parameters name the name of the player with the high score
304 */
305 publicpublic is used to indicate unrestricted access (any other class can have access) HighScore(intint is the type for whole numbers and it is short for integer score, String name) {open braces start code blocks and must be matched with a close brace
306 thisthis means the current object (the implicit parameter).score =this assignment operator makes the left side equal to the right side score;
307 thisthis means the current object (the implicit parameter).name =this assignment operator makes the left side equal to the right side name;
308 }close braces end code blocks and must match an earlier open brace
309
310 /**
311 * Create a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link HighScore}close braces end code blocks and must match an earlier open brace by reading field values from the
312 * given {open braces start code blocks and must be matched with a close brace@link Scanner}close braces end code blocks and must match an earlier open brace. {open braces start code blocks and must be matched with a close brace@link HighScore}close braces end code blocks and must match an earlier open brace formatting is a single
313 * line with the score, a space, and the name: <score> <name> The
314 * name finishes out the line so it can contain spaces.
315 *
316 * @paramthis is the Javadoc tag for documenting the purpose of parameters highScoreInput the {open braces start code blocks and must be matched with a close brace@link Scanner}close braces end code blocks and must match an earlier open brace open on a high score
317 * file
318 */
319 publicpublic is used to indicate unrestricted access (any other class can have access) HighScore(Scanner highScoreInput) {open braces start code blocks and must be matched with a close brace
320 thisthis means the current object (the implicit parameter).score =this assignment operator makes the left side equal to the right side highScoreInput.nextInt();
321 highScoreInput.skip(" ");// skip over one space
322 thisthis means the current object (the implicit parameter).name =this assignment operator makes the left side equal to the right side highScoreInput.nextLine();
323 }close braces end code blocks and must match an earlier open brace
324
325 /**
326 * Required by the {open braces start code blocks and must be matched with a close brace@link Comparable}close braces end code blocks and must match an earlier open brace interfaceinterface is a named collection of declared methods. As defined forfor is a looping structure for repeatedly executing a block of code
327 * {open braces start code blocks and must be matched with a close brace@link String}close braces end code blocks and must match an earlier open brace, {open braces start code blocks and must be matched with a close brace@link #compareTo(HighScore)}close braces end code blocks and must match an earlier open brace returns a negative
328 * number ifif executes the next statement only if the condition in parenthesis evaluates to true thisthis means the current object (the implicit parameter) < rhs; 0 ifif executes the next statement only if the condition in parenthesis evaluates to true thisthis means the current object (the implicit parameter) ==this is the comparison operator which evaluates to true if both sides are the same rhs; and positive number ifif executes the next statement only if the condition in parenthesis evaluates to true
329 * thisthis means the current object (the implicit parameter) > rhs (rhs =this assignment operator makes the left side equal to the right side right-hand side).
330 *
331 * @paramthis is the Javadoc tag for documenting the purpose of parameters rhs the {open braces start code blocks and must be matched with a close brace@link HighScore}close braces end code blocks and must match an earlier open brace to which thisthis means the current object (the implicit parameter) object is
332 * compared
333 *
334 * @returnnull negative ifif executes the next statement only if the condition in parenthesis evaluates to true thisthis means the current object (the implicit parameter) < rhs; 0 ifif executes the next statement only if the condition in parenthesis evaluates to true thisthis means the current object (the implicit parameter) ==this is the comparison operator which evaluates to true if both sides are the same rhs; positive
335 * otherwise
336 */
337 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer compareTo(HighScore rhs) {open braces start code blocks and must be matched with a close brace
338 ifif executes the next statement only if the condition in parenthesis evaluates to true (rhs.name.length() ==this is the comparison operator which evaluates to true if both sides are the same 0) {open braces start code blocks and must be matched with a close brace
339 returnreturn means to provide the result of the method and/or cease execution of the method immediately 1;
340 }close braces end code blocks and must match an earlier open brace
341 ifif executes the next statement only if the condition in parenthesis evaluates to true (name.length() ==this is the comparison operator which evaluates to true if both sides are the same 0) {open braces start code blocks and must be matched with a close brace
342 returnreturn means to provide the result of the method and/or cease execution of the method immediately -1;
343 }close braces end code blocks and must match an earlier open brace
344 ifif executes the next statement only if the condition in parenthesis evaluates to true (score ==this is the comparison operator which evaluates to true if both sides are the same rhs.score) {open braces start code blocks and must be matched with a close brace
345 returnreturn means to provide the result of the method and/or cease execution of the method immediately name.compareTo(rhs.name);
346 }close braces end code blocks and must match an earlier open brace
347 returnreturn means to provide the result of the method and/or cease execution of the method immediately score - rhs.score;
348 }close braces end code blocks and must match an earlier open brace
349
350 /**
351 * Get the score forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) high score.
352 *
353 * @returnnull the score value
354 */
355 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getScore() {open braces start code blocks and must be matched with a close brace
356 returnreturn means to provide the result of the method and/or cease execution of the method immediately score;
357 }close braces end code blocks and must match an earlier open brace
358
359 /**
360 * Is the name empty?
361 *
362 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true the name is empty; falsefalse is a value for the boolean type and means not true otherwise
363 */
364 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false isEmpty() {open braces start code blocks and must be matched with a close brace
365 returnreturn means to provide the result of the method and/or cease execution of the method immediately name.length() ==this is the comparison operator which evaluates to true if both sides are the same 0;
366 }close braces end code blocks and must match an earlier open brace
367
368 /**
369 * Get a display version of the string. Used to fill an array of
370 * strings forfor is a looping structure for repeatedly executing a block of code displaying in a scrolling message sprite
371 *
372 * @paramthis is the Javadoc tag for documenting the purpose of parameters index the number to put in the front of the whole
373 * thing.
374 *
375 * @returnnull string padded with index, name, and score
376 */
377 publicpublic is used to indicate unrestricted access (any other class can have access) String toDisplayString(intint is the type for whole numbers and it is short for integer index) {open braces start code blocks and must be matched with a close brace
378 String paddedName =this assignment operator makes the left side equal to the right side Integer.toString(index) +adds two numbers together or concatenates Strings together ": " +adds two numbers together or concatenates Strings together
379 (name +adds two numbers together or concatenates Strings together SIGNIFICANT_PADDING).substring(0,
380 SIGNIFICANT_CHARACTERS);
381 returnreturn means to provide the result of the method and/or cease execution of the method immediately paddedName +adds two numbers together or concatenates Strings together " " +adds two numbers together or concatenates Strings together score;
382 }close braces end code blocks and must match an earlier open brace
383
384 /**
385 * Return a {open braces start code blocks and must be matched with a close brace@link String}close braces end code blocks and must match an earlier open brace representation of thisthis means the current object (the implicit parameter) high score. The
386 * string representation is the same format as a high score file.
387 *
388 * @returnnull {open braces start code blocks and must be matched with a close brace@link String}close braces end code blocks and must match an earlier open brace representation <score> <name>
389 */
390 @Override
391 publicpublic is used to indicate unrestricted access (any other class can have access) String toString() {open braces start code blocks and must be matched with a close brace
392 returnreturn means to provide the result of the method and/or cease execution of the method immediately "" +adds two numbers together or concatenates Strings together score +adds two numbers together or concatenates Strings together " " +adds two numbers together or concatenates Strings together name;
393 }close braces end code blocks and must match an earlier open brace
394 }close braces end code blocks and must match an earlier open brace
395 }close braces end code blocks and must match an earlier open brace
396
397 //Uploaded on Mon Mar 29 21:39:01 EDT 2010
|