This commit is contained in:
Luca Puderbach 2024-12-02 04:20:14 +01:00
commit 07fd92c9b2
63 changed files with 503 additions and 266 deletions

View File

@ -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();
}
}

View File

@ -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<Client>, ClientStateListener, ServerConnection {
@ -34,9 +34,9 @@ public class NetworkSupport implements MessageListener<Client>, 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<Client>, ClientStateListe
/**
* Return the client connections Id
*
* @return the client id
*/
public int getId() {
@ -52,9 +53,9 @@ public class NetworkSupport implements MessageListener<Client>, ClientStateListe
}
/**
* Returns the Battleship application instance.
* Returns the Monopoly application instance.
*
* @return Battleship application instance
* @return Monopoly application instance
*/
public MonopolyApp getApp() {
return app;

View File

@ -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

View File

@ -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;

View File

@ -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) {

View File

@ -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<String> buildingSelector, Selector<String> 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(", ");
}
}

View File

@ -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

View File

@ -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<Set<Integer>> selectionRef;
private Selector<String> propertySelector;
private BuildingProperty selectedProperty;
private Set<String> 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<BuildingProperty> 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<BuildingProperty> playerProperties) {
private void onDropdownSelectionChanged(Selector<String> 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

View File

@ -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();
}

View File

@ -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

View File

@ -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);

View File

@ -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<Set<Integer>> selectionRef;
private Selector<String> propertySelector;
private Set<String> 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<BuildingProperty> 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<BuildingProperty> 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<BuildingProperty> 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<String> propertyOptions = new VersionedList<>();
List<PropertyField> 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<PropertyField> 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<String> 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.
*/

View File

@ -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<Set<Integer>> selectionRef;
private Selector<String> propertySelector;
private Set<String> 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<BuildingProperty> listModel = new VersionedList<>();
// Retrieve current player and their properties
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
BoardManager boardManager = app.getGameLogic().getBoardManager();
List<BuildingProperty> 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<BuildingProperty> 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<String> propertyOptions = new VersionedList<>();
List<BuildingProperty> 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<BuildingProperty> 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<String> 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.
*/

View File

@ -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<Set<Integer>> selectionRef;
private Selector<String> propertySelector;
private Set<String> 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<BuildingProperty> 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<BuildingProperty> 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<BuildingProperty> 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<String> propertyOptions = new VersionedList<>();
List<PropertyField> 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<PropertyField> 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<String> 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.
*/

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 518 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -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));
}
}
}

View File

@ -140,6 +140,9 @@ public class Player implements FieldVisitor<Void>{
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<Void>{
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<Void>{
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<Void>{
*/
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<Void>{
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;

View File

@ -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<PropertyField> 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();

View File

@ -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

View File

@ -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
}

View File

@ -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;

View File

@ -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)),

View File

@ -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<HostedConnection>, 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<HostedConnection>, 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);
}