From 11f4560745ca962a678056acd428b6ad66308f3f Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 1 Dec 2024 20:31:29 +0100 Subject: [PATCH] du kommst ins Gulag Popup --- .../pp/monopoly/client/gui/TestWorld.java | 2 ++ .../monopoly/game/client/ClientGameLogic.java | 6 ++--- .../java/pp/monopoly/game/server/Player.java | 6 ----- .../monopoly/game/server/ServerGameLogic.java | 14 +++++++++++ .../message/client/ClientInterpreter.java | 8 ++++++ .../message/client/NotificationAnswer.java | 25 +++++++++++++++++++ 6 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/NotificationAnswer.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java index 3548c76..a39684c 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java @@ -292,6 +292,8 @@ public class TestWorld implements GameEventListener { new TimeOut(app).open(); } else if(event.msg().equals("tradeRequest")) { new ConfirmTrade(app).open(); + } else if (event.msg().equals("goingToJail")) { + new Gulag(app).open(); } } 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 d12ae40..841e7d9 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 @@ -261,10 +261,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { @Override public void received(JailEvent msg) { if (msg.isGoingToJail()) { - playSound(Sound.GULAG); - } else { - System.out.println("NO MORE JAIL"); + notifyListeners(new PopUpEvent("goingToJail", msg)); } } @@ -345,6 +343,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { public void received(NotificationMessage msg) { if (msg.getKeyWord().equals("rent")) { notifyListeners(new PopUpEvent("rent", msg)); + } else if (msg.getKeyWord().equals("jailpay")) { + notifyListeners(new PopUpEvent(msg.getKeyWord(), msg)); } } } 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 ae1c20b..6e220b2 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 @@ -624,10 +624,7 @@ public class Player implements FieldVisitor{ public void payBail() { if (accountBalance >= 500) { pay(500); - handler.getLogic().send(Player.this, new NotificationMessage("")); state = new ActiveState(); - } else { - handler.getLogic().send(Player.this, new NotificationMessage("")); } } @@ -635,10 +632,7 @@ public class Player implements FieldVisitor{ public void useJailCard() { if (getOutOfJailCard > 0) { removeJailCard(); - handler.getLogic().send(Player.this, new NotificationMessage("")); state = new ActiveState(); - } else { - handler.getLogic().send(Player.this, new NotificationMessage("")); } } } 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 4193f37..f09feb0 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 @@ -14,6 +14,7 @@ import pp.monopoly.message.client.AlterProperty; import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.ClientInterpreter; import pp.monopoly.message.client.EndTurn; +import pp.monopoly.message.client.NotificationAnswer; import pp.monopoly.message.client.PlayerReady; import pp.monopoly.message.client.RollDice; import pp.monopoly.message.client.TradeOffer; @@ -400,5 +401,18 @@ public class ServerGameLogic implements ClientInterpreter { } } } + + updateAllPlayers(); + } + + @Override + public void received(NotificationAnswer msg, int from) { + if(msg.getKeyword().equals("UseJailCard")) { + playerHandler.getPlayerById(from).useJailCard(); + } else if (msg.getKeyword().equals("PayJail")) { + playerHandler.getPlayerById(from).payBail(); + } + + updateAllPlayers(); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java index 9f68460..63846e7 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java @@ -74,4 +74,12 @@ public interface ClientInterpreter { * @param from the connection ID from which the message was received */ void received(AlterProperty msg, int from); + + /** + * Processes a received NotificationAnswer. + * + * @param msg the NotificationAnswer to be processed + * @param from the connection ID from which the message was received + */ + void received(NotificationAnswer msg, int from); } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/NotificationAnswer.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/NotificationAnswer.java new file mode 100644 index 0000000..a48033f --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/NotificationAnswer.java @@ -0,0 +1,25 @@ +package pp.monopoly.message.client; + +import com.jme3.network.serializing.Serializable; + +@Serializable +public class NotificationAnswer extends ClientMessage{ + + private String keyword; + + private NotificationAnswer() {} + + public NotificationAnswer(String keyword) { + this.keyword = keyword; + } + + public String getKeyword() { + return keyword; + } + + @Override + public void accept(ClientInterpreter interpreter, int from) { + interpreter.received(this, from); + } + +}