From cdce478d7770e5905e69effaa723e09350612152 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Wed, 20 Nov 2024 01:45:34 +0100 Subject: [PATCH] send GameStart message with a list of all Players --- .../pp/monopoly/game/server/PlayerHandler.java | 8 ++++++++ .../pp/monopoly/game/server/ServerGameLogic.java | 7 +++++++ .../java/pp/monopoly/message/server/GameStart.java | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index d7bbe10..3cbe272 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -50,6 +50,14 @@ public class PlayerHandler { return players.size(); } + /** + * Retuns all players + * @return List of all players + */ + public List getPlayers() { + return players; + } + /** * Chechs if all players are ready to start the game * @return {@code true} if all players are ready, otherwise {@code false} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 62cdd72..9ce732d 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -2,6 +2,7 @@ package pp.monopoly.game.server; import pp.monopoly.MonopolyConfig; import pp.monopoly.message.client.*; +import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.ServerMessage; import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeRequest; @@ -177,6 +178,12 @@ public class ServerGameLogic implements ClientInterpreter { playerHandler.setPlayerReady(player, true); LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName()); } + + if(playerHandler.allPlayersReady()) { + for (Player p : playerHandler.getPlayers()) { + send(p, new GameStart(playerHandler.getPlayers())); + } + } } /** diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java index bf39031..cfdfe54 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java @@ -1,7 +1,21 @@ package pp.monopoly.message.server; +import java.util.List; + +import pp.monopoly.game.server.Player; + public class GameStart extends ServerMessage{ + private final List players; + + public GameStart(List players) { + this.players = players; + } + + public List getPlayers() { + return players; + } + @Override public void accept(ServerInterpreter interpreter) { interpreter.received(this);