package server.protocol;
import game.dice.Dice;
import game.gamesheet.GameSheet;
import game.leaderboard.Leaderboard;
import java.util.ArrayList;
import java.util.List;
import org.quickserver.net.server.ClientHandler;
/**
* The Class GameRoom. Gameroom holds all the vital information about
* the running game.
*
* @author Priit Laht
*/
public class GameRoom {
private Dice dice = new Dice(5);
private GameSheet gameSheet;
private List<ClientHandler> clients = new ArrayList<ClientHandler>();
private Leaderboard leaderboard = new Leaderboard();
private boolean inProgress = false;
private int size;
/**
* Instantiates a new game room.
*
* @param size the size for the game room
*/
public GameRoom(int size) {
this.size = size;
gameSheet = new GameSheet(size);
}
/**
* Resets the room variables.
*/
public void resetRoom() {
gameSheet = new GameSheet(size);
dice = new Dice(5);
dice.generateNeutralDice();
clients = new ArrayList<ClientHandler>();
inProgress = false;
}
/**
* Finds the player names for the clients that are in the room.
*
* @return the list of playernames
*/
public List<String> getPlayerNames() {
List<String> names = new ArrayList<String>();
ClientInfo data;
for (ClientHandler client : clients) {
data = (ClientInfo) client.getClientData();
names.add(data.getName());
}
return names;
}
/**
* Adds the client.
*
* @param handler the handler
*/
public void addClient(ClientHandler handler) {
clients.add(handler);
}
/**
* Removes the client.
*
* @param handler the handler
*/
public void removeClient(ClientHandler handler) {
clients.remove(handler);
}
public List<ClientHandler> getClients() {
return clients;
}
public GameSheet getGameSheet() {
return gameSheet;
}
public Dice getDice() {
return dice;
}
public boolean isInProgress() {
return inProgress;
}
public void setInProgress(boolean inProgress) {
this.inProgress = inProgress;
}
public Leaderboard getLeaderboard() {
return leaderboard;
}
public int getSize() {
return size;
}
}