Updated 'LobbyState' class.

Updated the 'LobbyState' class by updating the creation of the 'ServerStartGameMessage' object. In Addition, the start process if all players are ready was removed.
This commit is contained in:
Daniel Grigencha
2024-12-04 02:44:03 +01:00
parent de5c8bf44c
commit 4440341f79

View File

@@ -2,7 +2,6 @@
import pp.mdga.game.Color;
import pp.mdga.game.Player;
import pp.mdga.game.PlayerData;
import pp.mdga.message.client.*;
import pp.mdga.message.server.*;
import pp.mdga.server.ServerGameLogic;
@@ -48,8 +47,8 @@ public void exit() {
* This method will be used to initialize the game and all necessary objects.
*/
public void initializeGame() {
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
this.logic.getGame().getBoard().addPlayerData(entry.getValue().getColor(), new PlayerData(entry.getValue().getColor()));
for (var player : this.logic.getGame().getPlayers().values()) {
player.initialize();
}
}
@@ -122,11 +121,6 @@ public void received(LobbyReadyMessage msg, int from) {
}
this.logic.getGame().getPlayerById(from).setReady(true);
this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, true));
if (this.logic.getGame().areAllReady()) {
this.initializeGame();
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
this.logic.setCurrentState(this.logic.getGameState());
}
}
/**
@@ -151,9 +145,9 @@ public void received(LobbyNotReadyMessage msg, int from) {
*/
@Override
public void received(StartGameMessage msg, int from) {
if (msg.isForceStartGame() || this.logic.getGame().areAllReady()) {
if (this.logic.getGame().areAllReady()) {
this.initializeGame();
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getPlayersAsList(), this.logic.getGame().getBoard()));
this.logic.setCurrentState(this.logic.getGameState());
}
}