From 6bd1ed6e3a7fc91cfe1f478badcb6dd49266da62 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 1 Dec 2024 16:05:57 +0100 Subject: [PATCH] earnMoney with event card movement --- .../java/pp/monopoly/game/server/Player.java | 18 ++++++++++++++++++ .../pp/monopoly/model/card/DeckHelper.java | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) 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 b6a9710..1b8a4f7 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 @@ -188,6 +188,24 @@ public class Player implements FieldVisitor{ return fieldID; } + /** + * Sets the player to the specified Position on the board + * @param position the position to move to + * @return the new position + */ + public int setPositionWithMoney(int position){ + if(position < 40 && position >= 0) { + if(position < fieldID) { + earnMoney(2000); + } + fieldID = position; + figure.moveTo(fieldID); + handler.getLogic().send(this, new PlayerStatusUpdate(handler)); + handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this); + } + return fieldID; + } + /** * Gets all the properties owned by this player * @return List of all properties owned by this player diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java index fabcce6..7ec2d3e 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java @@ -189,7 +189,7 @@ public class DeckHelper{ } private void spoparty(Player player) { - player.setPosition(14); + player.setPositionWithMoney(14); } private void gulakFrei(Player player) { @@ -197,11 +197,11 @@ public class DeckHelper{ } private void dienstfuehrerschein(Player player) { - player.setPosition(20); + player.setPositionWithMoney(20); } private void pubquiz(Player player) { - player.setPosition(39); + player.setPositionWithMoney(39); } private void namensschildTruppenkueche(Player player) { @@ -221,7 +221,7 @@ public class DeckHelper{ } private void naechstesMonatsgehalt(Player player) { - player.setPosition(0); + player.setPositionWithMoney(0); } private void antretenVerschlafen(Player player) { @@ -237,7 +237,7 @@ public class DeckHelper{ } private void dienstsportGym(Player player) { - player.setPosition(1); + player.setPositionWithMoney(1); } private void schimmelGulak(Player player) { @@ -249,7 +249,7 @@ public class DeckHelper{ } private void jahresabschlussantreten(Player player) { - player.setPosition(17); + player.setPositionWithMoney(17); } private void verkaufenVersicherungen(Player player) {