From 7ace959f1f95b862adf24340dea71c6c3fc0554e Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 02:48:06 +0100 Subject: [PATCH] sellHouse --- .../monopoly/client/gui/popups/BuyHouse.java | 5 ++++ .../monopoly/client/gui/popups/SellHouse.java | 23 +++++++++++++++---- .../monopoly/game/server/ServerGameLogic.java | 13 +++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java index d2b3c4e..81c1c73 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java @@ -147,6 +147,11 @@ public class BuyHouse extends Dialog { selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + // Set initial selection + if (!propertyOptions.isEmpty()) { + onDropdownSelectionChanged(propertySelector); + } + return dropdownContainer; } /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java index 08d78c5..3b1fcf1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java @@ -21,7 +21,7 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.game.server.Player; -import pp.monopoly.message.client.BuyPropertyResponse; +import pp.monopoly.message.client.AlterProperty; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.notification.Sound; @@ -73,7 +73,7 @@ public class SellHouse extends Dialog { Container downContainer = sellhouseContainer.addChild(new Container()); // Text, der auf der Karte steht - upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen + upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -99,9 +99,16 @@ public class SellHouse extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - // Send the "alter building" message to the server - //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server - + AlterProperty msg = new AlterProperty("SellHouse"); + for (String string : selectedProperties) { + System.out.println(string); + } + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + for (Integer integer : msg.getProperties()) { + System.out.println("ID des verkaufs: "+integer); + } + app.getGameLogic().send(msg); + close(); })); // Zentriere das Popup @@ -149,6 +156,11 @@ public class SellHouse extends Dialog { selectionDisplay = new TextField(""); // Create TextField for displaying selections selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + + // Set initial selection + if (!propertyOptions.isEmpty()) { + onDropdownSelectionChanged(propertySelector); + } return dropdownContainer; } @@ -164,6 +176,7 @@ public class SellHouse extends Dialog { return boardManager.getPropertyFields(self.getProperties()).stream() .filter(property -> property instanceof BuildingProperty) .map(property -> (BuildingProperty) property) + .filter(p -> app.getGameLogic().getBoardManager().canSell(p)) .collect(Collectors.toList()); } 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 87b69af..a4fcf31 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 @@ -382,27 +382,32 @@ public class ServerGameLogic implements ClientInterpreter { public void received(AlterProperty msg, int from) { Player sender = playerHandler.getPlayerById(from); + Set properties = new HashSet<>(); + for (Integer integer : msg.getProperties()) { + properties.add( (PropertyField)boardManager.getFieldAtIndex(integer)); + } + if (msg.getKeyword().equals("TakeMortage")) { - for (PropertyField field : sender.getPropertyFields()) { + for (PropertyField field : properties) { field.setMortgaged(true); sender.earnMoney(field.getHypo()); } } else if (msg.getKeyword().equals("RepayMortage")) { - for (PropertyField field : sender.getPropertyFields()) { + for (PropertyField field : properties) { if(sender.getAccountBalance() >= field.getHypo()) { field.setMortgaged(false); sender.pay(field.getHypo()); } } } else if(msg.getKeyword().equals("BuyHouse")) { - for (BuildingProperty field : sender.getPropertyFields().stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { + for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) { if (boardManager.canBuild(field) && sender.getAccountBalance() >= field.getHousePrice()) { field.build(); sender.pay(field.getHousePrice()); } } } else if(msg.getKeyword().equals("SellHouse")) { - for (BuildingProperty field : sender.getPropertyFields().stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { + for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) { if (boardManager.canSell(field)) { field.sell(); sender.earnMoney(field.getHousePrice());