Added a player handler so the code look a bit better

This commit is contained in:
Ziver Koc 2007-04-05 12:45:22 +00:00
parent 34decd72e4
commit c2a579788a
6 changed files with 167 additions and 15 deletions

View file

@ -0,0 +1,63 @@
package ei.game.player;
import java.util.ArrayList;
public class PlayerHandler {
// The instance of this class
private static PlayerHandler instance;
// The player list
private ArrayList<Player> players;
/**
* Creates a PlayerHandler
*
*/
public PlayerHandler(){
players = new ArrayList<Player>();
}
/**
* Add a player to the handler
*
* @param p The player to add to the handler
* @return true if added else false
*/
public boolean addPlayer(Player p){
if(!players.contains(p)){
players.add(p);
return true;
}
return false;
}
/**
* Removes a player from the handler
* @param p The player to remove
* @return true if succesful else false
*/
public boolean removePlayer(Player p){
if(players.contains(p)){
players.remove(p);
return true;
}
return false;
}
public void update(){
for(int i=0; i<players.size() ;i++){
players.get(i).update();
}
}
/**
* Returns the instance of this class
*
* @return The instance
*/
public static PlayerHandler getInstance(){
if(instance == null){
instance = new PlayerHandler();
}
return instance;
}
}