From 0e405d2f9054b74b31c4860273151d671505c19f Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 25 Nov 2024 22:11:35 +0100 Subject: [PATCH] send PlayerHandler in GameStart --- .../monopoly/game/client/ClientGameLogic.java | 9 ++++--- .../java/pp/monopoly/game/server/Player.java | 4 +-- .../monopoly/game/server/PlayerHandler.java | 3 +-- .../monopoly/game/server/ServerGameLogic.java | 2 +- .../pp/monopoly/message/server/GameStart.java | 14 +++++----- .../pp/monopoly/server/MonopolyServer.java | 26 +------------------ 6 files changed, 16 insertions(+), 42 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index 978b2e7..3a6df03 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import pp.monopoly.game.server.Player; +import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.server.BuyPropertyResponse; import pp.monopoly.message.server.DiceResult; @@ -52,7 +53,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { /** The current state of the client game logic. */ private ClientState state = new LobbyState(this); - private List players; + private PlayerHandler playerHandler; private BoardManager boardManager = new BoardManager(); @@ -94,8 +95,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { state.entry(); } - public List getPlayers() { - return players; + public PlayerHandler getPlayerHandler() { + return playerHandler; } /** @@ -255,7 +256,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { */ @Override public void received(GameStart msg) { - players = msg.getPlayers(); + playerHandler = msg.getPlayerHandler(); setState(new WaitForTurnState(this)); } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java index 649a38c..c350479 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java @@ -40,8 +40,8 @@ public class Player implements FieldVisitor{ private int getOutOfJailCard; private int fieldID; private DiceResult rollResult; - private final PlayerHandler handler; - private PlayerState state = new LobbyState(); + private transient final PlayerHandler handler; + private transient PlayerState state = new LobbyState(); /** * Default constructor for serialization purposes. 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 aebe09c..d9a8326 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 @@ -1,6 +1,5 @@ package pp.monopoly.game.server; -import java.util.LinkedList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -18,7 +17,7 @@ import pp.monopoly.model.LimitedLinkedList; public class PlayerHandler { private List players = new LimitedLinkedList<>(6); private Set readyPlayers = new HashSet<>(); - private ServerGameLogic logic; + private transient ServerGameLogic logic; private Player hostPlayer; private Player extra = null; 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 d87d163..bcfd8da 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 @@ -204,7 +204,7 @@ public class ServerGameLogic implements ClientInterpreter { if(playerHandler.allPlayersReady()) { playerHandler.setStartBalance(startMoney); for (Player p : playerHandler.getPlayers()) { - send(p, new GameStart(playerHandler.getPlayers())); + send(p, new GameStart(playerHandler)); } playerHandler.randomOrder(); send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn()); 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 9dfab8d..45ea0b3 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,27 +1,25 @@ package pp.monopoly.message.server; -import java.util.List; - import com.jme3.network.serializing.Serializable; -import pp.monopoly.game.server.Player; +import pp.monopoly.game.server.PlayerHandler; @Serializable public class GameStart extends ServerMessage{ - private List players; + private PlayerHandler playerHandler; /** * Default constructor for serialization purposes. */ private GameStart() { /* empty */ } - public GameStart(List players) { - this.players = players; + public GameStart(PlayerHandler playerHandler) { + this.playerHandler = playerHandler; } - public List getPlayers() { - return players; + public PlayerHandler getPlayerHandler() { + return playerHandler; } @Override diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index d373e64..4c1b56d 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -43,18 +43,6 @@ import pp.monopoly.message.server.ServerMessage; import pp.monopoly.model.Figure; import pp.monopoly.model.IntPoint; import pp.monopoly.model.LimitedLinkedList; -import pp.monopoly.model.fields.BuildingProperty; -import pp.monopoly.model.fields.EventField; -import pp.monopoly.model.fields.Field; -import pp.monopoly.model.fields.FieldColor; -import pp.monopoly.model.fields.FineField; -import pp.monopoly.model.fields.FoodField; -import pp.monopoly.model.fields.GateField; -import pp.monopoly.model.fields.GoField; -import pp.monopoly.model.fields.GulagField; -import pp.monopoly.model.fields.PropertyField; -import pp.monopoly.model.fields.TestStreckeField; -import pp.monopoly.model.fields.WacheField; /** * Server implementing the visitor pattern as MessageReceiver for ClientMessages @@ -141,19 +129,7 @@ public class MonopolyServer implements MessageListener, Connec Serializer.registerClass(NextPlayerTurn.class); Serializer.registerClass(Player.class); Serializer.registerClass(Figure.class); - // Serializer.registerClass(PlayerHandler.class); - // Serializer.registerClass(BuildingProperty.class); - // Serializer.registerClass(EventField.class); - // Serializer.registerClass(Field.class); - // // Serializer.registerClass(FieldColor.class); - // Serializer.registerClass(FineField.class); - // Serializer.registerClass(FoodField.class); - // Serializer.registerClass(GateField.class); - // Serializer.registerClass(GoField.class); - // Serializer.registerClass(GulagField.class); - // Serializer.registerClass(PropertyField.class); - // Serializer.registerClass(TestStreckeField.class); - // Serializer.registerClass(WacheField.class); + Serializer.registerClass(PlayerHandler.class); } private void registerListeners() {