mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-04-12 04:21:08 +02:00
Compare commits
4 Commits
9bf9e8406b
...
9164dc6893
Author | SHA1 | Date | |
---|---|---|---|
|
9164dc6893 | ||
|
d3cf36ecb1 | ||
|
7d0a0123e0 | ||
|
2f025e2e1a |
@ -38,18 +38,7 @@ import static pp.monopoly.Resources.lookup;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.client.gui.StartMenu;
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
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.client.gui.popups.*;
|
||||
import pp.monopoly.game.client.ClientGameLogic;
|
||||
import pp.monopoly.game.client.MonopolyClient;
|
||||
import pp.monopoly.game.client.ServerConnection;
|
||||
@ -139,7 +128,6 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
private BuildingPropertyCard buildingProperty;
|
||||
private FoodFieldCard foodField;
|
||||
private GateFieldCard gateField;
|
||||
private BuyCard buyCard;
|
||||
private LooserPopUp looserpopup;
|
||||
private Bankrupt bankrupt;
|
||||
private TimeOut timeOut;
|
||||
@ -291,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 FoodFieldCard(this);
|
||||
Dialog tmp = new Gulag(this);
|
||||
tmp.open();
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,11 @@ import pp.monopoly.model.fields.FoodField;
|
||||
import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* PropertyOverviewMenu is a dialog for displaying the player's properties in the game.
|
||||
@ -102,7 +105,7 @@ public class PropertyOverviewMenu extends Dialog {
|
||||
}
|
||||
|
||||
// Iterate through the fetched properties
|
||||
for (PropertyField property : fields) {
|
||||
for (PropertyField property : fields.stream().sorted(Comparator.comparingInt(PropertyField::getId)).collect(Collectors.toList())) {
|
||||
if (property instanceof BuildingProperty) {
|
||||
BuildingProperty building = (BuildingProperty) property;
|
||||
cards.add(createBuildingCard(building));
|
||||
@ -129,17 +132,20 @@ public class PropertyOverviewMenu extends Dialog {
|
||||
|
||||
// Add property details
|
||||
Container propertyValuesContainer = card.addChild(new Container());
|
||||
propertyValuesContainer.addChild(new Label("Grundstückswert: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
|
||||
propertyValuesContainer.addChild(new Label("Grundstückswert: " + field.getPrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14);
|
||||
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
|
||||
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), 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), 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), 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("Miete allein: " + field.getAllRent().get(0)+ " EUR", 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 2 Häuser: " + field.getAllRent().get(2)+ " EUR", 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 4 Häuser: " + field.getAllRent().get(4)+ " EUR", 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("- 1 Haus kostet: " + field.getHousePrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14);
|
||||
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
|
||||
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
|
||||
Label hypo = new Label("Hypothek: " + field.getHypo()+ " EUR", new ElementId("label-Text"));
|
||||
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)));
|
||||
|
||||
return card;
|
||||
@ -162,7 +168,7 @@ public class PropertyOverviewMenu extends Dialog {
|
||||
// Property Values Section
|
||||
Container propertyValuesContainer = card.addChild(new Container());
|
||||
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Grey background
|
||||
propertyValuesContainer.addChild(new Label("Preis: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
|
||||
propertyValuesContainer.addChild(new Label("Preis: " + field.getPrice()+ " EUR", new ElementId("label-Text"))).setFontSize(14);
|
||||
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(field.getName() + " ist, so ist", new ElementId("label-Text"))).setFontSize(14);
|
||||
@ -172,7 +178,7 @@ public class PropertyOverviewMenu extends Dialog {
|
||||
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("", new ElementId("label-Text"))).setFontSize(14); // Leerzeile
|
||||
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
|
||||
propertyValuesContainer.addChild(new Label("Hypothek: " + field.getHypo()+ " EUR", new ElementId("label-Text"))).setFontSize(14);
|
||||
|
||||
return card;
|
||||
}
|
||||
@ -193,7 +199,7 @@ public class PropertyOverviewMenu extends Dialog {
|
||||
|
||||
// Property Values Section
|
||||
Container propertyValuesContainer = card.addChild(new Container());
|
||||
propertyValuesContainer.addChild(new Label("Preis: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
|
||||
propertyValuesContainer.addChild(new Label("Preis: " + field.getPrice()+ " EUR", 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("Wenn man", new ElementId("label-Text"))).setFontSize(14);
|
||||
|
@ -54,6 +54,7 @@ public class StartMenu extends Dialog {
|
||||
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
|
||||
|
||||
startButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
close();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.connect(); // Perform the connection logic
|
||||
}));
|
||||
|
@ -10,13 +10,7 @@ import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
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.client.gui.popups.*;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
@ -281,7 +275,7 @@ public class TestWorld implements GameEventListener {
|
||||
Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field);
|
||||
|
||||
if (fieldObject instanceof BuildingProperty) {
|
||||
new BuyCard(app).open();
|
||||
new BuildingPropertyCard(app).open();
|
||||
} else if (fieldObject instanceof GateField) {
|
||||
new GateFieldCard(app).open();
|
||||
} else if (fieldObject instanceof FoodField) {
|
||||
|
@ -174,7 +174,7 @@ public class Toolbar extends Dialog implements GameEventListener {
|
||||
propertyMenuButton.setFontSize(30);
|
||||
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
new PropertyOverviewMenu(app).open();
|
||||
new BuildingAdminMenu(app).open();
|
||||
}));
|
||||
return propertyMenuButton;
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
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.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
@ -13,33 +10,31 @@ 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;
|
||||
|
||||
/**
|
||||
* BuildingPropertyCard creates the popup for field information
|
||||
*/
|
||||
public class BuildingPropertyCard extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Geometry overlayBackground;
|
||||
private final Container buildingPropertyContainer;
|
||||
private final Container backgroundContainer;
|
||||
private int index = 37;
|
||||
|
||||
public BuildingPropertyCard(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
//Generate the corresponfing field
|
||||
BuildingProperty field = (BuildingProperty) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
//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
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
attachChild(backgroundContainer);
|
||||
|
||||
// Hauptcontainer für die Gebäudekarte
|
||||
buildingPropertyContainer = new Container();
|
||||
@ -48,8 +43,9 @@ public class BuildingPropertyCard extends Dialog {
|
||||
float padding = 10; // Passt den backgroundContainer an die Größe des buildingPropertyContainer an
|
||||
backgroundContainer.setPreferredSize(buildingPropertyContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
|
||||
Label settingsTitle = buildingPropertyContainer.addChild(new Label( field.getName(), new ElementId("settings-title")));
|
||||
//Titel
|
||||
Label settingsTitle = buildingPropertyContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
|
||||
settingsTitle.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
|
||||
settingsTitle.setFontSize(48);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
@ -68,6 +64,23 @@ public class BuildingPropertyCard extends Dialog {
|
||||
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 = 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
|
||||
buildingPropertyContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - buildingPropertyContainer.getPreferredSize().x) / 2,
|
||||
@ -85,22 +98,6 @@ public class BuildingPropertyCard extends Dialog {
|
||||
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.
|
||||
*/
|
||||
@ -108,16 +105,11 @@ public class BuildingPropertyCard extends Dialog {
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(buildingPropertyContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
super.close();
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ public class FoodFieldCard extends Dialog {
|
||||
// Create the background container
|
||||
backgroundContainer = new Container();
|
||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
attachChild(backgroundContainer);
|
||||
|
||||
// Hauptcontainer für die Gebäudekarte
|
||||
foodFieldContainer = new Container();
|
||||
@ -52,11 +52,12 @@ public class FoodFieldCard extends Dialog {
|
||||
backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
// Titel, bestehend aus dynamischen Namen anhand der ID und der Schriftfarbe/größe
|
||||
Label settingsTitle = foodFieldContainer.addChild(new Label(field.getName(), new ElementId("settings-title")));
|
||||
Label settingsTitle = foodFieldContainer.addChild(new Label(field.getName(), new ElementId("label-Bold")));
|
||||
settingsTitle.setFontSize(48);
|
||||
settingsTitle.setColor(ColorRGBA.White);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||
Container propertyValuesContainer = foodFieldContainer.addChild(new Container());
|
||||
propertyValuesContainer.addChild(new Label("„Preis: " + field.getPrice() + " EUR", new ElementId("label-Text")));
|
||||
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
|
||||
|
@ -22,7 +22,6 @@ import pp.monopoly.notification.Sound;
|
||||
*/
|
||||
public class GateFieldCard extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Geometry overlayBackground;
|
||||
private final Container gateFieldContainer;
|
||||
private final Container backgroundContainer;
|
||||
|
||||
@ -34,14 +33,10 @@ public class GateFieldCard extends Dialog {
|
||||
int index = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID();
|
||||
GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
|
||||
// Create the background container
|
||||
backgroundContainer = new Container();
|
||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
attachChild(backgroundContainer);
|
||||
|
||||
// Hauptcontainer für die Gebäudekarte
|
||||
gateFieldContainer = new Container();
|
||||
@ -51,9 +46,9 @@ public class GateFieldCard extends Dialog {
|
||||
backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
// Titel, bestehend aus dynamischen Namen anhand der ID und der Schriftfarbe/größe
|
||||
Label gateFieldTitle = gateFieldContainer.addChild(new Label(field.getName(), new ElementId("settings-title")));
|
||||
Label gateFieldTitle = gateFieldContainer.addChild(new Label(field.getName(), new ElementId("label-Bold")));
|
||||
gateFieldTitle.setFontSize(48);
|
||||
gateFieldTitle.setColor(ColorRGBA.White);
|
||||
gateFieldTitle.setColor(ColorRGBA.Black);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||
@ -89,9 +84,9 @@ public class GateFieldCard extends Dialog {
|
||||
|
||||
// Zentriere das Popup
|
||||
gateFieldContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - gateFieldContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + gateFieldContainer.getPreferredSize().y) / 2,
|
||||
8
|
||||
(app.getCamera().getWidth() - gateFieldContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + gateFieldContainer.getPreferredSize().y) / 2,
|
||||
8
|
||||
);
|
||||
|
||||
// Zentriere das Popup
|
||||
@ -127,7 +122,6 @@ public class GateFieldCard extends Dialog {
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(gateFieldContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.client.WaitForTurnState;
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
@ -149,7 +148,10 @@ public class Player implements FieldVisitor<Void>{
|
||||
if (state instanceof ActiveState) state = new WaitForTurnState();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
else {
|
||||
bankrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean canFinishTurn() {
|
||||
@ -496,7 +498,12 @@ public class Player implements FieldVisitor<Void>{
|
||||
return state.rollDice();
|
||||
}
|
||||
|
||||
|
||||
private void bankrupt() {
|
||||
for (PropertyField field : getPropertyFields()) {
|
||||
field.setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A interface representing the PlayerStates
|
||||
*/
|
||||
|
@ -6,8 +6,11 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.AlterProperty;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
@ -28,6 +31,7 @@ import pp.monopoly.model.Rotation;
|
||||
import pp.monopoly.model.TradeHandler;
|
||||
import pp.monopoly.model.card.DeckHelper;
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
/**
|
||||
@ -364,4 +368,37 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public DeckHelper getDeckHelper() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -66,4 +66,12 @@ public interface ClientInterpreter {
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package pp.monopoly.model.fields;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@ -112,4 +114,71 @@ public class BoardManager {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import pp.monopoly.game.server.Player;
|
||||
public class BuildingProperty extends PropertyField {
|
||||
|
||||
private int houses;
|
||||
private boolean hotel = false;
|
||||
private final int housePrice;
|
||||
private final FieldColor color;
|
||||
private final int rentFactor1 = 5;
|
||||
@ -34,41 +33,31 @@ public class BuildingProperty extends PropertyField {
|
||||
|
||||
@Override
|
||||
public int calcRent() {
|
||||
if (hotel) {
|
||||
return (int) Math.round(rent*rentFactorHotel/10)*10;
|
||||
}
|
||||
switch (houses) {
|
||||
case 1:
|
||||
return (int) Math.round(rent*rentFactor1/10)*10;
|
||||
return (int) Math.round(rent*rentFactor1/10)*10;
|
||||
case 2:
|
||||
return (int) Math.round(rent*rentFactor2/10)*10;
|
||||
return (int) Math.round(rent*rentFactor2/10)*10;
|
||||
case 3:
|
||||
return (int) Math.round(rent*rentFactor3/10)*10;
|
||||
return (int) Math.round(rent*rentFactor3/10)*10;
|
||||
case 4:
|
||||
return (int) Math.round(rent*rentFactor4/10)*10;
|
||||
|
||||
case 5:
|
||||
return (int) Math.round(rent*rentFactorHotel/10)*10;
|
||||
default:
|
||||
return rent;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean buildHouse() {
|
||||
if (houses < 4) {
|
||||
public boolean build() {
|
||||
if (houses < 5) {
|
||||
houses++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean buildHotel() {
|
||||
if (hotel) {
|
||||
return false;
|
||||
}
|
||||
hotel = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeHouse() {
|
||||
public boolean sell() {
|
||||
if (houses == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -76,14 +65,6 @@ public class BuildingProperty extends PropertyField {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeHotel() {
|
||||
if (!hotel) {
|
||||
return false;
|
||||
}
|
||||
hotel = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Player player) {
|
||||
player.visit(this);
|
||||
@ -113,6 +94,6 @@ public class BuildingProperty extends PropertyField {
|
||||
}
|
||||
|
||||
public int getHotel() {
|
||||
return hotel ? 1:0;
|
||||
return (houses == 5)? 1:0;
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.game.server.ServerGameLogic;
|
||||
import pp.monopoly.game.server.ServerSender;
|
||||
import pp.monopoly.message.client.AlterProperty;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
@ -174,6 +175,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(TradeHandler.class);
|
||||
Serializer.registerClass(NotificationMessage.class);
|
||||
Serializer.registerClass(JailEvent.class);
|
||||
Serializer.registerClass(AlterProperty.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
Loading…
Reference in New Issue
Block a user