View Javadoc

1   /*
2    * The ReWinder Project
3    * 
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU General Public License
6    * as published by the Free Software Foundation; either version 2
7    * of the License, or (at your option) any later version.
8   
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13  
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   */
18  package ch.twiddlefinger.inet.rewinder.model.entities;
19  
20  import java.awt.Color;
21  
22  /***
23   * @author matthias.vonrohr To change the template for this generated type
24   *         comment go to Window>Preferences>Java>Code
25   *         Generation>Code and Comments
26   */
27  public class Player {
28  	private Color color;
29  	private String name;
30  	private Race race;
31  	private int playerID;
32  
33  	public Player(String name, Color color, Race race) {
34  		if ((color == null) || (name == null) || (race == null)) {
35  			throw new IllegalArgumentException("Constructor Player: some parameters are null");
36  		}
37  
38  		this.color = color;
39  		this.race = race;
40  		this.name = name;
41  	}
42  
43  	public Player(int playerID, String name, Race race) {
44  		this(name, Color.BLUE, race);
45  		this.playerID = playerID;
46  	}
47  
48  	/***
49  	 * Returns the player's color
50  	 *
51  	 * @return
52  	 */
53  	public Color getColor() {
54  		return color;
55  	}
56  
57  	/***
58  	 * Returns the player's name
59  	 *
60  	 * @return
61  	 */
62  	public String getName() {
63  		return name;
64  	}
65  
66  	/***
67  	 * Returns the players race
68  	 *
69  	 * @return
70  	 */
71  	public Race getRace() {
72  		return race;
73  	}
74  
75  	public boolean equals(Object o) {
76  		if (o instanceof Player) {
77  			return ((Player) o).getName().equals(this.name);
78  		} else {
79  			return false;
80  		}
81  	}
82  
83  	/***
84  	 * @return
85  	 */
86  	public int getPlayerID() {
87  		return playerID;
88  	}
89  
90  	/***
91  	 * @param i
92  	 */
93  	public void setPlayerID(int i) {
94  		this.playerID = i;
95  	}
96  
97  	public String toString() {
98  		StringBuffer result = new StringBuffer();
99  		result.append(
100 			"[ ("
101 				+ this.playerID
102 				+ ") "
103 				+ this.name
104 				+ ", "
105 				+ this.color
106 				+ ", "
107 				+ this.race
108 				+ " ]");
109 
110 		return result.toString();
111 	}
112 
113 	public void setColor(Color color) {
114 		this.color = color;
115 	}
116 }