refactor: added hasFreePlayerSlot method to LobbyConnection
This commit is contained in:
parent
d58f0dfca9
commit
b087eee99d
@ -20,7 +20,6 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class LobbyConnection implements Runnable {
|
public class LobbyConnection implements Runnable {
|
||||||
public final String lobbyID;
|
|
||||||
public final String gameID;
|
public final String gameID;
|
||||||
public LobbyConnectionState state = LobbyConnectionState.Waiting;
|
public LobbyConnectionState state = LobbyConnectionState.Waiting;
|
||||||
|
|
||||||
@ -34,9 +33,8 @@ public class LobbyConnection implements Runnable {
|
|||||||
private Lobby lobby;
|
private Lobby lobby;
|
||||||
|
|
||||||
/** Creates a new LobbyConnection */
|
/** Creates a new LobbyConnection */
|
||||||
public LobbyConnection(String lobbyID) {
|
public LobbyConnection(String gameID) {
|
||||||
this.lobbyID = lobbyID;
|
this.gameID = gameID;
|
||||||
this.gameID = UUID.randomUUID().toString();
|
|
||||||
|
|
||||||
Tuple<CharacterProperties[], CharacterProperties[]> picked = Server.getCharacterConfig().getDisjointSetsOfPropertiesOfSize(12);
|
Tuple<CharacterProperties[], CharacterProperties[]> picked = Server.getCharacterConfig().getDisjointSetsOfPropertiesOfSize(12);
|
||||||
this.options.put(ParticipantType.PlayerOne, picked.item1);
|
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() {
|
public ParticipantType freeSlot() {
|
||||||
if(player1 == null) {
|
if(player1 == null) {
|
||||||
return ParticipantType.PlayerOne;
|
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() {
|
public Participant getPlayer1() {
|
||||||
return player1;
|
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) {
|
public void handleDisconnect(Participant participant) {
|
||||||
participant.disconnected = true;
|
participant.disconnected = true;
|
||||||
if(state == LobbyConnectionState.Started) {
|
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) {
|
public void handleReconnect(Participant participant) {
|
||||||
participant.disconnected = false;
|
participant.disconnected = false;
|
||||||
if(state == LobbyConnectionState.Started) {
|
if(state == LobbyConnectionState.Started) {
|
||||||
|
Loading…
Reference in New Issue
Block a user