Warning: dir(/var/www/fang/wiki/images/java/../javadoc/javadoc): failed to open dir: No such file or directory in /var/www/fang/wiki/extensions/JavaCoder/JavaCoder_body.php on line 982 Warning: dir(/var/www/fang/wiki/images/java/../javadoc/doc): failed to open dir: Too many levels of symbolic links in /var/www/fang/wiki/extensions/JavaCoder/JavaCoder_body.php on line 982 Warning: dir(/var/www/fang/wiki/images/java/../javadoc/silly): failed to open dir: Too many levels of symbolic links in /var/www/fang/wiki/extensions/JavaCoder/JavaCoder_body.php on line 982 Warning: dir(/var/www/fang/wiki/images/java/images/javadoc/javadoc): failed to open dir: No such file or directory in /var/www/fang/wiki/extensions/JavaCoder/JavaCoder_body.php on line 982 Warning: dir(/var/www/fang/wiki/images/java/images/javadoc/doc): failed to open dir: Too many levels of symbolic links in /var/www/fang/wiki/extensions/JavaCoder/JavaCoder_body.php on line 982 Warning: dir(/var/www/fang/wiki/images/java/images/javadoc/silly): failed to open dir: Too many levels of symbolic links in /var/www/fang/wiki/extensions/JavaCoder/JavaCoder_body.php on line 982 scg/ch07/IOColoredRectanglesMP - FANG

scg/ch07/IOColoredRectanglesMP

From FANG

Jump to: navigation, search

01 package scg.ch07;
02 
03 import fang2.attributes.Location2D;
04 import fang2.core.Game;
05 import fang2.sprites.RectangleSprite;
06 import 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 for mouse clicks and draws random rectangles.
12  * Note that rectangles are the same on both screens.
13  */
14 public class IOColoredRectanglesMP
15   extends Game {
16   /**
17    * Construct a new ColoredRectangleMP object; initialize the Game part
18    * and then set the player count to 2 (make it multi-player).
19    */
20   public IOColoredRectanglesMP() {
21     super();
22     setNumberOfPlayers(2);
23     players = 2;
24   }
25 
26   /**
27    * Advance one frame: iterate through all players looking for mouse
28    * clicks. If there is a mouse click, create a random rectangle
29    * centered at click location.
30    */
31   @Override
32   public void advance(double dT{
33     if (getKeyPressed(getPlayerID()) == 'k'{
34       UserInput ui = new UserInput("Hello""Something:");
35       System.out.println("The user says :" + ui.getInputText());
36     }
37     for (int = 0; p != getNumberOfPlayers()++p{
38       Location2D rectangleLocation = getClick2D(p);
39 
40       if (rectangleLocation != null{// was mouse(p) clicked?
41         RectangleSprite rectangle = new RectangleSprite(randomDouble(),
42             randomDouble());
43         rectangle.setColor(randomColor());
44         rectangle.setLocation(rectangleLocation);
45         addSprite(rectangle);
46       }
47     }
48   }
49 }
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




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games