From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch07;
02
03 importimport means to make the classes and/or packages available in this program fang2.attributes.Location2D;
04 importimport means to make the classes and/or packages available in this program fang2.core.Game;
05 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
06 importimport means to make the classes and/or packages available in this program fang2.ui.UserInput;
07
08 /**
09 * Demonstration of multi-player game techniques. Constructor sets
10 * number of required players to 2. When 2 players have joined, game can
11 * be started. Game looks forfor is a looping structure for repeatedly executing a block of code mouse clicks and draws random rectangles.
12 * Note that rectangles are the same on both screens.
13 */
14 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 IOColoredRectanglesMP
15 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
16 /**
17 * Construct a newnew is used to create objects by calling the constructor ColoredRectangleMP object; initialize the Game part
18 * and then set the player count to 2 (make it multi-player).
19 */
20 publicpublic is used to indicate unrestricted access (any other class can have access) IOColoredRectanglesMP() {open braces start code blocks and must be matched with a close brace
21 super();
22 setNumberOfPlayers(2);
23 players =this assignment operator makes the left side equal to the right side 2;
24 }close braces end code blocks and must match an earlier open brace
25
26 /**
27 * Advance one frame: iterate through all players looking forfor is a looping structure for repeatedly executing a block of code mouse
28 * clicks. If there is a mouse click, create a random rectangle
29 * centered at click location.
30 */
31 @Override
32 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
33 ifif executes the next statement only if the condition in parenthesis evaluates to true (getKeyPressed(getPlayerID()) ==this is the comparison operator which evaluates to true if both sides are the same 'k') {open braces start code blocks and must be matched with a close brace
34 UserInput ui =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor UserInput("Hello", "Something:");
35 System.out.println("The user says :" +adds two numbers together or concatenates Strings together ui.getInputText());
36 }close braces end code blocks and must match an earlier open brace
37 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 p =this assignment operator makes the left side equal to the right side 0; p !=this is the not equals operator which evaluates to true if both sides are different getNumberOfPlayers(); ++this is the increment operator, which increases the variable by 1p) {open braces start code blocks and must be matched with a close brace
38 Location2D rectangleLocation =this assignment operator makes the left side equal to the right side getClick2D(p);
39
40 ifif executes the next statement only if the condition in parenthesis evaluates to true (rectangleLocation !=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// was mouse(p) clicked?
41 RectangleSprite rectangle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(randomDouble(),
42 randomDouble());
43 rectangle.setColor(randomColor());
44 rectangle.setLocation(rectangleLocation);
45 addSprite(rectangle);
46 }close braces end code blocks and must match an earlier open brace
47 }close braces end code blocks and must match an earlier open brace
48 }close braces end code blocks and must match an earlier open brace
49 }close braces end code blocks and must match an earlier open brace
50
51 //Uploaded on Mon Mar 29 21:39:57 EDT 2010
|
Compiler Errors:
----------
1. ERROR in scg/ch07/IOColoredRectanglesMP.java (at line 6)
import fang2.ui.UserInput;
^^^^^^^^^^^^^^^^^^
The import fang2.ui.UserInput cannot be resolved
----------
2. ERROR in scg/ch07/IOColoredRectanglesMP.java (at line 34)
UserInput ui = new UserInput("Hello", "Something:");
^^^^^^^^^
UserInput cannot be resolved to a type
----------
3 problems (3 errors)
Download/View scg/ch07/IOColoredRectanglesMP.java