refactor: added hasFreePlayerSlot method to LobbyConnection

This commit is contained in:
Yannik Bretschneider 2021-06-07 15:34:22 +02:00
parent d58f0dfca9
commit b087eee99d

View File

@ -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<CharacterProperties[], CharacterProperties[]> 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) {