diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index aa6efba..ad5db00 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -279,7 +279,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen private void handleB(boolean isPressed) { if (isPressed) { - Dialog tmp = new GulagInfo(this); + Dialog tmp = new GulagInfo(this, 3); tmp.open(); } } 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 2dffab0..f754eeb 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 @@ -18,6 +18,7 @@ import pp.monopoly.client.gui.popups.EventCardPopup; import pp.monopoly.client.gui.popups.FoodFieldCard; import pp.monopoly.client.gui.popups.GateFieldCard; import pp.monopoly.client.gui.popups.Gulag; +import pp.monopoly.client.gui.popups.GulagInfo; import pp.monopoly.client.gui.popups.LooserPopUp; import pp.monopoly.client.gui.popups.NoMoneyWarning; import pp.monopoly.client.gui.popups.Rent; @@ -380,8 +381,11 @@ public class TestWorld implements GameEventListener { new NoMoneyWarning(app).open(); } else if(event.msg().equals("rent")) { new Rent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open(); + } else if (event.msg().equals("jailtryagain")) { + new GulagInfo(app, 1).open(); + } else if (event.msg().equals("jailpay")) { + new GulagInfo(app, 3).open(); } - } @Override diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GulagInfo.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GulagInfo.java index 19c7e69..04dbaac 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GulagInfo.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GulagInfo.java @@ -9,10 +9,7 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; -import pp.monopoly.client.gui.TradeMenu; -import pp.monopoly.message.client.TradeResponse; -import pp.monopoly.model.TradeHandler; -import pp.monopoly.model.fields.PropertyField; +import pp.monopoly.message.client.NotificationAnswer; import pp.monopoly.notification.Sound; /** @@ -24,7 +21,7 @@ public class GulagInfo extends Dialog { private final Container backgroundContainer; - public GulagInfo(MonopolyApp app) { + public GulagInfo(MonopolyApp app, int trys) { super(app.getDialogManager()); this.app = app; @@ -54,12 +51,6 @@ public class GulagInfo extends Dialog { propertyValuesContainer.addChild(new Label("- löst eine Gulag-Frei-Karte ein", new ElementId("label-Text"))); propertyValuesContainer.addChild(new Label("- wartest 3 Runden und bezahlst dann", new ElementId("label-Text")));// Leerzeile propertyValuesContainer.addChild(new Label("- oder du würfelst einen Pasch", new ElementId("label-Text"))); - /*propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile - propertyValuesContainer.addChild(new Label("- ", new ElementId("label-Text"))); - propertyValuesContainer.addChild(new Label("- EUR", new ElementId("label-Text"))); - propertyValuesContainer.addChild(new Label("- Sonderkaten", new ElementId("label-Text"))); - propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile - propertyValuesContainer.addChild(new Label("tauschen, willst du das Angebot annehmen?", new ElementId("label-Text")));*/ propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -68,6 +59,7 @@ public class GulagInfo extends Dialog { negotiateButton.setFontSize(32); negotiateButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); + app.getGameLogic().send(new NotificationAnswer("PayJail")); close(); })); // Ereigniskarte-Button @@ -75,6 +67,7 @@ public class GulagInfo extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); + app.getGameLogic().send(new NotificationAnswer("UseJailCard")); close(); })); // Schließen-Button @@ -99,6 +92,14 @@ public class GulagInfo extends Dialog { 7 ); + if(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getNumJailCard() == 0) { + confirmButton.setEnabled(false); + } + + if(trys == 3) { + declineButton.setEnabled(false); + } + app.getGuiNode().attachChild(confirmTradeContainer); } 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 39314eb..fb99bca 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 @@ -347,6 +347,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { notifyListeners(new PopUpEvent(msg.getKeyWord(), msg)); } else if(msg.getKeyWord().equals("NoMoneyWarning")) { notifyListeners(new PopUpEvent("NoMoneyWarning", msg)); + } else if (msg.getKeyWord().equals("jailpay")) { + notifyListeners(new PopUpEvent("jailpay", msg)); + } else if (msg.getKeyWord().equals("jailtryagain")) { + notifyListeners(new PopUpEvent("jailtryagain", 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 eabfa99..8e98239 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 @@ -140,6 +140,9 @@ public class Player implements FieldVisitor{ System.out.println("State: "+state.getClass().getName()); if(!(state instanceof JailState)) { state = new ActiveState(); + } else { + String message = (((JailState)state).remainingAttempts <= 0) ? "jailpay" : "jailtryagain"; + handler.getLogic().send(this, new NotificationMessage(message)); } } @@ -439,7 +442,6 @@ public class Player implements FieldVisitor{ public void moveToJail() { setPosition(10); // Jail position on the board state = new JailState(); - System.out.println("JAIL EVENT"); handler.getLogic().send(this, new JailEvent(true)); } @@ -481,6 +483,7 @@ public class Player implements FieldVisitor{ return total; } + // private static int c = 0; /** * Inner class for dice functionality in the game. * Rolls random dice values. @@ -495,7 +498,13 @@ public class Player implements FieldVisitor{ */ private static int rollDice() { return random.nextInt(6) + 1; - // return 3; + + // c++; + // if(c < 7) { + // return 3; + // } else { + // return (c%4)+1; + // } } } @@ -612,12 +621,6 @@ public class Player implements FieldVisitor{ state = new ActiveState(); } else { 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")); - } } System.out.println("Feld:"+fieldID); return rollResult; 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 6156ba2..4077952 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 @@ -234,10 +234,10 @@ public class ServerGameLogic implements ClientInterpreter { @Override public void received(RollDice msg, int from) { Player player = playerHandler.getPlayerById(from); - if (player != null) { + if (player != null && player == playerHandler.getPlayerAtIndex(0)) { send(player, player.rollDice()); + updateAllPlayers(); } - updateAllPlayers(); } /** @@ -414,12 +414,11 @@ public class ServerGameLogic implements ClientInterpreter { @Override public void received(NotificationAnswer msg, int from) { - if(msg.getKeyword().equals("UseJailCard")) { + if(msg.getA().equals("UseJailCard")) { playerHandler.getPlayerById(from).useJailCard(); - } else if (msg.getKeyword().equals("PayJail")) { + } else if (msg.getA().equals("PayJail")) { playerHandler.getPlayerById(from).payBail(); } - updateAllPlayers(); } } 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 index a48033f..6f0efda 100644 --- 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 @@ -5,16 +5,16 @@ import com.jme3.network.serializing.Serializable; @Serializable public class NotificationAnswer extends ClientMessage{ - private String keyword; + private String A; private NotificationAnswer() {} - public NotificationAnswer(String keyword) { - this.keyword = keyword; + public NotificationAnswer(String A) { + this.A = A; } - public String getKeyword() { - return keyword; + public String getA() { + return A; } @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 ac65ca7..f271e1a 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 @@ -33,6 +33,7 @@ import pp.monopoly.message.client.AlterProperty; import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.ClientMessage; 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; @@ -175,6 +176,7 @@ public class MonopolyServer implements MessageListener, Connec Serializer.registerClass(TradeReply.class); Serializer.registerClass(TradeHandler.class); Serializer.registerClass(NotificationMessage.class); + Serializer.registerClass(NotificationAnswer.class); Serializer.registerClass(JailEvent.class); Serializer.registerClass(AlterProperty.class); Serializer.registerClass(GameOver.class); @@ -188,6 +190,8 @@ public class MonopolyServer implements MessageListener, Connec myServer.addMessageListener(this, TradeOffer.class); myServer.addMessageListener(this, TradeResponse.class); myServer.addMessageListener(this, ViewAssetsRequest.class); + myServer.addMessageListener(this, AlterProperty.class); + myServer.addMessageListener(this, NotificationAnswer.class); myServer.addConnectionListener(this); }