From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch13.core;
02
03 importimport means to make the classes and/or packages available in this program fang2.sprites.StringSprite;
04
05 /**
06 * Keep and display score. The {open braces start code blocks and must be matched with a close brace@link ScoreSprite}close braces end code blocks and must match an earlier open brace is based on the
07 * version presented in Chapter09. The score in thisthis means the current object (the implicit parameter) version is an
08 * integer (the number of rows removed in the game).
09 */
10 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 ScoreSprite
11 extendsextends means to customize or extend the functionality of a class StringSprite {open braces start code blocks and must be matched with a close brace
12 /** current score */
13 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;
14
15 /**
16 * Default constructor: 0/0 is initial score.
17 */
18 publicpublic is used to indicate unrestricted access (any other class can have access) ScoreSprite() {open braces start code blocks and must be matched with a close brace
19 thisthis means the current object (the implicit parameter)(0);
20 }close braces end code blocks and must match an earlier open brace
21
22 /**
23 * Create newnew is used to create objects by calling the constructor ScoreSprite with the given score.
24 *
25 * @paramthis is the Javadoc tag for documenting the purpose of parameters score initial score
26 */
27 publicpublic is used to indicate unrestricted access (any other class can have access) ScoreSprite(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
28 thisthis means the current object (the implicit parameter).score =this assignment operator makes the left side equal to the right side score;
29 fixTextDisplay();
30 }close braces end code blocks and must match an earlier open brace
31
32 /**
33 * Get the current score.
34 *
35 * @returnnull the current score
36 */
37 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
38 returnreturn means to provide the result of the method and/or cease execution of the method immediately score;
39 }close braces end code blocks and must match an earlier open brace
40
41 /**
42 * Increment the score by 1.
43 */
44 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value increment() {open braces start code blocks and must be matched with a close brace
45 increment(1);
46 }close braces end code blocks and must match an earlier open brace
47
48 /**
49 * Increment the score by the given value.
50 *
51 * @paramthis is the Javadoc tag for documenting the purpose of parameters n number to add to the current score
52 */
53 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value increment(intint is the type for whole numbers and it is short for integer n) {open braces start code blocks and must be matched with a close brace
54 score +=this increases the variable on the left by the value on the right n;
55 fixTextDisplay();
56 }close braces end code blocks and must match an earlier open brace
57
58 /**
59 * Implementation method: display the currently recorded score.
60 */
61 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value fixTextDisplay() {open braces start code blocks and must be matched with a close brace
62 setText(Integer.toString(score));
63 }close braces end code blocks and must match an earlier open brace
64 }close braces end code blocks and must match an earlier open brace
65
66 //Uploaded on Mon Mar 29 21:41:07 EDT 2010
|
Download/View scg/ch13/core/ScoreSprite.java