Compare commits

..

2 Commits

Author SHA1 Message Date
Johannes Schmelz
10e24cf30e small bug fixes 2024-11-23 16:16:40 +01:00
Johannes Schmelz
3369057afb update the players figure when moved 2024-11-23 16:08:46 +01:00
5 changed files with 48 additions and 36 deletions

View File

@ -13,6 +13,7 @@ import java.util.Random;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
import pp.monopoly.model.FieldVisitor; import pp.monopoly.model.FieldVisitor;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
import pp.monopoly.model.IntPoint;
import pp.monopoly.model.card.DeckHelper; import pp.monopoly.model.card.DeckHelper;
import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.EventField; import pp.monopoly.model.fields.EventField;
@ -120,9 +121,11 @@ public class Player implements FieldVisitor<Void>{
fieldID = fieldID%40; fieldID = fieldID%40;
earnMoney(2000); earnMoney(2000);
} }
figure.moveTo(fieldID);
return fieldID; return fieldID;
} }
/** /**
* Gets all the properties owned by this player * Gets all the properties owned by this player
* @return List of all properties owned by this player * @return List of all properties owned by this player

View File

@ -8,31 +8,10 @@ import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
public class Figure implements Item{ 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 final int length; // The length of the Figure
private int x; // The x-coordinate of the Figure's position private int x; // The x-coordinate of the Figure's position
private int y; // The y-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 Rotation rot; // The rotation of the Figure
private Status status; // The current status of the Figure
private final Set<IntPoint> damaged = new HashSet<>(); // The set of positions that have been hit on this ship private final Set<IntPoint> 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.y = y;
this.rot = rot; this.rot = rot;
this.length = length; this.length = length;
this.status = Status.NORMAL;
} }
/** /**
@ -87,7 +65,7 @@ public class Figure implements Item{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
/** /**
* Moves the Figure to the specified position. * 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() { public void moveTo(int fieldId) {
return status; moveTo(fieldIdToPosition(fieldId));
} }
/** private IntPoint fieldIdToPosition(int fieldId) {
* Sets the status of the Figure. if (fieldId < 0 || fieldId > 39) {
* throw new IllegalArgumentException("Invalid fieldId: " + fieldId);
* @param status the new status to be set for the Figure }
*/
public void setStatus(Status status) { // Determine which edge and position along the edge
this.status = status; 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();
} }
/** /**

View File

@ -22,7 +22,7 @@ public class BoardManager {
* Creates a Monopoly GameBoard * Creates a Monopoly GameBoard
* @return the List of Fields in correct Order * @return the List of Fields in correct Order
*/ */
private List<Field> createBoard() { public static List<Field> createBoard() {
ArrayList<Field> fields = new ArrayList<>(); ArrayList<Field> fields = new ArrayList<>();
fields.add(new GoField()); fields.add(new GoField());

View File

@ -15,4 +15,8 @@ public class GulagField extends Field{
player.visit(this); player.visit(this);
} }
public int getBailCost() {
return bailCost;
}
} }

View File

@ -19,6 +19,8 @@ public class TestStreckeField extends Field{
} }
public int collectMoney() { public int collectMoney() {
return money = 0; int tmp = money;
money = 0;
return tmp;
} }
} }