diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java index 82c3f25..2c26ff1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java @@ -10,10 +10,18 @@ import com.jme3.scene.shape.Box; import com.jme3.texture.Texture; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.client.gui.popups.BuyCard; import pp.monopoly.client.gui.popups.EventCard; +import pp.monopoly.client.gui.popups.FoodFieldCard; +import pp.monopoly.client.gui.popups.GateFieldCard; +import pp.monopoly.model.fields.BuildingProperty; +import pp.monopoly.model.fields.FoodField; +import pp.monopoly.model.fields.GateField; +import pp.monopoly.model.fields.PropertyField; import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.EventCardEvent; import pp.monopoly.notification.GameEventListener; +import pp.monopoly.notification.PopUpEvent; /** * TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat. @@ -101,4 +109,22 @@ public class TestWorld implements GameEventListener{ public void receivedEvent(EventCardEvent event) { new EventCard(app, event.description()).open(); } + + @Override + public void receivedEvent(PopUpEvent event) { + System.err.println("Trigger ?"); + // if (event.desc() == "BuyCard") { + int field = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID(); + Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field); + + if (fieldObject instanceof BuildingProperty) { + new BuyCard(app).open(); + } else if (fieldObject instanceof GateField){ + new GateFieldCard(app).open(); + } else if (fieldObject instanceof FoodField) { + new FoodFieldCard(app).open(); + } + + // } + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java index d8261a5..4277c27 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java @@ -9,7 +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.message.client.BuyPropertyRequest; +import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.notification.Sound; @@ -64,6 +64,7 @@ public class BuyCard extends Dialog { 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(); })); @@ -72,7 +73,8 @@ public class BuyCard extends Dialog { buyButton.setFontSize(32); buyButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - app.getGameLogic().send(new BuyPropertyRequest()); + close(); + app.getGameLogic().send(new BuyPropertyResponse()); })); float padding = 10; // Padding around the settingsContainer for the background diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/ConfirmTrade.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/ConfirmTrade.java index 3bc6db6..4fd7f14 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/ConfirmTrade.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/ConfirmTrade.java @@ -9,7 +9,6 @@ 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.BuyPropertyRequest; import pp.monopoly.notification.Sound; /** @@ -72,14 +71,12 @@ public class ConfirmTrade extends Dialog { negotiateButton.setFontSize(32); negotiateButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - app.getGameLogic().send(new BuyPropertyRequest()); })); // Kaufen-Button Button confirmButton = confirmTradeContainer.addChild(new Button("Bestätigen", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - app.getGameLogic().send(new BuyPropertyRequest()); })); float padding = 10; // Padding around the settingsContainer for the background diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java index 3d6d801..90e4d24 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java @@ -14,7 +14,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.message.client.BuyPropertyRequest; +import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.model.fields.FoodField; import pp.monopoly.notification.Sound; @@ -83,7 +83,7 @@ public class FoodFieldCard extends Dialog { buyButton.setFontSize(32); buyButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - app.getGameLogic().send(new BuyPropertyRequest()); + app.getGameLogic().send(new BuyPropertyResponse()); })); float padding = 10; // Padding around the settingsContainer for the background diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java index ee4d64c..7eb1eb0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java @@ -13,7 +13,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.message.client.BuyPropertyRequest; +import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.model.fields.GateField; import pp.monopoly.notification.Sound; @@ -78,7 +78,7 @@ public class GateFieldCard extends Dialog { buyButton.setFontSize(32); buyButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - app.getGameLogic().send(new BuyPropertyRequest()); + app.getGameLogic().send(new BuyPropertyResponse()); close(); })); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java index 95b5f5f..49866de 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java @@ -12,7 +12,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.message.client.BuyPropertyRequest; +import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.notification.Sound; /** @@ -76,7 +76,7 @@ public class SellHouse extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - app.getGameLogic().send(new BuyPropertyRequest()); + //TODO })); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index dc9736b..706c525 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -7,6 +7,7 @@ import java.util.List; import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.message.client.ClientMessage; +import pp.monopoly.message.server.BuyPropertyRequest; import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.GameOver; @@ -30,6 +31,7 @@ import pp.monopoly.notification.GameEvent; import pp.monopoly.notification.GameEventBroker; import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.InfoTextEvent; +import pp.monopoly.notification.PopUpEvent; import pp.monopoly.notification.Sound; import pp.monopoly.notification.SoundEvent; import pp.monopoly.notification.UpdatePlayerView; @@ -329,4 +331,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { notifyListeners(new ButtonStatusEvent(true)); setState(new ActiveState(this)); } + + @Override + public void received(BuyPropertyRequest msg) { + notifyListeners(new PopUpEvent()); + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java index 7de65c9..8110e01 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java @@ -13,6 +13,7 @@ import java.util.Random; import com.jme3.network.serializing.Serializable; +import pp.monopoly.message.server.BuyPropertyRequest; import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.NextPlayerTurn; @@ -40,7 +41,7 @@ public class Player implements FieldVisitor{ private String name; private int accountBalance = 15000; private Figure figure; - private List properties = new ArrayList<>(); + private transient List properties = new ArrayList<>(); private int getOutOfJailCard; private int fieldID; private DiceResult rollResult; @@ -162,11 +163,14 @@ public class Player implements FieldVisitor{ */ public int movePos(int position){ fieldID = fieldID+position; + System.out.println("Aktuelle Position" +fieldID); + System.err.println("Würfelergebniss"+ rollResult.calcTotal()); if(fieldID >= 40) { fieldID = fieldID%40; earnMoney(2000); } figure.moveTo(fieldID); + getHandler().getLogic().send(this, new PlayerStatusUpdate(handler)); handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this); return fieldID; } @@ -299,30 +303,41 @@ public class Player implements FieldVisitor{ @Override public Void visit(BuildingProperty field) { - int rent = field.calcRent(); - - field.getOwner().earnMoney(rent); - pay(rent); + if(field.getOwner() == null) { + getHandler().getLogic().send(this, new BuyPropertyRequest()); + } else if (field.getOwner() != this){ + int rent = field.calcRent(); + field.getOwner().earnMoney(rent); + pay(rent); + } return null; } @Override public Void visit(FoodField field) { - int factor = 4; - if (field.getOwner().getNumProp(field) == 2) { - factor = 10; + if(field.getOwner() == null) { + getHandler().getLogic().send(this, new BuyPropertyRequest()); + } else { + int factor = 4; + if (field.getOwner().getNumProp(field) == 2) { + factor = 10; + } + field.getOwner().earnMoney(rollResult.calcTotal()*factor); + pay(rollResult.calcTotal()*factor); } - field.getOwner().earnMoney(rollResult.calcTotal()*factor); - pay(rollResult.calcTotal()*factor); return null; } @Override public Void visit(GateField field) { - int rent = field.calcRent() * field.getOwner().getNumProp(field); + if(field.getOwner() == null) { + getHandler().getLogic().send(this, new BuyPropertyRequest()); + } else { + int rent = field.calcRent() * field.getOwner().getNumProp(field); - field.getOwner().earnMoney(rent); - pay(rent); + field.getOwner().earnMoney(rent); + pay(rent); + } return null; } @@ -375,6 +390,7 @@ public class Player implements FieldVisitor{ */ public int getNumProp(PropertyField field) { int count = 0; + if (properties.isEmpty()) return 0; for (PropertyField propertyField : properties) { if (propertyField.getClass() == field.getClass()) { count++; @@ -476,6 +492,8 @@ public class Player implements FieldVisitor{ public DiceResult rollDice() { List roll = List.of(Dice.rollDice(), Dice.rollDice()); rollResult = new DiceResult(roll.get(0), roll.get(1)); + System.out.println(rollResult.calcTotal()); + move(rollResult.calcTotal()); return rollResult; } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 8b211ba..e628ad1 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -4,7 +4,7 @@ import java.lang.System.Logger; import java.lang.System.Logger.Level; import pp.monopoly.MonopolyConfig; -import pp.monopoly.message.client.BuyPropertyRequest; +import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.ClientInterpreter; import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.PlayerReady; @@ -144,19 +144,14 @@ public class ServerGameLogic implements ClientInterpreter { * @param from the connection ID of the player who sent the request */ @Override - public void received(BuyPropertyRequest msg, int from) { + public void received(BuyPropertyResponse msg, int from) { Player player = playerHandler.getPlayerById(from); - if (player != null && state == ServerState.INGAME) { - PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.move(0)); // Assuming player position for property + if (player != null) { + PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.getFieldID()); // Assuming player position for property - if (property.getOwner() == null && player.getAccountBalance() >= property.getPrice()) { - player.buyProperty(property); - property.setOwner(player); - player.earnMoney(-property.getPrice()); - LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName()); - } else { - LOGGER.log(Level.WARNING, "Player {0} cannot buy property {1}", player.getName(), property.getName()); - } + player.buyProperty(property); + System.out.println("Properties:" +player.getProperties().toString()); + LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName()); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyResponse.java similarity index 82% rename from Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java rename to Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyResponse.java index 44ff29b..6ddc24d 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyResponse.java @@ -6,14 +6,14 @@ import com.jme3.network.serializing.Serializable; * Represents a request from a player to buy a property. */ @Serializable -public class BuyPropertyRequest extends ClientMessage{ +public class BuyPropertyResponse extends ClientMessage{ /** * Constructs a BuyPropertyRequest with the specified property ID. * * @param propertyId the ID of the property to buy */ - public BuyPropertyRequest() {} + public BuyPropertyResponse() {} @Override diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java index cb83ff6..9b266a5 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ClientInterpreter.java @@ -17,7 +17,7 @@ public interface ClientInterpreter { * @param msg the BuyPropertyRequest to be processed * @param from the connection ID from which the message was received */ - void received(BuyPropertyRequest msg, int from); + void received(BuyPropertyResponse msg, int from); /** * Processes a received EndTurn. diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyRequest.java new file mode 100644 index 0000000..b348586 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyRequest.java @@ -0,0 +1,21 @@ +package pp.monopoly.message.server; + +import com.jme3.network.serializing.Serializable; + +@Serializable +public class BuyPropertyRequest extends ServerMessage{ + + public BuyPropertyRequest(){} + + @Override + public void accept(ServerInterpreter interpreter) { + interpreter.received(this); + } + + @Override + public String getInfoTextKey() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'"); + } + +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java index 51529fe..308cfca 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java @@ -89,4 +89,11 @@ public interface ServerInterpreter { * @param msg the NextPlayerTurn message received */ void received(NextPlayerTurn msg); + + /** + * Handles a NextPlayerTurn message received from the server. + * + * @param msg the NextPlayerTurn message received + */ + void received(BuyPropertyRequest msg); } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java index 1ea06ff..8006096 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java @@ -73,4 +73,11 @@ public interface GameEventListener { * @param event the received event */ default void receivedEvent(ButtonStatusEvent event) { /*Do nothing */} + + /** + * Indicates that all buttons in the toolbar should be disabled + * + * @param event the received event + */ + default void receivedEvent(PopUpEvent event) { /*Do nothing */} } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/PopUpEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/PopUpEvent.java new file mode 100644 index 0000000..85febde --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/PopUpEvent.java @@ -0,0 +1,10 @@ +package pp.monopoly.notification; + +public record PopUpEvent() implements GameEvent{ + + @Override + public void notifyListener(GameEventListener listener) { + listener.receivedEvent(this); + } + +} diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index 7674613..49a8171 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -29,7 +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.BuyPropertyRequest; +import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.PlayerReady; @@ -37,6 +37,7 @@ import pp.monopoly.message.client.RollDice; import pp.monopoly.message.client.TradeOffer; import pp.monopoly.message.client.TradeResponse; import pp.monopoly.message.client.ViewAssetsRequest; +import pp.monopoly.message.server.BuyPropertyRequest; import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.GameStart; @@ -120,6 +121,7 @@ public class MonopolyServer implements MessageListener, Connec private void initializeSerializables() { Serializer.registerClass(IntPoint.class); + Serializer.registerClass(BuyPropertyResponse.class); Serializer.registerClass(BuyPropertyRequest.class); Serializer.registerClass(EndTurn.class); Serializer.registerClass(PlayerReady.class); @@ -139,7 +141,7 @@ public class MonopolyServer implements MessageListener, Connec } private void registerListeners() { - myServer.addMessageListener(this, BuyPropertyRequest.class); + myServer.addMessageListener(this, BuyPropertyResponse.class); myServer.addMessageListener(this, EndTurn.class); myServer.addMessageListener(this, PlayerReady.class); myServer.addMessageListener(this, RollDice.class);