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/NetworkSupport.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java index da9198f..5ecd257 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java @@ -25,7 +25,7 @@ import java.lang.System.Logger.Level; import static pp.monopoly.Resources.lookup; /** - * Manages the network connection for the Battleship application. + * Manages the network connection for the Monopoly application. * Handles connecting to and disconnecting from the server, and sending messages. */ public class NetworkSupport implements MessageListener, ClientStateListener, ServerConnection { @@ -34,9 +34,9 @@ public class NetworkSupport implements MessageListener, ClientStateListe private Client client; /** - * Constructs a NetworkSupport instance for the given Battleship application. + * Constructs a NetworkSupport instance for the given Monopoly application. * - * @param app The Battleship application instance. + * @param app The Monopoly application instance. */ public NetworkSupport(MonopolyApp app) { this.app = app; @@ -44,6 +44,7 @@ public class NetworkSupport implements MessageListener, ClientStateListe /** * Return the client connections Id + * * @return the client id */ public int getId() { @@ -52,9 +53,9 @@ public class NetworkSupport implements MessageListener, ClientStateListe } /** - * Returns the Battleship application instance. + * Returns the Monopoly application instance. * - * @return Battleship application instance + * @return Monopoly application instance */ public MonopolyApp getApp() { return app; diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java index a96d8e2..d903c03 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java @@ -163,14 +163,6 @@ public class BuildingAdminMenu extends Dialog { app.getGuiNode().attachChild(background); } - /** - * Handles the "Zurück" action. - */ - private void handleBack() { - app.getGameLogic().playSound(Sound.BUTTON); - close(); - } - @Override public void close() { app.getGuiNode().detachChild(mainContainer); @@ -180,7 +172,7 @@ public class BuildingAdminMenu extends Dialog { @Override public void escape() { - handleBack(); + new SettingsMenu(app).open(); } @Override diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java index f0faeb5..9d7f710 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java @@ -14,7 +14,6 @@ import com.simsilica.lemur.Checkbox; import com.simsilica.lemur.Label; import com.simsilica.lemur.style.ElementId; -import static pp.monopoly.Resources.lookup; import pp.monopoly.client.GameMusic; import pp.monopoly.client.GameSound; import pp.monopoly.client.MonopolyApp; 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 fce9ae6..deaa3f1 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 @@ -17,20 +17,24 @@ import com.jme3.scene.control.AbstractControl; import com.jme3.texture.Texture; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.client.gui.popups.AcceptTrade; import pp.monopoly.client.gui.popups.BuildingPropertyCard; import pp.monopoly.client.gui.popups.ConfirmTrade; 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.RejectTrade; import pp.monopoly.client.gui.popups.Rent; import pp.monopoly.client.gui.popups.TimeOut; import pp.monopoly.client.gui.popups.WinnerPopUp; import pp.monopoly.game.server.Player; import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.message.server.NotificationMessage; +import pp.monopoly.message.server.TradeReply; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.FoodField; import pp.monopoly.model.fields.GateField; @@ -403,8 +407,15 @@ 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(); + } else if (event.msg().equals("tradepos")) { + new AcceptTrade(app, (TradeReply) event.message()).open(); + } else if (event.msg().equals("tradeneg")) { + new RejectTrade(app, (TradeReply) event.message()).open(); + } } private Vector3f calculateBuildingPosition(int fieldID) { diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java index b731ae3..7efcae4 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -84,24 +84,6 @@ public class TradeMenu extends Dialog { mainContent.addChild(createMiddleSection()); mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false)); - Container buttons = mainContent.addChild(new Container(new SpringGridLayout())); - Button cancel = new Button("Abbrechen"); - cancel.addClickCommands(s -> ifTopDialog(() -> { - close(); - app.getGameLogic().playSound(Sound.BUTTON); - })); - - Button trade = new Button("Handeln"); - trade.addClickCommands(s -> ifTopDialog(() -> { - app.getGameLogic().playSound(Sound.BUTTON); - setTrades(); - app.getGameLogic().send(new TradeOffer(tradeHandler)); - close(); - })); - - buttons.addChild(cancel); - buttons.addChild(trade); - return mainContent; } @@ -196,16 +178,30 @@ public class TradeMenu extends Dialog { leftSelectionsField = middleSection.addChild(new TextField("")); leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); - Label arrows = middleSection.addChild(new Label("⇅")); - arrows.setFontSize(40); + Container buttons = middleSection.addChild(new Container(new SpringGridLayout())); + Button cancel = new Button("Abbrechen"); + cancel.addClickCommands(s -> ifTopDialog(() -> { + close(); + app.getGameLogic().playSound(Sound.BUTTON); + })); - rightSelectionsField = middleSection.addChild(new TextField("")); - rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); + Button trade = new Button("Handeln"); + trade.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + setTrades(); + app.getGameLogic().send(new TradeOffer(tradeHandler)); + close(); + })); + + buttons.addChild(cancel); + buttons.addChild(trade); Label middleLabelBottom = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:")); middleLabelBottom.setFontSize(24); middleLabelBottom.setInsets(new Insets3f(5, 5, 5, 5)); + rightSelectionsField = middleSection.addChild(new TextField("")); + rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); return middleSection; } @@ -217,6 +213,7 @@ public class TradeMenu extends Dialog { private void styleTextField(TextField textField) { textField.setInsets(new Insets3f(5, 10, 5, 10)); textField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black)); + textField.setPreferredSize(new Vector3f(300, 30, 0)); } private void assignSelectors(Selector buildingSelector, Selector specialCardSelector, TextField currencyInput, boolean isLeft) { @@ -281,7 +278,6 @@ public class TradeMenu extends Dialog { } for (String property : leftselBuildings) { buildingText.append(property); - buildingText.append(", "); } } else { if (rightselBuildings.contains(building.getSelectedItem())) { @@ -291,7 +287,6 @@ public class TradeMenu extends Dialog { } for (String property : rightselBuildings) { buildingText.append(property); - buildingText.append(", "); } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java index fdbd22d..f2fb28f 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java @@ -13,6 +13,8 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.message.server.TradeReply; +import pp.monopoly.notification.Sound; /** * Bankrupt is a Warning-Popup which appears when the balance is negative at the end of a player´s turn @@ -25,7 +27,7 @@ public class AcceptTrade extends Dialog { - public AcceptTrade(MonopolyApp app) { + public AcceptTrade(MonopolyApp app, TradeReply msg) { super(app.getDialogManager()); this.app = app; @@ -55,7 +57,7 @@ public class AcceptTrade extends Dialog { // Text, der im Popup steht Container textContainer = noMoneyWarningContainer.addChild(new Container()); - textContainer.addChild(new Label("Du hast Spieler XXX einen Handel vorgeschlagen", new ElementId("label-Text"))); + textContainer.addChild(new Label("Du hast Spieler"+ msg.getTradeHandler().getReceiver().getName() + "einen Handel vorgeschlagen", new ElementId("label-Text"))); textContainer.addChild(new Label("", new ElementId("label-Text"))); textContainer.addChild(new Label("Der Handel wurde angenommen", new ElementId("label-Text"))); textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -66,7 +68,10 @@ public class AcceptTrade extends Dialog { // Beenden-Button Button quitButton = noMoneyWarningContainer.addChild(new Button("Bestätigen", new ElementId("button"))); quitButton.setFontSize(32); - quitButton.addClickCommands(source -> close()); + quitButton.addClickCommands(source -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Zentriere das Popup 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 2030f1a..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 @@ -6,8 +6,8 @@ import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; -import com.simsilica.lemur.ListBox; import com.simsilica.lemur.Selector; +import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.core.VersionedList; @@ -17,11 +17,12 @@ 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.AlterProperty; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; -import pp.monopoly.model.fields.PropertyField; import pp.monopoly.notification.Sound; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -33,9 +34,12 @@ public class BuyHouse extends Dialog { private final MonopolyApp app; private final Container buyHouseContainer; private final Container backgroundContainer; + private TextField selectionDisplay; // TextField to display selections private VersionedReference> selectionRef; private Selector propertySelector; - private BuildingProperty selectedProperty; + private Set selectedProperties = new HashSet<>(); + + private Label cost = new Label("0", new ElementId("label-Text")); public BuyHouse(MonopolyApp app) { super(app.getDialogManager()); @@ -76,7 +80,7 @@ public class BuyHouse extends Dialog { downContainer.addChild(new Label("", new ElementId("label-Text"))); // Empty line downContainer.addChild(new Label("Kosten:", new ElementId("label-Text"))); // Label for cost - downContainer.addChild(new Label("Hier die tatsächlichen Kosten", new ElementId("label-Text"))); // Cost details + downContainer.addChild(cost); // Cost details downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Cancel button @@ -92,11 +96,10 @@ public class BuyHouse extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - if (selectedProperty != null) { - System.out.println("Confirmed property: " + selectedProperty.getName()); - // Send the "alter building" message to the server - // app.getGameLogic().sendMessage(new AlterBuildingMessage(selectedProperty.getId(), false)); // TODO - } + AlterProperty msg = new AlterProperty("BuyHouse"); + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + app.getGameLogic().send(msg); + close(); })); // Center the popup @@ -130,62 +133,71 @@ public class BuyHouse extends Dialog { // Populate the dropdown with property names for (BuildingProperty property : playerProperties) { - propertyOptions.add(property.getName() + " (ID: " + property.getId() + ")"); + propertyOptions.add(property.getName()); } propertySelector = new Selector<>(propertyOptions, "glass"); - dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); dropdownContainer.addChild(propertySelector); - // Set initial selection - if (!propertyOptions.isEmpty()) { - onDropdownSelectionChanged(propertyOptions.get(0), playerProperties); - } - // Track selection changes selectionRef = propertySelector.getSelectionModel().createReference(); + // Initialize the selection display here + 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; } - /** * Retrieves the list of properties owned by the current player. * * @return List of BuildingProperty objects owned by the player. */ private List getPlayerProperties() { - Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); + Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); BoardManager boardManager = app.getGameLogic().getBoardManager(); - return boardManager.getPropertyFields(currentPlayer.getProperties()).stream() + return boardManager.getPropertyFields(self.getProperties()).stream() .filter(property -> property instanceof BuildingProperty) .map(property -> (BuildingProperty) property) + .filter(property -> app.getGameLogic().getBoardManager().canBuild(property)) .collect(Collectors.toList()); } + @Override + public void update(float delta) { + if(selectionRef.update()) { + onDropdownSelectionChanged(propertySelector); + } + } + /** * Handles property selection changes. */ - private void onDropdownSelectionChanged(String selected, List playerProperties) { + private void onDropdownSelectionChanged(Selector playerProperties) { + String selected = playerProperties.getSelectedItem(); app.getGameLogic().playSound(Sound.BUTTON); - - // Extract the ID from the selected string - int idStart = selected.indexOf("(ID: ") + 5; - int idEnd = selected.indexOf(")", idStart); - String idStr = selected.substring(idStart, idEnd); - int propertyId = Integer.parseInt(idStr); - - // Find the selected property - selectedProperty = playerProperties.stream() - .filter(property -> property.getId() == propertyId) - .findFirst() - .orElse(null); - - if (selectedProperty != null) { - System.out.println("Selected property: " + selectedProperty.getName()); + if (selectedProperties.contains(selected)) { + selectedProperties.remove(selected); + } else { + selectedProperties.add(selected); } + + int cost = 0; + for (String s : selectedProperties) { + cost += ((BuildingProperty) app.getGameLogic().getBoardManager().getFieldByName(s)).getHousePrice(); + } + + String display = String.join(" | ", selectedProperties); + selectionDisplay.setText(display); + + this.cost.setText(cost+""); } @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..7a75c0c 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; /** @@ -20,11 +17,11 @@ import pp.monopoly.notification.Sound; */ public class GulagInfo extends Dialog { private final MonopolyApp app; - private final Container confirmTradeContainer; + private final Container gulagInfoContainer; private final Container backgroundContainer; - public GulagInfo(MonopolyApp app) { + public GulagInfo(MonopolyApp app, int trys) { super(app.getDialogManager()); this.app = app; @@ -34,19 +31,19 @@ public class GulagInfo extends Dialog { attachChild(backgroundContainer); // Hauptcontainer für das Bestätigungspopup - confirmTradeContainer = new Container(); + gulagInfoContainer = new Container(); float padding = 10; // Passt den backgroundContainer an die Größe des confirmTradeContainer an - backgroundContainer.setPreferredSize(confirmTradeContainer.getPreferredSize().addLocal(padding, padding, 0)); + backgroundContainer.setPreferredSize(gulagInfoContainer.getPreferredSize().addLocal(padding, padding, 0)); // Titel - Label title = confirmTradeContainer.addChild(new Label( "Gulag", new ElementId("warning-title"))); + Label title = gulagInfoContainer.addChild(new Label( "Gulag", new ElementId("warning-title"))); title.setFontSize(48); title.setColor(ColorRGBA.Black); // Text, der auf der Karte steht // Die Werte werden dem Handel entnommen (Iwas auch immer da dann ist) - Container propertyValuesContainer = confirmTradeContainer.addChild(new Container()); + Container propertyValuesContainer = gulagInfoContainer.addChild(new Container()); propertyValuesContainer.addChild(new Label("„Du sitzt im Gefänginis und kommst nicht raus ...", new ElementId("label-Text"))); propertyValuesContainer.addChild(new Label("Es sei denn, du ...", new ElementId("label-Text")));// Leerzeile propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); @@ -54,52 +51,56 @@ 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))); // Bezahlen-Button - Button negotiateButton = confirmTradeContainer.addChild(new Button("Bestechungsgeld bezahlen", new ElementId("button"))); - negotiateButton.setFontSize(32); - negotiateButton.addClickCommands(s -> ifTopDialog( () -> { + Button payButton = gulagInfoContainer.addChild(new Button("Bestechungsgeld bezahlen", new ElementId("button"))); + payButton.setFontSize(32); + payButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); + app.getGameLogic().send(new NotificationAnswer("PayJail")); close(); })); // Ereigniskarte-Button - Button confirmButton = confirmTradeContainer.addChild(new Button("Ereigniskarte nutzen", new ElementId("button"))); - confirmButton.setFontSize(32); - confirmButton.addClickCommands(s -> ifTopDialog( () -> { + Button eventCardButton = gulagInfoContainer.addChild(new Button("Ereigniskarte nutzen", new ElementId("button"))); + eventCardButton.setFontSize(32); + eventCardButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); + app.getGameLogic().send(new NotificationAnswer("UseJailCard")); close(); })); // Schließen-Button - Button declineButton = confirmTradeContainer.addChild(new Button("Schließen", new ElementId("button"))); - declineButton.setFontSize(32); - declineButton.addClickCommands(s -> ifTopDialog(() -> { + Button closeButton = gulagInfoContainer.addChild(new Button("Schließen", new ElementId("button"))); + closeButton.setFontSize(32); + closeButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); close(); })); // Zentriere das Menü - confirmTradeContainer.setLocalTranslation( - (app.getCamera().getWidth() - confirmTradeContainer.getPreferredSize().x) / 2, - (app.getCamera().getHeight() + confirmTradeContainer.getPreferredSize().y) / 2, + gulagInfoContainer.setLocalTranslation( + (app.getCamera().getWidth() - gulagInfoContainer.getPreferredSize().x) / 2, + (app.getCamera().getHeight() + gulagInfoContainer.getPreferredSize().y) / 2, 8 ); // Zentriere das Menü backgroundContainer.setLocalTranslation( - (app.getCamera().getWidth() - confirmTradeContainer.getPreferredSize().x - padding) / 2, - (app.getCamera().getHeight() + confirmTradeContainer.getPreferredSize().y+ padding) / 2, + (app.getCamera().getWidth() - gulagInfoContainer.getPreferredSize().x - padding) / 2, + (app.getCamera().getHeight() + gulagInfoContainer.getPreferredSize().y+ padding) / 2, 7 ); - app.getGuiNode().attachChild(confirmTradeContainer); + if(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getNumJailCard() == 0) { + eventCardButton.setEnabled(false); + } + + if(trys == 3) { + closeButton.setEnabled(false); + } + + app.getGuiNode().attachChild(gulagInfoContainer); } /** @@ -107,7 +108,7 @@ public class GulagInfo extends Dialog { */ @Override public void close() { - app.getGuiNode().detachChild(confirmTradeContainer); // Entferne das Menü + app.getGuiNode().detachChild(gulagInfoContainer); // Entferne das Menü app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand super.close(); } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java index 2caa095..4cd9c23 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java @@ -13,6 +13,8 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.message.server.TradeReply; +import pp.monopoly.notification.Sound; /** * Bankrupt is a Warning-Popup which appears when the balance is negative at the end of a player´s turn @@ -25,7 +27,7 @@ public class RejectTrade extends Dialog { - public RejectTrade(MonopolyApp app) { + public RejectTrade(MonopolyApp app, TradeReply msg) { super(app.getDialogManager()); this.app = app; @@ -55,7 +57,7 @@ public class RejectTrade extends Dialog { // Text, der im Popup steht Container textContainer = noMoneyWarningContainer.addChild(new Container()); - textContainer.addChild(new Label("Du hast Spieler XXX einen Handel vorgeschlagen", new ElementId("label-Text"))); + textContainer.addChild(new Label("Du hast Spieler"+ msg.getTradeHandler().getReceiver().getName() + "einen Handel vorgeschlagen", new ElementId("label-Text"))); textContainer.addChild(new Label("", new ElementId("label-Text"))); textContainer.addChild(new Label("Der Handel wurde abgelehnt", new ElementId("label-Text"))); textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -66,7 +68,10 @@ public class RejectTrade extends Dialog { // Beenden-Button Button quitButton = noMoneyWarningContainer.addChild(new Button("Bestätigen", new ElementId("button"))); quitButton.setFontSize(32); - quitButton.addClickCommands(source -> close()); + quitButton.addClickCommands(source -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Zentriere das Popup diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java index 9ae5eec..14530f9 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java @@ -83,7 +83,7 @@ public class Rent extends Dialog { container.setPreferredSize(new Vector3f(550, 250, 10)); // Title - Label title = container.addChild(new Label("Miete!", new ElementId("label-Bold"))); + Label title = container.addChild(new Label("Miete!", new ElementId("warning-title"))); title.setFontSize(48); title.setColor(ColorRGBA.Black); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java index 14a9487..ada03c0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java @@ -2,22 +2,29 @@ package pp.monopoly.client.gui.popups; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; +import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; -import com.simsilica.lemur.ListBox; +import com.simsilica.lemur.Selector; +import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.style.ElementId; 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.AlterProperty; import pp.monopoly.model.fields.BoardManager; -import pp.monopoly.model.fields.BuildingProperty; +import pp.monopoly.model.fields.PropertyField; import pp.monopoly.notification.Sound; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -27,6 +34,12 @@ public class RepayMortage extends Dialog { private final MonopolyApp app; private final Container repayMortageContainer; private final Container backgroundContainer; + private TextField selectionDisplay; // TextField to display selections + private VersionedReference> selectionRef; + private Selector propertySelector; + private Set selectedProperties = new HashSet<>(); + + private Label cost = new Label("0", new ElementId("label-Text")); public RepayMortage(MonopolyApp app) { @@ -56,49 +69,18 @@ public class RepayMortage extends Dialog { Container downContainer = repayMortageContainer.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))); middleContainer.setPreferredSize(new Vector3f(100, 150, 0)); middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); - // Create a VersionedList for the ListBox model - VersionedList listModel = new VersionedList<>(); - - // Retrieve current player and their properties //TODO hier Prüfen, ob abweichungen zur SellHouse-Klasse beachtet werden müssen - Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); - BoardManager boardManager = app.getGameLogic().getBoardManager(); - - List playerProperties = boardManager.getPropertyFields( - currentPlayer.getProperties()).stream() - .filter(property -> property instanceof BuildingProperty) - .map(property -> (BuildingProperty) property) - .filter(property -> property.getHouses() > 0 || property.getHotel() == 1) - .collect(Collectors.toList()); - - // Populate the list model - listModel.addAll(playerProperties); - - // Create a ListBox with the "glass" style and the model - ListBox listBox = new ListBox<>(listModel, "glass"); - listBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed - - // Add selection listener - listBox.addClickCommands(item -> { - BuildingProperty selected = listBox.getSelectedItem(); // Correct method to retrieve the selected item - if (selected != null) { - System.out.println("Selected property: " + selected.getName()); - } - }); - - // Add the ListBox to the middle container - middleContainer.addChild(listBox); - + middleContainer.addChild(createPropertyDropdown()); downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile downContainer.addChild(new Label("Kosten:", new ElementId("label-Text")));// Leerzeile - downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text"))); + downContainer.addChild(cost); downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Beenden-Button @@ -113,12 +95,10 @@ public class RepayMortage extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - BuildingProperty selected = listBox.getSelectedItem(); - if (selected != null) { - System.out.println("Confirmed property: " + selected.getName()); - // Send the "alter building" message to the server - //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server - } + AlterProperty msg = new AlterProperty("RepayMortage"); + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + app.getGameLogic().send(msg); + close(); })); // Zentriere das Popup @@ -138,6 +118,88 @@ public class RepayMortage extends Dialog { app.getGuiNode().attachChild(repayMortageContainer); } + /** + * Creates a dropdown menu for selecting a property. + * + * @return The dropdown container. + */ + private Container createPropertyDropdown() { + Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + dropdownContainer.setPreferredSize(new Vector3f(300, 200, 0)); + dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); + + VersionedList propertyOptions = new VersionedList<>(); + List playerProperties = getPlayerProperties(); + + // Populate the dropdown with property names + for (PropertyField property : playerProperties) { + propertyOptions.add(property.getName()); + } + + propertySelector = new Selector<>(propertyOptions, "glass"); + dropdownContainer.addChild(propertySelector); + + // Track selection changes + selectionRef = propertySelector.getSelectionModel().createReference(); + + // Initialize the selection display here + 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; + } + /** + * Retrieves the list of properties owned by the current player. + * + * @return List of PropertyField objects owned by the player. + */ + private List getPlayerProperties() { + Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); + BoardManager boardManager = app.getGameLogic().getBoardManager(); + + return boardManager.getPropertyFields(self.getProperties()).stream() + .filter(property -> property instanceof PropertyField) + .map(property -> (PropertyField) property) + .filter(p -> p.isMortgaged()) + .collect(Collectors.toList()); + } + + @Override + public void update(float delta) { + if(selectionRef.update()) { + onDropdownSelectionChanged(propertySelector); + } + } + + /** + * Handles property selection changes. + */ + private void onDropdownSelectionChanged(Selector playerProperties) { + String selected = playerProperties.getSelectedItem(); + app.getGameLogic().playSound(Sound.BUTTON); + if (selectedProperties.contains(selected)) { + selectedProperties.remove(selected); + } else { + selectedProperties.add(selected); + } + + int cost = 0; + for (String s : selectedProperties) { + cost += ((PropertyField) app.getGameLogic().getBoardManager().getFieldByName(s)).getHypo(); + } + + String display = String.join(" | ", selectedProperties); + selectionDisplay.setText(display); + + this.cost.setText(cost+""); + } + /** * Schließt das Menü und entfernt die GUI-Elemente. */ 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 ed6e7d7..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 @@ -3,25 +3,32 @@ package pp.monopoly.client.gui.popups; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; +import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Checkbox; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; import com.simsilica.lemur.ListBox; +import com.simsilica.lemur.Selector; +import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.IconComponent; import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.style.ElementId; 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; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -31,6 +38,12 @@ public class SellHouse extends Dialog { private final MonopolyApp app; private final Container sellhouseContainer; private final Container backgroundContainer; + private TextField selectionDisplay; // TextField to display selections + private VersionedReference> selectionRef; + private Selector propertySelector; + private Set selectedProperties = new HashSet<>(); + + private Label cost = new Label("0", new ElementId("label-Text")); public SellHouse(MonopolyApp app) { @@ -60,49 +73,18 @@ 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))); middleContainer.setPreferredSize(new Vector3f(100, 150, 0)); middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); - // Create a VersionedList for the ListBox model - VersionedList listModel = new VersionedList<>(); - - // Retrieve current player and their properties - Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); - BoardManager boardManager = app.getGameLogic().getBoardManager(); - - List playerProperties = boardManager.getPropertyFields( - currentPlayer.getProperties()).stream() - .filter(property -> property instanceof BuildingProperty) - .map(property -> (BuildingProperty) property) - .filter(property -> property.getHouses() > 0 || property.getHotel() == 1) - .collect(Collectors.toList()); - - // Populate the list model - listModel.addAll(playerProperties); - - // Create a ListBox with the "glass" style and the model - ListBox listBox = new ListBox<>(listModel, "glass"); - listBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed - - // Add selection listener - listBox.addClickCommands(item -> { - BuildingProperty selected = listBox.getSelectedItem(); // Correct method to retrieve the selected item - if (selected != null) { - System.out.println("Selected property: " + selected.getName()); - } - }); - - // Add the ListBox to the middle container - middleContainer.addChild(listBox); - + middleContainer.addChild(createPropertyDropdown()); downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile downContainer.addChild(new Label("Erstattung:", new ElementId("label-Text")));// Leerzeile - downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text"))); + downContainer.addChild(cost); // Cost details downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Beenden-Button @@ -117,12 +99,16 @@ public class SellHouse extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - BuildingProperty selected = listBox.getSelectedItem(); - if (selected != null) { - System.out.println("Confirmed property: " + selected.getName()); - // 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 @@ -142,6 +128,88 @@ public class SellHouse extends Dialog { app.getGuiNode().attachChild(sellhouseContainer); } + /** + * Creates a dropdown menu for selecting a property. + * + * @return The dropdown container. + */ + private Container createPropertyDropdown() { + Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + dropdownContainer.setPreferredSize(new Vector3f(300, 200, 0)); + dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); + + VersionedList propertyOptions = new VersionedList<>(); + List playerProperties = getPlayerProperties(); + + // Populate the dropdown with property names + for (BuildingProperty property : playerProperties) { + propertyOptions.add(property.getName()); + } + + propertySelector = new Selector<>(propertyOptions, "glass"); + dropdownContainer.addChild(propertySelector); + + // Track selection changes + selectionRef = propertySelector.getSelectionModel().createReference(); + + // Initialize the selection display here + 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; + } + /** + * Retrieves the list of properties owned by the current player. + * + * @return List of BuildingProperty objects owned by the player. + */ + private List getPlayerProperties() { + Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); + BoardManager boardManager = app.getGameLogic().getBoardManager(); + + 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()); + } + + @Override + public void update(float delta) { + if(selectionRef.update()) { + onDropdownSelectionChanged(propertySelector); + } + } + + /** + * Handles property selection changes. + */ + private void onDropdownSelectionChanged(Selector playerProperties) { + String selected = playerProperties.getSelectedItem(); + app.getGameLogic().playSound(Sound.BUTTON); + if (selectedProperties.contains(selected)) { + selectedProperties.remove(selected); + } else { + selectedProperties.add(selected); + } + + int cost = 0; + for (String s : selectedProperties) { + cost += ((BuildingProperty) app.getGameLogic().getBoardManager().getFieldByName(s)).getHousePrice(); + } + + String display = String.join(" | ", selectedProperties); + selectionDisplay.setText(display); + + this.cost.setText(cost+""); + } + /** * Schließt das Menü und entfernt die GUI-Elemente. */ diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java index f2c615a..c53999b 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java @@ -2,22 +2,30 @@ package pp.monopoly.client.gui.popups; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; +import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; -import com.simsilica.lemur.ListBox; +import com.simsilica.lemur.Selector; +import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.style.ElementId; 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.AlterProperty; import pp.monopoly.model.fields.BoardManager; -import pp.monopoly.model.fields.BuildingProperty; +import pp.monopoly.model.fields.PropertyField; +import pp.monopoly.model.fields.PropertyField; import pp.monopoly.notification.Sound; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -27,6 +35,12 @@ public class TakeMortage extends Dialog { private final MonopolyApp app; private final Container takeMortageContainer; private final Container backgroundContainer; + private TextField selectionDisplay; // TextField to display selections + private VersionedReference> selectionRef; + private Selector propertySelector; + private Set selectedProperties = new HashSet<>(); + + private Label cost = new Label("0", new ElementId("label-Text")); public TakeMortage(MonopolyApp app) { @@ -56,49 +70,18 @@ public class TakeMortage extends Dialog { Container downContainer = takeMortageContainer.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))); middleContainer.setPreferredSize(new Vector3f(100, 150, 0)); middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); - // Create a VersionedList for the ListBox model - VersionedList listModel = new VersionedList<>(); - - // Retrieve current player and their properties //TODO hier Prüfen, ob abweichungen zur SellHouse-Klasse beachtet werden müssen - Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); - BoardManager boardManager = app.getGameLogic().getBoardManager(); - - List playerProperties = boardManager.getPropertyFields( - currentPlayer.getProperties()).stream() - .filter(property -> property instanceof BuildingProperty) - .map(property -> (BuildingProperty) property) - .filter(property -> property.getHouses() > 0 || property.getHotel() == 1) - .collect(Collectors.toList()); - - // Populate the list model - listModel.addAll(playerProperties); - - // Create a ListBox with the "glass" style and the model - ListBox listBox = new ListBox<>(listModel, "glass"); - listBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed - - // Add selection listener - listBox.addClickCommands(item -> { - BuildingProperty selected = listBox.getSelectedItem(); // Correct method to retrieve the selected item - if (selected != null) { - System.out.println("Selected property: " + selected.getName()); - } - }); - - // Add the ListBox to the middle container - middleContainer.addChild(listBox); - + middleContainer.addChild(createPropertyDropdown()); downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile downContainer.addChild(new Label("Erstattung:", new ElementId("label-Text")));// Leerzeile - downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text"))); + downContainer.addChild(cost); downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Beenden-Button @@ -113,12 +96,10 @@ public class TakeMortage extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - BuildingProperty selected = listBox.getSelectedItem(); - if (selected != null) { - System.out.println("Confirmed property: " + selected.getName()); - // Send the "alter building" message to the server - //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server - } + AlterProperty msg = new AlterProperty("TakeMortage"); + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + app.getGameLogic().send(msg); + close(); })); // Zentriere das Popup @@ -138,6 +119,88 @@ public class TakeMortage extends Dialog { app.getGuiNode().attachChild(takeMortageContainer); } + /** + * Creates a dropdown menu for selecting a property. + * + * @return The dropdown container. + */ + private Container createPropertyDropdown() { + Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + dropdownContainer.setPreferredSize(new Vector3f(300, 200, 0)); + dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); + + VersionedList propertyOptions = new VersionedList<>(); + List playerProperties = getPlayerProperties(); + + // Populate the dropdown with property names + for (PropertyField property : playerProperties) { + propertyOptions.add(property.getName()); + } + + propertySelector = new Selector<>(propertyOptions, "glass"); + dropdownContainer.addChild(propertySelector); + + // Track selection changes + selectionRef = propertySelector.getSelectionModel().createReference(); + + // Initialize the selection display here + 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; + } + /** + * Retrieves the list of properties owned by the current player. + * + * @return List of PropertyField objects owned by the player. + */ + private List getPlayerProperties() { + Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); + BoardManager boardManager = app.getGameLogic().getBoardManager(); + + return boardManager.getPropertyFields(self.getProperties()).stream() + .filter(property -> property instanceof PropertyField) + .map(property -> (PropertyField) property) + .filter(p -> !p.isMortgaged()) + .collect(Collectors.toList()); + } + + @Override + public void update(float delta) { + if(selectionRef.update()) { + onDropdownSelectionChanged(propertySelector); + } + } + + /** + * Handles property selection changes. + */ + private void onDropdownSelectionChanged(Selector playerProperties) { + String selected = playerProperties.getSelectedItem(); + app.getGameLogic().playSound(Sound.BUTTON); + if (selectedProperties.contains(selected)) { + selectedProperties.remove(selected); + } else { + selectedProperties.add(selected); + } + + int cost = 0; + for (String s : selectedProperties) { + cost += ((PropertyField) app.getGameLogic().getBoardManager().getFieldByName(s)).getHypo(); + } + + String display = String.join(" | ", selectedProperties); + selectionDisplay.setText(display); + + this.cost.setText(cost+""); + } + /** * Schließt das Menü und entfernt die GUI-Elemente. */ diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/WinnerPopUp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/WinnerPopUp.java index 95d31c2..afe1e3e 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/WinnerPopUp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/WinnerPopUp.java @@ -53,7 +53,7 @@ public class WinnerPopUp extends Dialog { backgroundContainer.setPreferredSize(WinnerContainer.getPreferredSize().addLocal(padding, padding, 0)); // Titel - Label winnerTitle = WinnerContainer.addChild(new Label("Herlichen Glückwunsch, du bist der neue Monopoly Champion!", new ElementId("header"))); + Label winnerTitle = WinnerContainer.addChild(new Label("Herzlichen Glückwunsch, du bist der neue Monopoly Champion!", new ElementId("header"))); winnerTitle.setFontSize(25); // winnerTitle.setColor(ColorRGBA.Black); // Create the image container diff --git a/Projekte/monopoly/client/src/main/resources/models/Handyholster/Handyholster.j3o b/Projekte/monopoly/client/src/main/resources/models/Handyholster/Handyholster.j3o deleted file mode 100644 index 0cd2049..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Handyholster/Handyholster.j3o and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Haus/1Haus.j3o b/Projekte/monopoly/client/src/main/resources/models/Haus/1Haus.j3o index 7056998..58cddb8 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Haus/1Haus.j3o and b/Projekte/monopoly/client/src/main/resources/models/Haus/1Haus.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Haus/2Haus.j3o b/Projekte/monopoly/client/src/main/resources/models/Haus/2Haus.j3o index 7d59289..5d9230e 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Haus/2Haus.j3o and b/Projekte/monopoly/client/src/main/resources/models/Haus/2Haus.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Haus/3Haus.j3o b/Projekte/monopoly/client/src/main/resources/models/Haus/3Haus.j3o index df78569..067a047 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Haus/3Haus.j3o and b/Projekte/monopoly/client/src/main/resources/models/Haus/3Haus.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Haus/4Haus.j3o b/Projekte/monopoly/client/src/main/resources/models/Haus/4Haus.j3o index 1a63203..353533b 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Haus/4Haus.j3o and b/Projekte/monopoly/client/src/main/resources/models/Haus/4Haus.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Haus/white-brick-wall_ao.png b/Projekte/monopoly/client/src/main/resources/models/Haus/white-brick-wall_ao.png deleted file mode 100644 index 73095b0..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Haus/white-brick-wall_ao.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Hotel/Hotel.j3o b/Projekte/monopoly/client/src/main/resources/models/Hotel/Hotel.j3o index ffbe354..05023ae 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Hotel/Hotel.j3o and b/Projekte/monopoly/client/src/main/resources/models/Hotel/Hotel.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_metallicRoughness.png b/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_metallicRoughness.png deleted file mode 100644 index de1782a..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_metallicRoughness.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_transmission.png b/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_transmission.png deleted file mode 100644 index b209454..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_transmission.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Gemeinschaftskarten.j3o b/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Gemeinschaftskarten.j3o deleted file mode 100644 index a074a07..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Gemeinschaftskarten.j3o and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ereigniskarten_Deck.j3o b/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ereigniskarten_Deck.j3o new file mode 100644 index 0000000..e72a650 Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ereigniskarten_Deck.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Ereigniskarten.j3o b/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Gemeinschaftskarten_Deck.j3o similarity index 67% rename from Projekte/monopoly/client/src/main/resources/models/Kartendeck/Ereigniskarten.j3o rename to Projekte/monopoly/client/src/main/resources/models/Kartendecks/Gemeinschaftskarten_Deck.j3o index acf8911..d6ccb96 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Ereigniskarten.j3o and b/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Gemeinschaftskarten_Deck.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Rücken_Gemeinschaftskarte.png b/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ruecken_Gemeinschaftskarte.png similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/Kartendeck/Rücken_Gemeinschaftskarte.png rename to Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ruecken_Gemeinschaftskarte.png diff --git a/Projekte/monopoly/client/src/main/resources/models/Kartendeck/Rücken_Karte.png b/Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ruecken_Karte.png similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/Kartendeck/Rücken_Karte.png rename to Projekte/monopoly/client/src/main/resources/models/Kartendecks/Ruecken_Karte.png diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_0.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_0.png deleted file mode 100644 index ad84902..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_0.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_1.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_1.png deleted file mode 100644 index 6fb6267..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_1.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_2.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_2.png deleted file mode 100644 index 1b2edd4..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_2.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_3.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_3.png deleted file mode 100644 index 42d3ee1..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_3.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_4.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_4.png deleted file mode 100644 index c542720..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_4.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_5.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_5.png deleted file mode 100644 index 7766e18..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_5.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_6.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_6.png deleted file mode 100644 index 2a52719..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_6.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_7.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_7.png deleted file mode 100644 index 70dc6a9..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_7.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_8.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_8.png deleted file mode 100644 index aa1714b..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_8.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_9.png b/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_9.png deleted file mode 100644 index 8869e85..0000000 Binary files a/Projekte/monopoly/client/src/main/resources/models/Laptop/gltf_embedded_9.png and /dev/null differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Laptop/Laptop.j3o b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Computer/Computer.j3o similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/Laptop/Laptop.j3o rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Computer/Computer.j3o diff --git a/Projekte/monopoly/client/src/main/resources/models/Flugzeug/Flugzeug.j3o b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Flugzeug/Flugzeug.j3o similarity index 99% rename from Projekte/monopoly/client/src/main/resources/models/Flugzeug/Flugzeug.j3o rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Flugzeug/Flugzeug.j3o index 8e83de3..b673cb5 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Flugzeug/Flugzeug.j3o and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Flugzeug/Flugzeug.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Holster/Holster.j3o b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Holster/Holster.j3o new file mode 100644 index 0000000..133da68 Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Holster/Holster.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Handyholster/black-leather_albedo.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Holster/black-leather_albedo.png similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/Handyholster/black-leather_albedo.png rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Holster/black-leather_albedo.png diff --git a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_baseColor.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Atlas_baseColor.png similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_baseColor.png rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Atlas_baseColor.png diff --git a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_normal.jpeg b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Atlas_normal.jpeg similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/Jägermeister/Atlas_normal.jpeg rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Atlas_normal.jpeg diff --git a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Jagermeister.j3o b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Jaegermeister.j3o similarity index 92% rename from Projekte/monopoly/client/src/main/resources/models/Jägermeister/Jagermeister.j3o rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Jaegermeister.j3o index 79b6673..c545324 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/Jägermeister/Jagermeister.j3o and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Jaegermeister/Jaegermeister.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Katze.j3o b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Katze.j3o new file mode 100644 index 0000000..ee4663e Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Katze.j3o differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Base_Color.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Base_Color.png new file mode 100644 index 0000000..20df310 Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Base_Color.png differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Metallic-Kitty_001_MI_Roughness@channels=B.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Metallic-Kitty_001_MI_Roughness@channels=B.png new file mode 100644 index 0000000..4c8bb13 Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Metallic-Kitty_001_MI_Roughness@channels=B.png differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Metallic-Kitty_001_MI_Roughness@channels=G.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Metallic-Kitty_001_MI_Roughness@channels=G.png new file mode 100644 index 0000000..121958c Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/Kitty_001_MI_Metallic-Kitty_001_MI_Roughness@channels=G.png differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Base_Color.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Base_Color.png new file mode 100644 index 0000000..8d3075d Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Base_Color.png differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Metallic-alb_001_Roughness@channels=B.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Metallic-alb_001_Roughness@channels=B.png new file mode 100644 index 0000000..f2a017c Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Metallic-alb_001_Roughness@channels=B.png differ diff --git a/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Metallic-alb_001_Roughness@channels=G.png b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Metallic-alb_001_Roughness@channels=G.png new file mode 100644 index 0000000..38116ef Binary files /dev/null and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/Katze/alb_001_Metallic-alb_001_Roughness@channels=G.png differ diff --git a/Projekte/monopoly/client/src/main/resources/models/OOP/Durchgefallen.jpg b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/OOP/Durchgefallen.jpg similarity index 100% rename from Projekte/monopoly/client/src/main/resources/models/OOP/Durchgefallen.jpg rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/OOP/Durchgefallen.jpg diff --git a/Projekte/monopoly/client/src/main/resources/models/OOP/OOP.j3o b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/OOP/OOP.j3o similarity index 85% rename from Projekte/monopoly/client/src/main/resources/models/OOP/OOP.j3o rename to Projekte/monopoly/client/src/main/resources/models/Spielfiguren/OOP/OOP.j3o index a2368b9..d82e1a9 100644 Binary files a/Projekte/monopoly/client/src/main/resources/models/OOP/OOP.j3o and b/Projekte/monopoly/client/src/main/resources/models/Spielfiguren/OOP/OOP.j3o differ 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..32725de 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 @@ -307,8 +307,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { public void received(TradeReply msg) { if (msg.isAccepted()) { playSound(Sound.TRADE_ACCEPTED); + notifyListeners(new PopUpEvent("tradepos", msg)); } else { playSound(Sound.TRADE_REJECTED); + notifyListeners(new PopUpEvent("tradeneg", msg)); } } @@ -347,6 +349,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..aa95bee 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(); } /** @@ -357,6 +357,7 @@ public class ServerGameLogic implements ClientInterpreter { private void updateAllPlayers() { for (Player player : playerHandler.getPlayers()) { send(player, new PlayerStatusUpdate(playerHandler)); + send(player, new ViewAssetsResponse(boardManager)); } } @@ -381,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()); @@ -414,10 +420,16 @@ 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(); + } else if(msg.getA().equals("hack")) { + for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { + bp.setOwner(playerHandler.getPlayerById(0)); + playerHandler.getPlayerById(0).addProperty(bp.getId()); + } + playerHandler.getPlayerAtIndex(0).earnMoney(20000); } 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/model/src/main/java/pp/monopoly/model/fields/BoardManager.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java index 5df9080..9ff130d 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java @@ -130,7 +130,7 @@ public class BoardManager { .collect(Collectors.toList()); // Check if the player owns all properties in the color group - if (!groupProperties.stream().allMatch(bp -> bp.getOwner() != null && bp.getOwner().equals(field.getOwner()))) { + if (!groupProperties.stream().allMatch(bp -> bp.getOwner() != null && bp.getOwner().getId() == field.getOwner().getId())) { return false; // The player must own all properties in the color group } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java index 3fc9839..f289e14 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java @@ -10,7 +10,7 @@ import pp.monopoly.game.server.Player; @Serializable public class BuildingProperty extends PropertyField { - private int houses; + private int houses = 2; private final int housePrice; private final FieldColor color; private final int rentFactor1 = 5; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/FieldColor.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/FieldColor.java index 0b14722..2dd476b 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/FieldColor.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/FieldColor.java @@ -1,12 +1,10 @@ package pp.monopoly.model.fields; import com.jme3.math.ColorRGBA; -import com.jme3.network.serializing.Serializable; /** * Enum representing eight distinct colors for properties in the game. */ -// @Serializable public enum FieldColor { BROWN(new ColorRGBA(148 / 255f, 86 / 255f, 57 / 255f, 1)), GREEN(new ColorRGBA(30 / 255f, 179 / 255f, 90 / 255f, 1)), 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); }