From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch05;
02
03 importimport means to make the classes and/or packages available in this program fang2.core.Game;
04
05 /**
06 * Demonstration game using OneDie and EasyButton classes: Roll two big
07 * dice every time the button saying "Roll Dice" is pressed.
08 */
09 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 RollDice
10 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
11 /** the button at the bottom of the screen */
12 privateprivate is used to restrict access to the current class only EasyButton button;
13
14 /** the left die */
15 privateprivate is used to restrict access to the current class only OneDie leftDie;
16
17 /** the right die */
18 privateprivate is used to restrict access to the current class only OneDie rightDie;
19
20 /**
21 * Advance the game one frame.
22 *
23 * @paramthis is the Javadoc tag for documenting the purpose of parameters secondsSinceLastCall time since last advance
24 */
25 @Override
26 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 secondsSinceLastCall) {open braces start code blocks and must be matched with a close brace
27 ifif executes the next statement only if the condition in parenthesis evaluates to true (button.isPressed()) {open braces start code blocks and must be matched with a close brace
28 leftDie.roll();
29 rightDie.roll();
30 }close braces end code blocks and must match an earlier open brace
31 }close braces end code blocks and must match an earlier open brace
32
33 /**
34 * Set up the game forfor is a looping structure for repeatedly executing a block of code play. Initializes all of the sprites (either
35 * here or in other setup functions).
36 */
37 @Override
38 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
39 button =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor EasyButton();
40 button.setScale(0.5);
41 button.setLocation(0.5, 0.85);
42 button.setColor(getColor("yellow"));
43 button.setTextColor(getColor("navy"));
44 addSprite(button);
45
46 button.setText("Roll Dice");
47
48 leftDie =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OneDie();
49 leftDie.setScale(0.33);
50 leftDie.setLocation(5.0 / 18.0, 0.5);
51 addSprite(leftDie);
52
53 rightDie =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OneDie();
54 rightDie.setScale(0.33);
55 rightDie.setLocation(13.0 / 18.0, 0.5);
56 addSprite(rightDie);
57 }close braces end code blocks and must match an earlier open brace
58 }close braces end code blocks and must match an earlier open brace
59
60 //Uploaded on Mon Mar 29 21:41:32 EDT 2010
|
Download/View scg/ch05/RollDice.java