merge dev into test #30

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

View File

@@ -4,7 +4,9 @@
import pp.mdga.client.ClientState;
import pp.mdga.client.DialogsState;
import pp.mdga.game.Color;
import pp.mdga.game.Piece;
import pp.mdga.game.Player;
import pp.mdga.game.PlayerData;
import pp.mdga.message.client.*;
import pp.mdga.message.server.LobbyPlayerJoinedMessage;
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
@@ -13,6 +15,8 @@
import pp.mdga.message.server.UpdateTSKMessage;
import pp.mdga.notification.*;
import java.util.*;
public class LobbyState extends DialogStates {
private final DialogsState parent;
@@ -73,6 +77,13 @@ public void selectStart(){
public void received(ServerStartGameMessage msg){
logic.getGame().setBoard(msg.getBoard());
logic.addNotification(new GameNotification(logic.getGame().getPlayers().get(parent.getOwnPlayerId()).getColor()));
for(Map.Entry<Color, PlayerData> entry : msg.getBoard().getPlayerData().entrySet()){
List<UUID> pieceIds = new ArrayList<>();
for (Piece piece : entry.getValue().getPieces()){
pieceIds.add(piece.getUuid());
}
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceIds, logic.getGame().getPlayerByColor(entry.getKey()).getName()));
}
parent.startGame();
}

View File

@@ -33,6 +33,17 @@ public Board() {
}
}
/**
* This method will be used to add the given color and playerData parameters to the playerData attribute of
* Board class.
*
* @param color as the color of the player as a Color enumeration.
* @param playerData as the playerData of the player as a PlayerData object.
*/
public void addPlayerData(Color color, PlayerData playerData) {
this.playerData.put(color, playerData);
}
/**
* This method returns the playerData
*

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());
}