Compare commits

..

No commits in common. "9164dc6893e98732284f4a8dba98dbf07c71bdec" and "9bf9e8406b4f9e764a8fa8606d220f4194c27ef3" have entirely different histories.

16 changed files with 233 additions and 234 deletions

View File

@ -38,7 +38,18 @@ import static pp.monopoly.Resources.lookup;
import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.client.gui.StartMenu; import pp.monopoly.client.gui.StartMenu;
import pp.monopoly.client.gui.TestWorld; import pp.monopoly.client.gui.TestWorld;
import pp.monopoly.client.gui.popups.*; import pp.monopoly.client.gui.popups.Bankrupt;
import pp.monopoly.client.gui.popups.BuildingPropertyCard;
import pp.monopoly.client.gui.popups.BuyCard;
import pp.monopoly.client.gui.popups.BuyHouse;
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.LooserPopUp;
import pp.monopoly.client.gui.popups.RepayMortage;
import pp.monopoly.client.gui.popups.SellHouse;
import pp.monopoly.client.gui.popups.TakeMortage;
import pp.monopoly.client.gui.popups.TimeOut;
import pp.monopoly.game.client.ClientGameLogic; import pp.monopoly.game.client.ClientGameLogic;
import pp.monopoly.game.client.MonopolyClient; import pp.monopoly.game.client.MonopolyClient;
import pp.monopoly.game.client.ServerConnection; import pp.monopoly.game.client.ServerConnection;
@ -128,6 +139,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
private BuildingPropertyCard buildingProperty; private BuildingPropertyCard buildingProperty;
private FoodFieldCard foodField; private FoodFieldCard foodField;
private GateFieldCard gateField; private GateFieldCard gateField;
private BuyCard buyCard;
private LooserPopUp looserpopup; private LooserPopUp looserpopup;
private Bankrupt bankrupt; private Bankrupt bankrupt;
private TimeOut timeOut; private TimeOut timeOut;
@ -279,7 +291,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
private void handleB(boolean isPressed) { private void handleB(boolean isPressed) {
if (isPressed) { if (isPressed) {
Dialog tmp = new Gulag(this); Dialog tmp = new FoodFieldCard(this);
tmp.open(); tmp.open();
} }
} }

View File

