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..b3cd33b 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 @@ -494,6 +494,7 @@ public class Player implements FieldVisitor{ */ private static int rollDice() { return random.nextInt(6) + 1; + // return 3; } } @@ -612,6 +613,7 @@ public class Player implements FieldVisitor{ remainingAttempts--; if (remainingAttempts <= 0) { handler.getLogic().send(Player.this, new NotificationMessage("jailpay")); + if(getOutOfJailCard == 0) payBail(); } else { handler.getLogic().send(Player.this, new NotificationMessage("jailtryagain")); } @@ -622,23 +624,15 @@ public class Player implements FieldVisitor{ @Override 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("")); - } } @Override 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..6156ba2 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,11 +14,13 @@ 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; import pp.monopoly.message.client.TradeResponse; import pp.monopoly.message.client.ViewAssetsRequest; +import pp.monopoly.message.server.GameOver; import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.NextPlayerTurn; import pp.monopoly.message.server.PlayerStatusUpdate; @@ -181,8 +183,14 @@ public class ServerGameLogic implements ClientInterpreter { send(next, new NextPlayerTurn()); send(next, new PlayerStatusUpdate(playerHandler)); send(player, new PlayerStatusUpdate(playerHandler)); + } else { + send(player, new GameOver(false)); + playerHandler.removePlayer(player); } } + if(playerHandler.getPlayers().size() == 1) { + send(playerHandler.getPlayerAtIndex(0), new GameOver(true)); + } updateAllPlayers(); } @@ -400,5 +408,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); + } + +} 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 2fa1a50..ac65ca7 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 @@ -41,6 +41,7 @@ import pp.monopoly.message.client.ViewAssetsRequest; import pp.monopoly.message.server.BuyPropertyRequest; import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.EventDrawCard; +import pp.monopoly.message.server.GameOver; import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.JailEvent; import pp.monopoly.message.server.NextPlayerTurn; @@ -176,6 +177,7 @@ public class MonopolyServer implements MessageListener, Connec Serializer.registerClass(NotificationMessage.class); Serializer.registerClass(JailEvent.class); Serializer.registerClass(AlterProperty.class); + Serializer.registerClass(GameOver.class); } private void registerListeners() {