merge dev into test #30

Merged
j23f0712 merged 45 commits from development into dev/test 2024-12-02 01:29:40 +01:00
27 changed files with 261 additions and 88 deletions
Showing only changes of commit c1280ba089 - Show all commits

View File

@@ -2,6 +2,7 @@
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;
@@ -43,6 +44,15 @@ public void exit() {
LOGGER.log(System.Logger.Level.DEBUG, "Exited LobbyState state.");
}
/**
* 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()));
}
}
/**
* This method will be called whenever the server received a JoinedLobbyMessage message.
* It will also get the client id of the player who send this message
@@ -110,6 +120,7 @@ public void received(LobbyReadyMessage msg, int from) {
this.logic.getGame().setAllReady(true);
if (this.logic.getGame().allReady()) {
this.initializeGame();
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
}
}
@@ -152,6 +163,7 @@ public void received(LeaveGameMessage msg, int from) {
@Override
public void received(StartGameMessage msg, int from) {
if (msg.isForceStartGame() || this.logic.getGame().allReady()) {
this.initializeGame();
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
this.logic.setCurrentState(this.logic.getGameState());
}