doc: added documentation for Lobby classes

This commit is contained in:
Richard Reiber 2021-06-06 01:51:39 +02:00
parent 7f512400df
commit bbaeb63bb6
7 changed files with 64 additions and 5 deletions

View File

@ -27,6 +27,16 @@ public class Lobby {
private PauseSegment pauseSegment;
private final TurnTimer turnTimer;
/**
* The {@link Lobby} is where the magic happens.
* In this class is a whole {@link GameInstance game} is processed.
* To initialize the game it gets the following parameters
* @param gameID a String to identify the game
* @param connection the Connection to the {@link uulm.teamname.marvelous.server.lobbymanager.LobbyManager}
* @param partyConfig declared in Editor
* @param characterConfig declared in Editor
* @param scenarioConfig declared in Editor
*/
public Lobby(
String gameID,
LobbyConnection connection,
@ -95,6 +105,10 @@ public class Lobby {
updateTimer();
}
/**
* This method is called at the end of receiveRequests, to start a timer.
* The active player has now a specific amount of time to do his moves.
*/
void updateTimer() {
var currentActiveCharacterType = game.state.getActiveCharacter().type;
if (pauseSegment.isPaused()) {

View File

@ -7,6 +7,9 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.function.Consumer;
/**
* The {@link TurnTimer} class is called by the {@link Lobby} to limit the amount of time a player has per round.
*/
public class TurnTimer {
private final Timer timer;
private final Consumer<Participant> callback;
@ -18,6 +21,10 @@ public class TurnTimer {
this.callback = callback;
}
/**
* This method checks if the participant is not a spectator. Otherwise it won't start a timer.
* @param participant the timer is for
*/
public void startTurnTimer(Participant participant) {
if (participant.type == ParticipantType.Spectator)
throw new IllegalStateException("Spectators don't have TurnTime");

View File

@ -9,6 +9,10 @@ import uulm.teamname.marvelous.server.lobby.Lobby;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link DisconnectSegment} handles requests of {@link RequestType} DisconnectRequest.
* Therefore it removes the disconnecting player-connection from the {@link Lobby}.
*/
public class DisconnectSegment implements Segment {
private final Lobby parent;
@ -17,7 +21,6 @@ public class DisconnectSegment implements Segment {
this.parent = parent;
}
@Override
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
Logger.trace("DisconnectSegment received {} requests.", packet.size());

View File

@ -11,9 +11,14 @@ import uulm.teamname.marvelous.server.lobby.Lobby;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link GameStateSegment} handles all {@link GameInstance game} relevant {@link Request Requests}.
* Therefore it updates the game with the matching request.
*/
public class GameStateSegment implements Segment {
private GameInstance game;
public GameStateSegment(GameInstance game){
this.game = game;
}

View File

@ -6,6 +6,10 @@ import uulm.teamname.marvelous.server.lobbymanager.Participant;
import java.util.*;
/**
* The {@link Packet} contains all {@link Request Requests} and the belonging {@link Participant}.
* You can add and remove {@link Request Requests} at will.
*/
public class Packet extends ArrayList<Request> {
private final Participant origin;
@ -15,6 +19,11 @@ public class Packet extends ArrayList<Request> {
addAll(Arrays.asList(requests));
}
/**
* This method checks if a {@link RequestType} is part of the {@link Packet} or not
* @param requiredType RequestType to check.
* @return boolean
*/
public boolean containsRequestOfType(RequestType requiredType) {
for (Request request : this) {
if (request.type == requiredType) {
@ -24,11 +33,19 @@ public class Packet extends ArrayList<Request> {
return false;
}
/**
* This method removes all {@link Request Requests} of given {@link RequestType types} from the {@link Packet}.
* @param types RequestType(s) to remove
*/
public void removeRequestsOfTypes(RequestType... types) {
var listOfTypes = Arrays.asList(types);
this.removeIf(request -> listOfTypes.contains(request.type));
}
/**
* This method removes all {@link Request Requests} except of given {@link RequestType types} from the {@link Packet}.
* @param types RequestType(s) to not remove
*/
public void removeRequestsNotOfTypes(RequestType... types) {
var listOfTypes = Arrays.asList(types);
this.removeIf(request -> !listOfTypes.contains(request.type));

View File

@ -11,6 +11,9 @@ import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link PauseSegment} can pause and unpause a game.
*/
public class PauseSegment implements Segment {
private boolean paused;
@ -19,18 +22,23 @@ public class PauseSegment implements Segment {
paused = false;
}
/**
* This method pauses the game if it is not already paused.
*/
public void pauseGame(){
if(!paused) {
paused = true;
Logger.debug("{}: Game paused.",
Thread.currentThread().getName());
Logger.debug("Game paused.");
}
}
/**
* This method ends a paused game.
*/
public void pauseEnd(){
if(paused) {
paused = false;
Logger.debug("{}: Game unpaused.",
Thread.currentThread().getName());
Logger.debug("Game unpaused.");
}
}

View File

@ -10,10 +10,15 @@ import uulm.teamname.marvelous.server.lobby.Lobby;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link RequestGameStateSegment} handles requests of {@link RequestType} Req.
* Therefore it sends the active gamestate and clears the {@link Packet} afterwards.
*/
public class RequestGameStateSegment implements Segment {
private final GameInstance game;
public RequestGameStateSegment(GameInstance game) {
this.game = game;
}