From b087eee99d935be8a28ab8cc3de402a7c1a2b1d5 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Mon, 7 Jun 2021 15:34:22 +0200 Subject: [PATCH] refactor: added hasFreePlayerSlot method to LobbyConnection --- .../server/lobbymanager/LobbyConnection.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java index eb235ae..5ac3885 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java @@ -20,7 +20,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; public class LobbyConnection implements Runnable { - public final String lobbyID; public final String gameID; public LobbyConnectionState state = LobbyConnectionState.Waiting; @@ -34,9 +33,8 @@ public class LobbyConnection implements Runnable { private Lobby lobby; /** Creates a new LobbyConnection */ - public LobbyConnection(String lobbyID) { - this.lobbyID = lobbyID; - this.gameID = UUID.randomUUID().toString(); + public LobbyConnection(String gameID) { + this.gameID = gameID; Tuple picked = Server.getCharacterConfig().getDisjointSetsOfPropertiesOfSize(12); this.options.put(ParticipantType.PlayerOne, picked.item1); @@ -81,6 +79,7 @@ public class LobbyConnection implements Runnable { } } + /** Returns the next free slot in the lobby as a {@link ParticipantType} */ public ParticipantType freeSlot() { if(player1 == null) { return ParticipantType.PlayerOne; @@ -91,6 +90,11 @@ public class LobbyConnection implements Runnable { } } + /** Returns whether there is a player slot available in the lobby */ + public boolean hasFreePlayerSlot() { + return player1 == null || player2 == null; + } + public Participant getPlayer1() { return player1; @@ -117,6 +121,7 @@ public class LobbyConnection implements Runnable { } } + /** Handles disconnect of a Participant. Hereby, the participant is made ready for reconnection */ public void handleDisconnect(Participant participant) { participant.disconnected = true; if(state == LobbyConnectionState.Started) { @@ -124,6 +129,7 @@ public class LobbyConnection implements Runnable { } } + /** Handles reconnect of a Participant. Hereby, the participant is made ready for reconnection */ public void handleReconnect(Participant participant) { participant.disconnected = false; if(state == LobbyConnectionState.Started) {