@ -18,11 +18,8 @@ import pp.monopoly.model.fields.FoodField;
import pp.monopoly.model.fields.GateField; import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.PropertyField; import pp.monopoly.model.fields.PropertyField;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* PropertyOverviewMenu is a dialog for displaying the player's properties in the game. * PropertyOverviewMenu is a dialog for displaying the player's properties in the game.
@ -105,7 +102,7 @@ public class PropertyOverviewMenu extends Dialog {
} }
// Iterate through the fetched properties // Iterate through the fetched properties
for (PropertyField property : fields.stream().sorted(Comparator.comparingInt(PropertyField::getId)).collect(Collectors.toList())) { for (PropertyField property : fields) {
if (property instanceof BuildingProperty) { if (property instanceof BuildingProperty) {
BuildingProperty building = (BuildingProperty) property; BuildingProperty building = (BuildingProperty) property;
cards.add(createBuildingCard(building)); cards.add(createBuildingCard(building));
@ -132,20 +129,17 @@ public class PropertyOverviewMenu extends Dialog {
// Add property details // Add property details
Container propertyValuesContainer = card.addChild(new Container()); Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.addChild(new Label("Grundstückswert: " + field.getPrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Grundstückswert: " + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
propertyValuesContainer.addChild(new Label("Miete allein: " + field.getAllRent().get(0)+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Miete allein: " + field.getAllRent().get(0), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 1 Haus: " + field.getAllRent().get(1)+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("- mit 1 Haus: " + field.getAllRent().get(1), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 2 Häuser: " + field.getAllRent().get(2)+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("- mit 2 Häuser: " + field.getAllRent().get(2), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 3 Häuser: " + field.getAllRent().get(3)+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("- mit 3 Häuser: " + field.getAllRent().get(3), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 4 Häuser: " + field.getAllRent().get(4)+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("- mit 4 Häuser: " + field.getAllRent().get(4), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 1 Hotel: " + field.getAllRent().get(5)+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("- mit 1 Hotel: " + field.getAllRent().get(5), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- 1 Haus kostet: " + field.getHousePrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("- 1 Haus kostet: " + field.getHousePrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
Label hypo = new Label("Hypothek: " + field.getHypo()+ " EUR", new ElementId("label-Text")); propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
hypo.setFontSize(14);
if (field.isMortgaged()) hypo.setColor(ColorRGBA.Red);
propertyValuesContainer.addChild(hypo);
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
return card; return card;
@ -168,7 +162,7 @@ public class PropertyOverviewMenu extends Dialog {
// Property Values Section // Property Values Section
Container propertyValuesContainer = card.addChild(new Container()); Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Grey background propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Grey background
propertyValuesContainer.addChild(new Label("Preis: " + field.getPrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Preis: " + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
propertyValuesContainer.addChild(new Label("Wenn man Besitzer der", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Wenn man Besitzer der", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label(field.getName() + " ist, so ist", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label(field.getName() + " ist, so ist", new ElementId("label-Text"))).setFontSize(14);
@ -178,7 +172,7 @@ public class PropertyOverviewMenu extends Dialog {
propertyValuesContainer.addChild(new Label("Restaurants zahlt", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Restaurants zahlt", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("100x Würfelwert.", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("100x Würfelwert.", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: " + field.getHypo()+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Hypothek: " + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
return card; return card;
} }
@ -199,7 +193,7 @@ public class PropertyOverviewMenu extends Dialog {
// Property Values Section // Property Values Section
Container propertyValuesContainer = card.addChild(new Container()); Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.addChild(new Label("Preis: " + field.getPrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Preis: " + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("Miete: 250 EUR", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Miete: 250 EUR", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("Wenn man", new ElementId("label-Text"))).setFontSize(14); propertyValuesContainer.addChild(new Label("Wenn man", new ElementId("label-Text"))).setFontSize(14);

View File

@ -54,7 +54,6 @@ public class StartMenu extends Dialog {
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
startButton.addClickCommands(s -> ifTopDialog(() -> { startButton.addClickCommands(s -> ifTopDialog(() -> {
close();
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
app.connect(); // Perform the connection logic app.connect(); // Perform the connection logic
})); }));

View File

@ -10,7 +10,13 @@ import com.jme3.renderer.ViewPort;
import com.jme3.scene.control.AbstractControl; import com.jme3.scene.control.AbstractControl;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.popups.*; import pp.monopoly.client.gui.popups.BuyCard;
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.LooserPopUp;
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.Player;
import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.BuildingProperty;
@ -275,7 +281,7 @@ public class TestWorld implements GameEventListener {
Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field); Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field);
if (fieldObject instanceof BuildingProperty) { if (fieldObject instanceof BuildingProperty) {
new BuildingPropertyCard(app).open(); new BuyCard(app).open();
} else if (fieldObject instanceof GateField) { } else if (fieldObject instanceof GateField) {
new GateFieldCard(app).open(); new GateFieldCard(app).open();
} else if (fieldObject instanceof FoodField) { } else if (fieldObject instanceof FoodField) {

View File

@ -174,7 +174,7 @@ public class Toolbar extends Dialog implements GameEventListener {
propertyMenuButton.setFontSize(30); propertyMenuButton.setFontSize(30);
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> { propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
new BuildingAdminMenu(app).open(); new PropertyOverviewMenu(app).open();
})); }));
return propertyMenuButton; return propertyMenuButton;
} }

View File

@ -1,7 +1,10 @@
package pp.monopoly.client.gui.popups; package pp.monopoly.client.gui.popups;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.simsilica.lemur.Button; import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.simsilica.lemur.Container; import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.QuadBackgroundComponent;
@ -10,31 +13,33 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
/** /**
* BuildingPropertyCard creates the popup for field information * BuildingPropertyCard creates the popup for field information
*/ */
public class BuildingPropertyCard extends Dialog { public class BuildingPropertyCard extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final Geometry overlayBackground;
private final Container buildingPropertyContainer; private final Container buildingPropertyContainer;
private final Container backgroundContainer; private final Container backgroundContainer;
private int index = 37;
public BuildingPropertyCard(MonopolyApp app) { public BuildingPropertyCard(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
//Generate the corresponding field //Generate the corresponfing field
int index = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID(); BuildingProperty field = (BuildingProperty) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Create the background container // Create the background container
backgroundContainer = new Container(); backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
attachChild(backgroundContainer); app.getGuiNode().attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte // Hauptcontainer für die Gebäudekarte
buildingPropertyContainer = new Container(); buildingPropertyContainer = new Container();
@ -43,9 +48,8 @@ public class BuildingPropertyCard extends Dialog {
float padding = 10; // Passt den backgroundContainer an die Größe des buildingPropertyContainer an float padding = 10; // Passt den backgroundContainer an die Größe des buildingPropertyContainer an
backgroundContainer.setPreferredSize(buildingPropertyContainer.getPreferredSize().addLocal(padding, padding, 0)); backgroundContainer.setPreferredSize(buildingPropertyContainer.getPreferredSize().addLocal(padding, padding, 0));
//Titel
Label settingsTitle = buildingPropertyContainer.addChild(new Label( field.getName(), new ElementId("label-Bold"))); Label settingsTitle = buildingPropertyContainer.addChild(new Label( field.getName(), new ElementId("settings-title")));
settingsTitle.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
settingsTitle.setFontSize(48); settingsTitle.setFontSize(48);
// Text, der auf der Karte steht // Text, der auf der Karte steht
@ -64,23 +68,6 @@ public class BuildingPropertyCard extends Dialog {
propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text"))); propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text")));
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Beenden-Button
Button quitButton = buildingPropertyContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> {
System.err.println("Button does something?");
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button
Button buyButton = buildingPropertyContainer.addChild(new Button("Kaufen", new ElementId("button")));
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
app.getGameLogic().send(new BuyPropertyResponse());
}));
// Zentriere das Popup // Zentriere das Popup
buildingPropertyContainer.setLocalTranslation( buildingPropertyContainer.setLocalTranslation(
(app.getCamera().getWidth() - buildingPropertyContainer.getPreferredSize().x) / 2, (app.getCamera().getWidth() - buildingPropertyContainer.getPreferredSize().x) / 2,
@ -98,6 +85,22 @@ public class BuildingPropertyCard extends Dialog {
app.getGuiNode().attachChild(buildingPropertyContainer); app.getGuiNode().attachChild(buildingPropertyContainer);
} }
/**
* Erstellt einen halbtransparenten Hintergrund für das Menü.
*
* @return Geometrie des Overlays
*/
private Geometry createOverlayBackground() {
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry overlay = new Geometry("Overlay", quad);
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
overlay.setMaterial(material);
overlay.setLocalTranslation(0, 0, 0);
return overlay;
}
/** /**
* Schließt das Menü und entfernt die GUI-Elemente. * Schließt das Menü und entfernt die GUI-Elemente.
*/ */
@ -105,9 +108,14 @@ public class BuildingPropertyCard extends Dialog {
public void close() { public void close() {
app.getGuiNode().detachChild(buildingPropertyContainer); // Entferne das Menü app.getGuiNode().detachChild(buildingPropertyContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
super.close(); super.close();
} }
public void setIndex(int index) {
this.index = index;
}
@Override @Override
public void escape() { public void escape() {
new SettingsMenu(app).open(); new SettingsMenu(app).open();

View File

@ -0,0 +1,115 @@
package pp.monopoly.client.gui.popups;
import com.jme3.math.ColorRGBA;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
/**
* BuyCard is a popup that appears when a player lands on a field that is still available for purchase.
*/
public class BuyCard extends Dialog {
private final MonopolyApp app;
private final Container buyCardContainer;
private final Container backgroundContainer;
public BuyCard(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
//Generate the corresponding field
int index = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID();
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Create the background container
backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte
buyCardContainer = new Container();
buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor())); // Ändert den Rahmen und die Hintergrundfarbe der Karten
float padding = 10; // Passt den backgroundContainer an die Größe des buyCardContainers an
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
// Titel
Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
title.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
title.setFontSize(48);
// Text, der auf dem Popup steht
// Die Preise werden dynamisch dem BoardManager entnommen
Container propertyValuesContainer = buyCardContainer.addChild(new Container());
propertyValuesContainer.addChild(new Label("„Grundstückswert: " + field.getPrice() + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("„Miete allein: " + field.getAllRent().get(0)+ " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("„-mit 1 Haus: " + field.getAllRent().get(1) + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("„-mit 2 Häuser: " + field.getAllRent().get(2) + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("„-mit 3 Häuser: " + field.getAllRent().get(3) + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("„-mit 4 Häuser: " + field.getAllRent().get(4) + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("„-mit 1 Hotel: " + field.getAllRent().get(5) + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("„-1 Haus kostet: " + field.getHousePrice()+ " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text")));
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Beenden-Button
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> {
System.err.println("Button does something?");
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
app.getGameLogic().send(new BuyPropertyResponse());
}));
// Zentriere das Popup
buyCardContainer.setLocalTranslation(
(app.getCamera().getWidth() - buyCardContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + buyCardContainer.getPreferredSize().y) / 2,
10
);
// Zentriere das Popup
backgroundContainer.setLocalTranslation(
(app.getCamera().getWidth() - buyCardContainer.getPreferredSize().x - padding) / 2,
(app.getCamera().getHeight() + buyCardContainer.getPreferredSize().y+ padding) / 2,
9
);
app.getGuiNode().attachChild(buyCardContainer);
}
/**
* Schließt das Menü und entfernt die GUI-Elemente.
*/
@Override
public void close() {
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
super.close();
}
@Override
public void escape() {
new SettingsMenu(app).open();
}
}

View File

@ -42,7 +42,7 @@ public class FoodFieldCard extends Dialog {
// Create the background container // Create the background container
backgroundContainer = new Container(); backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
attachChild(backgroundContainer); app.getGuiNode().attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte // Hauptcontainer für die Gebäudekarte
foodFieldContainer = new Container(); foodFieldContainer = new Container();
@ -52,12 +52,11 @@ public class FoodFieldCard extends Dialog {
backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0)); backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
// Titel, bestehend aus dynamischen Namen anhand der ID und der Schriftfarbe/größe // Titel, bestehend aus dynamischen Namen anhand der ID und der Schriftfarbe/größe
Label settingsTitle = foodFieldContainer.addChild(new Label(field.getName(), new ElementId("label-Bold"))); Label settingsTitle = foodFieldContainer.addChild(new Label(field.getName(), new ElementId("settings-title")));
settingsTitle.setFontSize(48); settingsTitle.setFontSize(48);
settingsTitle.setColor(ColorRGBA.White); settingsTitle.setColor(ColorRGBA.White);
// Text, der auf der Karte steht // Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen
Container propertyValuesContainer = foodFieldContainer.addChild(new Container()); Container propertyValuesContainer = foodFieldContainer.addChild(new Container());
propertyValuesContainer.addChild(new Label("„Preis: " + field.getPrice() + " EUR", new ElementId("label-Text"))); propertyValuesContainer.addChild(new Label("„Preis: " + field.getPrice() + " EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile

View File

@ -22,6 +22,7 @@ import pp.monopoly.notification.Sound;
*/ */
public class GateFieldCard extends Dialog { public class GateFieldCard extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final Geometry overlayBackground;
private final Container gateFieldContainer; private final Container gateFieldContainer;
private final Container backgroundContainer; private final Container backgroundContainer;
@ -33,10 +34,14 @@ public class GateFieldCard extends Dialog {
int index = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID(); int index = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID();
GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index); GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Create the background container // Create the background container
backgroundContainer = new Container(); backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
attachChild(backgroundContainer); app.getGuiNode().attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte // Hauptcontainer für die Gebäudekarte
gateFieldContainer = new Container(); gateFieldContainer = new Container();
@ -46,9 +51,9 @@ public class GateFieldCard extends Dialog {
backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0)); backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
// Titel, bestehend aus dynamischen Namen anhand der ID und der Schriftfarbe/größe // Titel, bestehend aus dynamischen Namen anhand der ID und der Schriftfarbe/größe
Label gateFieldTitle = gateFieldContainer.addChild(new Label(field.getName(), new ElementId("label-Bold"))); Label gateFieldTitle = gateFieldContainer.addChild(new Label(field.getName(), new ElementId("settings-title")));
gateFieldTitle.setFontSize(48); gateFieldTitle.setFontSize(48);
gateFieldTitle.setColor(ColorRGBA.Black); gateFieldTitle.setColor(ColorRGBA.White);
// Text, der auf der Karte steht // Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen // Die Preise werden dynamisch dem BoardManager entnommen
@ -122,6 +127,7 @@ public class GateFieldCard extends Dialog {
public void close() { public void close() {
app.getGuiNode().detachChild(gateFieldContainer); // Entferne das Menü app.getGuiNode().detachChild(gateFieldContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
super.close(); super.close();
} }

View File

@ -15,6 +15,7 @@ import java.util.Set;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.client.WaitForTurnState;
import pp.monopoly.message.server.BuyPropertyRequest; import pp.monopoly.message.server.BuyPropertyRequest;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.EventDrawCard;
@ -148,10 +149,7 @@ public class Player implements FieldVisitor<Void>{
if (state instanceof ActiveState) state = new WaitForTurnState(); if (state instanceof ActiveState) state = new WaitForTurnState();
return true; return true;
} }
else { else return false;
bankrupt();
return false;
}
} }
boolean canFinishTurn() { boolean canFinishTurn() {
@ -498,11 +496,6 @@ public class Player implements FieldVisitor<Void>{
return state.rollDice(); return state.rollDice();
} }
private void bankrupt() {
for (PropertyField field : getPropertyFields()) {
field.setOwner(null);
}
}
/** /**
* A interface representing the PlayerStates * A interface representing the PlayerStates

View File

@ -6,11 +6,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import pp.monopoly.MonopolyConfig; import pp.monopoly.MonopolyConfig;
import pp.monopoly.message.client.AlterProperty;
import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.message.client.ClientInterpreter; import pp.monopoly.message.client.ClientInterpreter;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
@ -31,7 +28,6 @@ import pp.monopoly.model.Rotation;
import pp.monopoly.model.TradeHandler; import pp.monopoly.model.TradeHandler;
import pp.monopoly.model.card.DeckHelper; import pp.monopoly.model.card.DeckHelper;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.PropertyField; import pp.monopoly.model.fields.PropertyField;
/** /**
@ -368,37 +364,4 @@ public class ServerGameLogic implements ClientInterpreter {
public DeckHelper getDeckHelper() { public DeckHelper getDeckHelper() {
return deckHelper; return deckHelper;
} }
@Override
public void received(AlterProperty msg, int from) {
Player sender = playerHandler.getPlayerById(from);
if (msg.getKeyword().equals("TakeMortage")) {
for (PropertyField field : sender.getPropertyFields()) {
field.setMortgaged(true);
sender.earnMoney(field.getHypo());
}
} else if (msg.getKeyword().equals("RepayMortage")) {
for (PropertyField field : sender.getPropertyFields()) {
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())) {
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())) {
if (boardManager.canSell(field)) {
field.sell();
sender.earnMoney(field.getHousePrice());
}
}
}
}
} }

View File

@ -1,36 +0,0 @@
package pp.monopoly.message.client;
import java.util.Set;
import com.jme3.network.serializing.Serializable;
@Serializable
public class AlterProperty extends ClientMessage{
private String keyword;
private Set<Integer> properties;
private AlterProperty() {}
public AlterProperty(String keyword) {
this.keyword = keyword;
}
@Override
public void accept(ClientInterpreter interpreter, int from) {
interpreter.received(this, from);
}
public String getKeyword() {
return keyword;
}
public void setProperties(Set<Integer> properties) {
this.properties = properties;
}
public Set<Integer> getProperties() {
return properties;
}
}

View File

@ -66,12 +66,4 @@ public interface ClientInterpreter {
* @param from the connection ID from which the message was received * @param from the connection ID from which the message was received
*/ */
void received(ViewAssetsRequest msg, int from); void received(ViewAssetsRequest msg, int from);
/**
* Processes a received AlterProperty.
*
* @param msg the AlterProperty to be processed
* @param from the connection ID from which the message was received
*/
void received(AlterProperty msg, int from);
} }

View File

@ -3,8 +3,6 @@ package pp.monopoly.model.fields;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
@ -114,71 +112,4 @@ public class BoardManager {
} }
return properties; return properties;
} }
public boolean canBuild(BuildingProperty field) {
if (field == null) {
return false; // Null check for safety
}
// Get the color group of the property
FieldColor groupColor = field.getColor();
// Get all properties of the same color group
List<BuildingProperty> groupProperties = board.stream()
.filter(f -> f instanceof BuildingProperty)
.map(f -> (BuildingProperty) f)
.filter(bp -> bp.getColor() == groupColor)
.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()))) {
return false; // The player must own all properties in the color group
}
// Ensure balanced building: Check if building levels are balanced within the group
int currentHouses = field.getHouses();
return groupProperties.stream()
.allMatch(bp -> bp.getHouses() >= currentHouses);
}
/**
* Checks if a House can be sold on the given Property
* @param field the Property to check
* @return true if a house can be sold on the property, false otherwise
*/
public boolean canSell(BuildingProperty field) {
if (field == null) {
return false; // Null check for safety
}
// Get the color group of the property
FieldColor groupColor = field.getColor();
// Get all properties of the same color group
List<BuildingProperty> groupProperties = board.stream()
.filter(f -> f instanceof BuildingProperty)
.map(f -> (BuildingProperty) f)
.filter(bp -> bp.getColor() == groupColor)
.collect(Collectors.toList());
// Check if the property has houses or a hotel to sell
if (field.getHouses() == 0 && field.getHotel() == 0) {
return false; // No houses or hotels to sell
}
// Ensure balanced selling: You cannot sell houses unevenly in the group
int currentHouses = field.getHouses();
int currentHotel = field.getHotel();
// If there is a hotel, selling is allowed only if all other properties have max houses
if (currentHotel > 0) {
return groupProperties.stream()
.allMatch(bp -> bp.getHouses() == 4 || bp.equals(field));
}
// If there are houses, check that selling does not unbalance the group
return groupProperties.stream()
.allMatch(bp -> bp.getHouses() <= currentHouses);
}
} }

View File

@ -11,6 +11,7 @@ import pp.monopoly.game.server.Player;
public class BuildingProperty extends PropertyField { public class BuildingProperty extends PropertyField {
private int houses; private int houses;
private boolean hotel = false;
private final int housePrice; private final int housePrice;
private final FieldColor color; private final FieldColor color;
private final int rentFactor1 = 5; private final int rentFactor1 = 5;
@ -33,6 +34,9 @@ public class BuildingProperty extends PropertyField {
@Override @Override
public int calcRent() { public int calcRent() {
if (hotel) {
return (int) Math.round(rent*rentFactorHotel/10)*10;
}
switch (houses) { switch (houses) {
case 1: case 1:
return (int) Math.round(rent*rentFactor1/10)*10; return (int) Math.round(rent*rentFactor1/10)*10;
@ -42,22 +46,29 @@ public class BuildingProperty extends PropertyField {
return (int) Math.round(rent*rentFactor3/10)*10; return (int) Math.round(rent*rentFactor3/10)*10;
case 4: case 4:
return (int) Math.round(rent*rentFactor4/10)*10; return (int) Math.round(rent*rentFactor4/10)*10;
case 5:
return (int) Math.round(rent*rentFactorHotel/10)*10;
default: default:
return rent; return rent;
} }
} }
public boolean build() { public boolean buildHouse() {
if (houses < 5) { if (houses < 4) {
houses++; houses++;
return true; return true;
} }
return false; return false;
} }
public boolean sell() { public boolean buildHotel() {
if (hotel) {
return false;
}
hotel = true;
return true;
}
public boolean removeHouse() {
if (houses == 0) { if (houses == 0) {
return false; return false;
} }
@ -65,6 +76,14 @@ public class BuildingProperty extends PropertyField {
return true; return true;
} }
public boolean removeHotel() {
if (!hotel) {
return false;
}
hotel = false;
return true;
}
@Override @Override
public void accept(Player player) { public void accept(Player player) {
player.visit(this); player.visit(this);
@ -94,6 +113,6 @@ public class BuildingProperty extends PropertyField {
} }
public int getHotel() { public int getHotel() {
return (houses == 5)? 1:0; return hotel ? 1:0;
} }
} }

View File

@ -29,7 +29,6 @@ import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.game.server.ServerGameLogic; import pp.monopoly.game.server.ServerGameLogic;
import pp.monopoly.game.server.ServerSender; import pp.monopoly.game.server.ServerSender;
import pp.monopoly.message.client.AlterProperty;
import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
@ -175,7 +174,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(TradeHandler.class); Serializer.registerClass(TradeHandler.class);
Serializer.registerClass(NotificationMessage.class); Serializer.registerClass(NotificationMessage.class);
Serializer.registerClass(JailEvent.class); Serializer.registerClass(JailEvent.class);
Serializer.registerClass(AlterProperty.class);
} }
private void registerListeners() { private void registerListeners() {