Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/zazof/jtegServer/Player.java


1   package org.zazof.jtegServer;
2   
3   import java.util.*;
4   
5   public class Player{
6   
7     public Player(ClientConnection connection){
8       $connection = connection;
9     }
10  
11    public String getName(){
12      return $name;
13    }
14  
15    public void setName(String name){
16      $name = name;
17    }
18  
19    public int getID(){
20      return $id;
21    }
22  
23    public void setID(int id){
24      $id = id;
25    }
26  
27    public int getColor(){
28      return $color;
29    }
30  
31    public void setColor(int color){
32      $color = color;
33    }
34  
35    /**
36     * status = "started, attacking, waiting, lost, ..."
37     */
38    public int getStatus(){
39      return $status;
40    }
41  
42    public void setStatus(int status){
43      $status = status;
44    }
45  
46    /** 
47     * sends a message to this player
48     */
49    public void sendMessage(String message){
50      $connection.write(message);
51    }
52  
53    /**
54     * sends the answer to the player. The message send depends on the protocol used between
55     * player and server.
56     */
57    public void sendMessage(Answer a){
58      sendMessage(a.getAnswer($protocolVersion));
59    }
60  
61    public String getProtocol(){
62      return $protocolVersion;
63    }
64  
65    public void setProtocol(String protocol){
66      $protocolVersion = protocol;
67    }
68  
69    public int getConqueredCountries(){
70      return $conqueredCountries;
71    }
72  
73    public void setConqueredCountries(int cc){
74      $conqueredCountries = cc;
75    }
76  
77    /**
78     * @return number of cards owned by this player
79     */
80    public int getNbCards(){
81      return $cards.size();
82    }
83  
84    /**
85     * adds a card to this player
86     */
87    public void addCard(Card c){
88      $cards.add(c);
89    }
90  
91    public void removeCard(int cardID){
92      Card tmp;
93      for(int i = 0; i < $cards.size(); i++){
94        tmp = (Card) $cards.elementAt(i);  
95        
96      }
97    }
98  
99    public int getExchangeCards(){
100     return $exchangeCards;
101   }
102 
103   public void addExchangeCards(){
104     $exchangeCards++;
105   }
106 
107   private String $name; // name of this player
108   private ClientConnection $connection; // each player is remote, thus a socket facade is useful
109   private int $id; // each player needs a id to communicate
110   private int $color = 6; // 6 because the player default no color
111   private int $status = 3; // default status
112   private String $protocolVersion = "default"; // the protocol used between this client and the server
113   private int $conqueredCountries = 0; // the number of conquered countries during the current turn
114   private int $exchangeCards = 0; // the number of exchange cards this user got
115   private Vector $cards = new Vector(5); // contains the cards of this Player
116 
117   public static final int ENABLED = 3;
118   public static final int STARTED = 4;
119   public static final int PLACING_ARMIES = 5;
120   public static final int POST_ARMIES = 6;
121   public static final int POST_ARMIES2 = 8;
122   public static final int IDLE = 9;
123   public static final int PLACING_ARMIES3 = 10;
124   public static final int ATTACKING = 15;
125   public static final int GETTING_CARDS = 18;
126 
127   public static final int LOST = -1;
128 }