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 28f1f16..11c9697 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 pp.monopoly.message.server.DiceResult; import pp.monopoly.model.FieldVisitor; import pp.monopoly.model.Figure; +import pp.monopoly.model.IntPoint; import pp.monopoly.model.card.DeckHelper; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.EventField; @@ -120,9 +121,11 @@ public class Player implements FieldVisitor{ fieldID = fieldID%40; earnMoney(2000); } + figure.moveTo(fieldID); 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/Figure.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Figure.java index d076acd..573ea38 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Figure.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Figure.java @@ -8,31 +8,10 @@ import static java.lang.Math.max; import static java.lang.Math.min; public class Figure implements Item{ - /** - * Enumeration representing the different statuses a Figure can have during the game. - */ - public enum Status { - /** - * The ship is in its normal state, not being previewed for placement. - */ - NORMAL, - - /** - * The ship is being previewed in a valid position for placement. - */ - VALID_PREVIEW, - - /** - * The ship is being previewed in an invalid position for placement. - */ - INVALID_PREVIEW - } - private final int length; // The length of the Figure private int x; // The x-coordinate of the Figure's position private int y; // The y-coordinate of the Figure's position private Rotation rot; // The rotation of the Figure - private Status status; // The current status of the Figure private final Set damaged = new HashSet<>(); // The set of positions that have been hit on this ship /** @@ -56,7 +35,6 @@ public class Figure implements Item{ this.y = y; this.rot = rot; this.length = length; - this.status = Status.NORMAL; } /** @@ -87,7 +65,7 @@ public class Figure implements Item{ this.x = x; this.y = y; } - + /** * Moves the Figure to the specified position. * @@ -98,21 +76,46 @@ public class Figure implements Item{ } /** - * Returns the current status of the Figure. + * Moves the Figure to the specified coordinates. * - * @return the status of the Figure + * @param x the new x-coordinate of the Figure's position + * @param y the new y-coordinate of the Figure's position */ - public Status getStatus() { - return status; + public void moveTo(int fieldId) { + moveTo(fieldIdToPosition(fieldId)); } - /** - * Sets the status of the Figure. - * - * @param status the new status to be set for the Figure - */ - public void setStatus(Status status) { - this.status = status; + private IntPoint fieldIdToPosition(int fieldId) { + if (fieldId < 0 || fieldId > 39) { + throw new IllegalArgumentException("Invalid fieldId: " + fieldId); + } + + // Determine which edge and position along the edge + if (fieldId <= 9) { + // Bottom edge: From (-10, -10) to (10, -10) + int x = -10 + fieldId * 2; + return new IntPoint(x, -10); + } else if (fieldId <= 19) { + // Right edge: From (10, -10) to (10, 10) + int y = -10 + (fieldId - 10) * 2; + return new IntPoint(10, y); + } else if (fieldId <= 29) { + // Top edge: From (10, 10) to (-10, 10) + int x = 10 - (fieldId - 20) * 2; + return new IntPoint(x, 10); + } else { + // Left edge: From (-10, 10) to (-10, -10) + int y = 10 - (fieldId - 30) * 2; + return new IntPoint(-10, y); + } + } + + private Rotation fieldIdToRotation(int fieldId) { + if (fieldId >= 0 && fieldId <= 10) return Rotation.DOWN; + else if (fieldId <= 20) return Rotation.LEFT; + else if (fieldId <= 30) return Rotation.UP; + else if (fieldId <= 39) return Rotation.RIGHT; + else throw new IllegalArgumentException(); } /**