Lobby now have static field to count how many lobbies there are in total which is used to assign a particular lobby and ID, so players can ask to join the lobby.

This commit is contained in:
sebaschi 2022-04-08 12:40:11 +02:00
parent 1d9ee624fe
commit 16e6364cc9

View File

@ -9,6 +9,9 @@ import java.util.List;
*/
public class Lobby {
private static final int MAX_NO_OF_CLIENTS = 6;
private static int lobbies;
/**
* The Person who created the game and can configure it and decide to start once enough players
* have entered the lobby.
@ -18,23 +21,29 @@ public class Lobby {
/**
* Everyone who's in the lobby.
*/
private List<ClientHandler> players = new ArrayList<>();
private static final int MAX_NO_OF_CLIENTS = 6;
private List<ClientHandler> players = new ArrayList<>(6);
private int numberOfPlayersInLobby;
private final int lobbyID = lobbies++;
static {
lobbies = 0;
}
/**
* The admin has to be set in the constructor. The admin is final.
* Every Lobby needs and admin, so no other constructors are needed.
* Constructor. Sets the admin to who created the lobby. Adds the admin to the list of players.
* Increases the number of players from 0 to 1.
*
* @param admin the Client who called CRTGM
*/
public Lobby(ClientHandler admin) {
this.admin = admin;
this.players.add(admin);
this.numberOfPlayersInLobby = 1;
lobbies++;
}
/**
@ -48,6 +57,7 @@ public class Lobby {
/**
* Adds a player to the lobby.
*
* @param player who wants to join the lobby.
*/
public void addPlayer(ClientHandler player) {