From 422faec28156d183b6d448ff008b4f810f8fb42f Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 24 Nov 2024 22:06:19 +0100 Subject: [PATCH] send player ready --- .../pp/monopoly/client/gui/LobbyMenu.java | 22 +++++++++++-------- .../monopoly/game/client/ClientGameLogic.java | 1 + .../message/client/BuyPropertyRequest.java | 8 +++++++ .../pp/monopoly/message/client/EndTurn.java | 9 ++++++++ .../monopoly/message/client/PlayerReady.java | 16 ++++++++++---- .../pp/monopoly/message/client/RollDice.java | 9 ++++++++ .../monopoly/message/client/TradeOffer.java | 7 ++++++ .../message/client/TradeResponse.java | 8 +++++++ .../message/client/ViewAssetsRequest.java | 10 ++++++++- .../pp/monopoly/server/MonopolyServer.java | 15 +++++++++++++ 10 files changed, 91 insertions(+), 14 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java index c0a4b0d..aea34df 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java @@ -40,14 +40,12 @@ public class LobbyMenu extends Dialog { private TextField playerInputField = new TextField("Spieler 1"); private TextField startingCapital = new TextField("15000"); + private String figure; public LobbyMenu(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - // Entfernt das CreateGameMenu (inklusive Hintergrund) - app.getGuiNode().detachAllChildren(); - // Hintergrundbild laden und hinzufügen addBackgroundImage(); @@ -207,7 +205,7 @@ public class LobbyMenu extends Dialog { * Schaltet den "Bereit"-Status um. */ private void toggleReady(Label playersLabel) { - app.getGameLogic().send(new PlayerReady(true, "Test", "flugzeug", 15000));; + app.getGameLogic().send(new PlayerReady(true, playerInputField.getText(), figure, Integer.parseInt(startingCapital.getText()))); } @Override @@ -258,19 +256,25 @@ public class LobbyMenu extends Dialog { System.out.println("Selected: " + selected); switch (selected) { case "[0]": - System.out.println("Alpha selected"); + figure = "Laptop"; break; case "[1]": - System.out.println("Beta selected"); + figure = "Flugzeug"; break; case "[2]": - System.out.println("Gamma selected"); + figure = "Jägermeister"; break; case "[3]": - close(); + figure = "Katze"; + break; + case "[4]": + figure = "OOP"; + break; + case "[5]": + figure = "Handyholster"; break; default: - System.out.println("Unknown selection"); + break; } } 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 bf16bc9..de58eda 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 @@ -144,6 +144,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS } else { clientSender.send(msg); + System.out.println("Message gesendet"); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java index 12a6bc9..6ecd9b3 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java @@ -1,11 +1,19 @@ package pp.monopoly.message.client; +import com.jme3.network.serializing.Serializable; + /** * Represents a request from a player to buy a property. */ +@Serializable public class BuyPropertyRequest extends ClientMessage{ private int propertyId; + /** + * Default constructor for serialization purposes. + */ + private BuyPropertyRequest() { /* empty */ } + /** * Constructs a BuyPropertyRequest with the specified property ID. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/EndTurn.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/EndTurn.java index dae8120..f08e8cd 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/EndTurn.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/EndTurn.java @@ -1,9 +1,18 @@ package pp.monopoly.message.client; + +import com.jme3.network.serializing.Serializable; + /** * Represents a message indicating the player wants to end their turn. */ +@Serializable public class EndTurn extends ClientMessage{ + /** + * Default constructor for serialization purposes. + */ + public EndTurn() { /* empty */ } + @Override public void accept(ClientInterpreter interpreter, int from) { interpreter.received(this, from); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/PlayerReady.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/PlayerReady.java index 42aa0d6..ee61d11 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/PlayerReady.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/PlayerReady.java @@ -1,13 +1,21 @@ package pp.monopoly.message.client; +import com.jme3.network.serializing.Serializable; + /** * Represents a message indicating the player is ready to play. */ +@Serializable public class PlayerReady extends ClientMessage { - private final boolean isReady; - private final String name; - private final String figure; - private final int startMoney; + private boolean isReady; + private String name; + private String figure; + private int startMoney; + + /** + * Default constructor for serialization purposes. + */ + private PlayerReady() { /* empty */ } /** * Constructs a PlayerReady message. diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java index 9fb0b93..a4d5dfc 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java @@ -1,9 +1,18 @@ package pp.monopoly.message.client; + +import com.jme3.network.serializing.Serializable; + /** * Represents a message requesting to roll the dice. */ +@Serializable public class RollDice extends ClientMessage{ + /** + * Default constructor for serialization purposes. + */ + private RollDice() { /* empty */ } + @Override public void accept(ClientInterpreter interpreter, int from) { interpreter.received(this, from); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeOffer.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeOffer.java index b614365..edb885f 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeOffer.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeOffer.java @@ -1,14 +1,21 @@ package pp.monopoly.message.client; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.model.TradeHandler; /** * Represents a trade Request message from one player to another. */ +@Serializable public class TradeOffer extends ClientMessage{ private int receiverId; private TradeHandler tradehandler; + /** + * Default constructor for serialization purposes. + */ + private TradeOffer() { /* empty */ } /** * Constructs a TradeOffer with the specified details. diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java index d317c6f..78d38f0 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java @@ -1,14 +1,22 @@ package pp.monopoly.message.client; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.model.TradeHandler; /** * Represents a response to a trade offer. */ +@Serializable public class TradeResponse extends ClientMessage{ private int initiatorId; private TradeHandler tradeHandler; + /** + * Default constructor for serialization purposes. + */ + private TradeResponse() { /* empty */ } + /** * Constructs a TradeResponse with the specified response details. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java index afbdc79..11c26af 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java @@ -1,13 +1,21 @@ package pp.monopoly.message.client; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.game.server.Player; /** * Represents a request from a player to view their assets. */ +@Serializable public class ViewAssetsRequest extends ClientMessage{ - private final Player player; + private Player player; + + /** + * Default constructor for serialization purposes. + */ + private ViewAssetsRequest() { /* empty */ } public ViewAssetsRequest(Player player) { this.player = player; 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 f4bfa7e..479c36c 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 @@ -28,7 +28,14 @@ import pp.monopoly.MonopolyConfig; import pp.monopoly.game.server.Player; import pp.monopoly.game.server.ServerGameLogic; import pp.monopoly.game.server.ServerSender; +import pp.monopoly.message.client.BuyPropertyRequest; import pp.monopoly.message.client.ClientMessage; +import pp.monopoly.message.client.EndTurn; +import pp.monopoly.message.client.PlayerReady; +import pp.monopoly.message.client.RollDice; +import pp.monopoly.message.client.TradeOffer; +import pp.monopoly.message.client.TradeResponse; +import pp.monopoly.message.client.ViewAssetsRequest; import pp.monopoly.message.server.ServerMessage; import pp.monopoly.model.IntPoint; @@ -105,6 +112,13 @@ public class MonopolyServer implements MessageListener, Connec private void initializeSerializables() { Serializer.registerClass(IntPoint.class); + Serializer.registerClass(BuyPropertyRequest.class); + Serializer.registerClass(EndTurn.class); + Serializer.registerClass(PlayerReady.class); + Serializer.registerClass(RollDice.class); + Serializer.registerClass(TradeOffer.class); + Serializer.registerClass(TradeResponse.class); + Serializer.registerClass(ViewAssetsRequest.class); } private void registerListeners() { @@ -113,6 +127,7 @@ public class MonopolyServer implements MessageListener, Connec @Override public void messageReceived(HostedConnection source, Message message) { + System.out.println("Message recieved"); LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS if (message instanceof ClientMessage clientMessage) pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));