/*
*--------------------------------------------------------------------------
* 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: Game.java 607 2010-07-27 07:16:34Z Harry $
* $LastChangedDate: 2010-07-27 00:16:34 -0700 (Tue, 27 Jul 2010) $
* $LastChangedBy: Harry $
*--------------------------------------------------------------------------
*/
package battlefield.entity;
import battlefield.state.GamePhase;
import battlefield.state.PlayerState;
import java.io.Serializable;
import java.util.ArrayList;
/**
*
* @author Harry Nguyen
*/
public class Game implements Serializable {
private int id;
private int goldReloadDuration;
private int goldReloadAmt;
private int startGold;
private GamePhase phase;
private ArrayList<Player> players;
/**
* Construct the Game object with an id number
*
* @param id a unique id number for the game
*/
public Game(int id) {
this.id = id;
this.players = new ArrayList<Player>();
}
/**
* Returns the id of the game
*
* @return the id of the game
*/
public int getId() {
return id;
}
/**
* Returns the duration to reload gold
*
* @return number of second before gold is reloaded
*/
public int getGoldReloadDuration() {
return goldReloadDuration;
}
/**
* Sets duration required to reload gold
*
* @param goldReloadDuration number of seconds required to reload gold
*/
public void setGoldReloadDuration(int goldReloadDuration) {
this.goldReloadDuration = goldReloadDuration;
}
/**
* Returns the amount of gold to reload
*
* @return amount of gold to reload
*/
public int getGoldReloadAmount() {
return goldReloadAmt;
}
/**
* Sets amount of gold to reload
*
* @param goldReloadAmt amount of gold to reload
*/
public void setGoldReloadAmount(int goldReloadAmt) {
this.goldReloadAmt = goldReloadAmt;
}
/**
* Returns the starting gold
*
* @return the amount of starting gold
*/
public int getStartGold() {
return startGold;
}
/**
* Sets starting amount of gold
*
* @param startGold amount of starting gold
*/
public void setStartGold(int startGold) {
this.startGold = startGold;
}
/**
* Returns the phase of the game
*
* @return phase the game is in
*/
public GamePhase getPhase() {
return phase;
}
/**
* Sets phase the game is currently in
*
* @param phase the current phase the game is in
*/
public void setPhase(GamePhase phase) {
this.phase = phase;
}
/**
* Returns true is the phase is completed
*
* @return true is the phase has been completed
*/
public boolean isPhaseCompleted() {
for (Player player : this.getPlayers()) {
if (player.getState() != PlayerState.DONE) {
return false;
}
}
return true;
}
/**
* Returns the list of all player currently playing the game
*
* @return list of all the player in the game
*/
public ArrayList<Player> getPlayers() {
return players;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Game)) {
return false;
}
return ((Game) obj).getId() == this.getId();
}
@Override
public int hashCode() {
int hash = 5;
hash = 59 * hash + this.id;
return hash;
}
}
|