/*
*--------------------------------------------------------------------------
* Battlefield - A Realtime Network Multiplayer Game
* =======================================================
* Developed by Group D02 - 2009/2010 Semester 4 - CS2103
* Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
* Kent Chng Siang Rong <fivefootway@gmail.com>
* Lim Yong Peng <limpeng1986@gmail.com>
* Loh Xiankun <u0807185@nus.edu.sg>
* Instructed by
* Dr. Damith C.Rajapakse <damith@gmail.com>
* =======================================================
* $Id: Player.java 643 2010-07-30 05:56:41Z Victor $
* $LastChangedDate: 2010-07-29 22:56:41 -0700 (Thu, 29 Jul 2010) $
* $LastChangedBy: Victor $
*--------------------------------------------------------------------------
*/
package battlefield.entity;
import battlefield.state.PlayerState;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Stack;
/**
*
* @author Harry Nguyen
*/
public class Player implements Serializable {
private int id;
private String name;
private int gold;
private PlayerState state;
private int unitsAlive;
private int unitsDestroyed;
private Map map;
private HashMap<String, Mission> missions;
private Stack<String> missionStack;
/**
* Constructs the Player object using the following parameter
* @param id unique id to be allocated to the object
*/
public Player(int id) {
this.id = id;
}
/**
* return the stack object containing missions name
* @return
*/
public Stack<String> getMissionStack() {
return missionStack;
}
/**
* set stack object containing missions name
* @param missionStack
*/
public void setMissionStack(Stack<String> missionStack) {
this.missionStack = missionStack;
}
/**
* Returns the id of the Player object
* @return id of the Player object
*/
public int getId() {
return id;
}
/**
* Returns a HashMap of all the missions available
* @return HashMap of missions
*/
public HashMap<String, Mission> getMissions() {
return missions;
}
/**
* Sets the HashMap of all mission
* @param missions HashMap of all mission
*/
public void setMissions(HashMap<String, Mission> missions) {
this.missions = missions;
}
/**
* Returns the name of the player
* @return String of the player name
*/
public String getName() {
return name;
}
/**
* Sets the name of the Player
* @param name of the player
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns amount of gold that the player have
* @return an int of the amount of gold the player have
*/
public int getGold() {
return gold;
}
/**
* Sets the amount of gold the player have
* @param gold the amount of gold to set for the player
*/
public void setGold(int gold) {
this.gold = gold;
}
/**
* Returns the state the player is in
* @return the PlayerState of the player
* @see PlayerState
*/
public PlayerState getState() {
return state;
}
/**
* Sets the PlayerState of the player
* @param state the PlayerState object
*/
public void setState(PlayerState state) {
this.state = state;
}
/**
* Returns the map of the player
* @return Map object of the player
*/
public Map getMap() {
return map;
}
/**
* Sets a Map object the player is using
* @param map selected by the player
*/
public void setMap(Map map) {
this.map = map;
}
/**
* Returns the number of unit of the player that is alive
* @return int of the number of alive unit
*/
public int getUnitsAlive() {
return unitsAlive;
}
/**
* Sets the number of units alive
* @param unitsAlive number of alive unit
*/
public void setUnitsAlive(int unitsAlive) {
this.unitsAlive = unitsAlive;
}
/**
* Returns the number of units destroyed
* @return the number of units destroyed
*/
public int getUnitsDestroyed() {
return unitsDestroyed;
}
/**
* Sets the number of units destroyed
* @param unitsDestroyed number of unit destroyed
*/
public void setUnitsDestroyed(int unitsDestroyed) {
this.unitsDestroyed = unitsDestroyed;
}
/**
* Returns true if at least one unit is alive
* @return true if at least one unit is alive
*/
public boolean isAlive() {
if (unitsAlive <= 0) {
return false;
}
return true;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Player)) {
return false;
}
return ((Player) obj).getId() == this.getId();
}
@Override
public int hashCode() {
int hash = 7;
hash = 17 * hash + this.id;
return hash;
}
}
|