examples/multiplayer/Multiplayer

From FANG

Revision as of 17:58, 19 September 2009 by Jam Jenkins (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

01 package examples.multiplayer;
02 
03 import fang.*;
04 
05 
06 /**Demonstrates how to make a multiplayer
07  * game with input from each player.
08  @author Jam Jenkins
09  */
10 public class Multiplayer extends Game
11 {
12    /**size of the players*/
13    private static final double SIZE=0.3;
14    /**the array of player sprites*/
15    private StringSprite[] numbers;
16 
17    /**initializes the number of players
18     * at the very beginning of the game
19     */
20    public Multiplayer()
21    {
22       setNumberOfPlayers(2);
23    }
24 
25    /**makes the player sprites.  This
26     * method can only be called once
27     * startGame has been called because
28     * all players must connect before
29     * knowing how large to make the array.
30     */
31    public void makeSprites()
32    {
33       numbers=new StringSprite[getNumberOfPlayers()];
34       for(int i=0; i<numbers.length; i++)
35       {
36          numbers[i]=new StringSprite("Player "+i);
37          numbers[i].setScale(SIZE);
38       }
39    }
40 
41    /**adds the player sprites to the canvas*/
42    public void addSprites()
43    {
44       addSprite(numbers);
45    }
46 
47    /**this method is called once all
48     * players have joined the game*/
49    public void setup()
50    {
51       makeSprites();
52       addSprites();
53       setHelp("resources/MultiplayerHelp.txt");
54    }
55 
56    /**positions each player where his or
57     * her mouse is*/
58    public void advance()
59    {
60       for(int i=0; i<numbers.length; i++)
61          numbers[i].setLocation(getMouse2D(i));
62    }
63 
64    public static void main(String[] argv)
65    {
66       Multiplayer player=new Multiplayer();
67       player.runAsApplication();
68    }
69 }


Download/View examples/multiplayer/Multiplayer.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