the game will now create a new clg when entering the main view

This commit is contained in:
Fleischer Hanno
2024-12-16 11:38:31 +01:00
parent e8506e607c
commit 61ea4c3276
4 changed files with 26 additions and 4 deletions

View File

@@ -84,7 +84,7 @@ public class MdgaApp extends SimpleApplication {
/**
* The client game logic.
*/
private final ClientGameLogic clientGameLogic;
private ClientGameLogic clientGameLogic;
private ExecutorService executor;
@@ -204,6 +204,7 @@ public void enter(MdgaState state) {
switch (state) {
case MAIN:
view = mainView;
clientGameLogic.clear();
break;
case LOBBY:
view = lobbyView;

View File

@@ -76,6 +76,15 @@ private Piece getPiece(UUID pieceId) {
return null;
}
public void clear(){
game = new Game();
notifications.clear();
setState(dialogsState);
isHost = false;
ownPlayerID = 0;
ownPlayerName = null;
}
/**
* This method returns the clientSender
*

View File

@@ -175,4 +175,16 @@ public void received(StartGameMessage msg, int from) {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(5));
}
}
/**
* Removed the player after receiving a LeaveGameMessage message.
*
* @param msg as the message which was sent by the player as a LeaveGameMessage object.
* @param from as the client id of the player as an Integer.
*/
@Override
public void received(LeaveGameMessage msg, int from) {
this.logic.getGame().removePlayer(from);
this.logic.getServerSender().broadcast(new LobbyPlayerLeaveMessage(from));
}
}

View File

@@ -61,13 +61,13 @@ public void received(AnimationEndMessage msg, int from) {
if (finishedAnimations.size() == logic.getGame().getPlayers().size()) {
if (logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).isFinished()) {
logic.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getActivePlayer());
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
setActivePlayer(logic.getGame().getActiveColor());
if (logic.getGame().getPlayerRanking().size() == logic.getGame().getPlayers().size() - 1) {
logic.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getActivePlayer());
logic.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getPlayerByColor(logic.getGame().getActiveColor().next(logic.getGame())));
logic.setCurrentState(logic.getCeremonyState());
return;
}
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
setActivePlayer(logic.getGame().getActiveColor());
this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState());
}
else if (logic.getGame().getDiceEyes() == 6) {