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 34fc1c4..82c3f25 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 @@ -10,12 +10,16 @@ import com.jme3.scene.shape.Box; import com.jme3.texture.Texture; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.client.gui.popups.EventCard; +import pp.monopoly.notification.DiceRollEvent; +import pp.monopoly.notification.EventCardEvent; +import pp.monopoly.notification.GameEventListener; /** * TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat. * Die Kamera wird durch den CameraController gesteuert. */ -public class TestWorld { +public class TestWorld implements GameEventListener{ private final MonopolyApp app; private CameraController cameraController; // Steuert die Kamera @@ -28,6 +32,7 @@ public class TestWorld { */ public TestWorld(MonopolyApp app) { this.app = app; + app.getGameLogic().addListener(this); } /** @@ -91,4 +96,9 @@ public class TestWorld { app.getRootNode().attachChild(geom); } + + @Override + public void receivedEvent(EventCardEvent event) { + new EventCard(app, event.description()).open(); + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index f3af9c3..2e1f613 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -195,6 +195,8 @@ public class Toolbar extends Dialog implements GameEventListener{ @Override public void receivedEvent(UpdatePlayerView event) { + playerHandler = app.getGameLogic().getPlayerHandler(); + System.err.println("Update Player View"); // Clear existing accountContainer and overviewContainer content accountContainer.clearChildren(); overviewContainer.clearChildren(); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java index a85eaa5..3b8a1f6 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java @@ -14,8 +14,6 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; -import pp.monopoly.model.card.Card; // TODO für den Import der Queue notwendig -import pp.monopoly.model.card.DeckHelper; /** * SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. */ @@ -24,14 +22,13 @@ public class EventCard extends Dialog { private final Geometry overlayBackground; private final Container eventCardContainer; private final Container backgroundContainer; + private final String description; - public EventCard(MonopolyApp app) { + public EventCard(MonopolyApp app, String description) { super(app.getDialogManager()); this.app = app; - - //Generate the corresponfing field - Card card = new DeckHelper().drawCard(); // TODO nimmt die Karten gerade unabhängig aus dem DeckHelper + this.description = description; // Halbtransparentes Overlay hinzufügen overlayBackground = createOverlayBackground(); @@ -56,7 +53,7 @@ public class EventCard extends Dialog { // Text, der auf der Karte steht // Die Preise werden dynamisch dem BoardManager entnommen Container propertyValuesContainer = eventCardContainer.addChild(new Container()); - propertyValuesContainer.addChild(new Label(card.getDescription(), new ElementId("label-Text"))); + propertyValuesContainer.addChild(new Label(description, new ElementId("label-Text"))); propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); propertyValuesContainer.setPreferredSize(new Vector3f(300,200,10)); @@ -114,6 +111,6 @@ public class EventCard extends Dialog { @Override public void escape() { - new SettingsMenu(app).open(); + close(); } } \ No newline at end of file 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 7a7ecdf..05f1329 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 @@ -26,12 +26,14 @@ import pp.monopoly.model.IntPoint; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.notification.ClientStateEvent; import pp.monopoly.notification.DiceRollEvent; +import pp.monopoly.notification.EventCardEvent; import pp.monopoly.notification.GameEvent; import pp.monopoly.notification.GameEventBroker; import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.InfoTextEvent; import pp.monopoly.notification.Sound; import pp.monopoly.notification.SoundEvent; +import pp.monopoly.notification.UpdatePlayerView; /** * Controls the client-side game logic for Monopoly. @@ -225,9 +227,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { */ @Override public void received(EventDrawCard msg) { - - // Kartenlogik playSound(Sound.EVENT_CARD); + notifyListeners(new EventCardEvent(msg.getCardDescription())); } /** @@ -282,8 +283,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { */ @Override public void received(PlayerStatusUpdate msg) { - - + playerHandler = msg.getPlayerHandler(); + notifyListeners(new UpdatePlayerView()); } /** 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 9aae056..c76cf8e 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 @@ -7,12 +7,15 @@ package pp.monopoly.game.server; +import java.util.ArrayList; import java.util.List; import java.util.Random; import com.jme3.network.serializing.Serializable; import pp.monopoly.message.server.DiceResult; +import pp.monopoly.message.server.EventDrawCard; +import pp.monopoly.message.server.PlayerStatusUpdate; import pp.monopoly.model.FieldVisitor; import pp.monopoly.model.Figure; import pp.monopoly.model.card.Card; @@ -36,7 +39,7 @@ public class Player implements FieldVisitor{ private String name; private int accountBalance = 15000; private Figure figure; - private List properties; + private List properties = new ArrayList<>(); private int getOutOfJailCard; private int fieldID; private DiceResult rollResult; @@ -319,7 +322,9 @@ public class Player implements FieldVisitor{ @Override public Void visit(EventField field) { Card c = getHandler().getLogic().getDeckHelper().drawCard(); - getHandler().getLogic().getDeckHelper().visit(c, this); + getHandler().getLogic().getDeckHelper().visit(c, this); //Logic + getHandler().getLogic().send(this, new EventDrawCard(c.getDescription())); // Card notification + getHandler().getLogic().send(this, new PlayerStatusUpdate(getHandler())); //update view return null; } @@ -408,6 +413,10 @@ public class Player implements FieldVisitor{ return state.rollDice(); } + private void visitEvent() { + getHandler().getLogic().getBoardManager().getFieldAtIndex(36).accept(this); + } + /** * A interface representing the PlayerStates */ @@ -519,6 +528,7 @@ public class Player implements FieldVisitor{ @Override public DiceResult rollDice() { + visitEvent(); return null; } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java index 0a84661..e6cc7bf 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java @@ -2,36 +2,24 @@ package pp.monopoly.message.server; import com.jme3.network.serializing.Serializable; -import pp.monopoly.game.server.PlayerColor; +import pp.monopoly.game.server.PlayerHandler; @Serializable public class PlayerStatusUpdate extends ServerMessage{ - private String playerName; - private String status; - private PlayerColor color; + private PlayerHandler playerHandler; /** * Default constructor for serialization purposes. */ private PlayerStatusUpdate() { /* empty */ } - public PlayerStatusUpdate(String playerName, String status, PlayerColor color) { - this.playerName = playerName; - this.status = status; - this.color = color; + public PlayerStatusUpdate(PlayerHandler playerHandler) { + this.playerHandler = playerHandler; } - public String getPlayerName() { - return playerName; - } - - public String getStatus() { - return status; - } - - public PlayerColor getColor() { - return color; + public PlayerHandler getPlayerHandler() { + return playerHandler; } @Override diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java index 500d14a..50aa77f 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java @@ -48,6 +48,8 @@ public class DeckHelper{ cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500 EUR", "party-gewinn")); cards.add(new Card("Zur falschen Zeit am falschen Ort. Du musst einen Bergmarsch planen und setzt eine Runde aus.", "bergmarsch")); cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000 EUR", "jodel-eispenis")); + + shuffle(); } public void visit(Card card, Player player) { @@ -203,7 +205,7 @@ public class DeckHelper{ } private void namensschildTruppenkueche(Player player) { - //TODO + //TODO 10 existiert nicht mehr } private void spendierhosenUnibar(Player player) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/EventCardEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/EventCardEvent.java new file mode 100644 index 0000000..2f6a16c --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/EventCardEvent.java @@ -0,0 +1,10 @@ +package pp.monopoly.notification; + +public record EventCardEvent(String description) implements GameEvent{ + + @Override + public void notifyListener(GameEventListener listener) { + listener.receivedEvent(this); + } + +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java index d5cc0bf..1d50dcb 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java @@ -58,5 +58,12 @@ public interface GameEventListener { * * @param event the received event */ -default void receivedEvent(UpdatePlayerView event) { /*Do nothing */} + default void receivedEvent(UpdatePlayerView event) { /*Do nothing */} + + /** + * Indicates that an event card has been drawn + * + * @param event the received event + */ + default void receivedEvent(EventCardEvent event) { /*Do nothing */} } 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 92557bf..7674613 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 @@ -38,8 +38,10 @@ import pp.monopoly.message.client.TradeOffer; import pp.monopoly.message.client.TradeResponse; import pp.monopoly.message.client.ViewAssetsRequest; import pp.monopoly.message.server.DiceResult; +import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.NextPlayerTurn; +import pp.monopoly.message.server.PlayerStatusUpdate; import pp.monopoly.message.server.ServerMessage; import pp.monopoly.model.Figure; import pp.monopoly.model.IntPoint; @@ -132,6 +134,8 @@ public class MonopolyServer implements MessageListener, Connec Serializer.registerClass(Figure.class); Serializer.registerClass(PlayerHandler.class); Serializer.registerClass(DiceResult.class); + Serializer.registerClass(EventDrawCard.class); + Serializer.registerClass(PlayerStatusUpdate.class); } private void registerListeners() {