From 052a2078221a32f083c06a0139c4519341e088b4 Mon Sep 17 00:00:00 2001 From: sebaschi <74497638+sebaschi@users.noreply.github.com> Date: Fri, 8 Apr 2022 12:23:51 +0200 Subject: [PATCH] Added final field MAX_NO_OF_CLIENTS used to not overfill the lobby. --- .../unibas/dmi/dbis/cs108/sebaschi/Lobby.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/Lobby.java b/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/Lobby.java index 3b104b0..419b18d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/Lobby.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/Lobby.java @@ -1,6 +1,7 @@ package ch.unibas.dmi.dbis.cs108.sebaschi; import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; +import java.util.ArrayList; import java.util.List; /** @@ -12,11 +13,45 @@ public class Lobby { * The Person who created the game and can configure it and decide to start once enough players * have entered the lobby. */ - private ClientHandler admin; + private final ClientHandler admin; /** * Everyone who's in the lobby. */ - private List players; + private List players = new ArrayList<>(); + + private static final int MAX_NO_OF_CLIENTS = 6; + + + + + + + + /** + * The admin has to be set in the constructor. The admin is final. + * Every Lobby needs and admin, so no other constructors are needed. + * @param admin the Client who called CRTGM + */ + public Lobby(ClientHandler admin) { + this.admin = admin; + } + + /** + * Getter + * + * @return the admin of the lobby. + */ + public ClientHandler getAdmin() { + return this.admin; + } + + /** + * Adds a player to the lobby. + * @param player who wants to join the lobby. + */ + public void addPlayer(ClientHandler player) { + players.add(player); + } }