add figure when player added

This commit is contained in:
Johannes Schmelz 2024-11-23 16:35:33 +01:00
parent 10e24cf30e
commit b38a34efa5
4 changed files with 13 additions and 3 deletions

View File

@ -63,6 +63,10 @@ public class Player implements FieldVisitor<Void>{
this.handler = handler; this.handler = handler;
} }
public void setFigure(Figure figure) {
this.figure = figure;
}
public PlayerColor getColor() { public PlayerColor getColor() {
switch ((id%6)+1) { switch ((id%6)+1) {
case 1: return PlayerColor.BLUE; case 1: return PlayerColor.BLUE;

View File

@ -19,6 +19,9 @@ import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeReply;
import pp.monopoly.message.server.TradeRequest; import pp.monopoly.message.server.TradeRequest;
import pp.monopoly.message.server.ViewAssetsResponse; import pp.monopoly.message.server.ViewAssetsResponse;
import pp.monopoly.model.Board;
import pp.monopoly.model.Figure;
import pp.monopoly.model.Rotation;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.PropertyField; import pp.monopoly.model.fields.PropertyField;
@ -187,6 +190,8 @@ public class ServerGameLogic implements ClientInterpreter {
if (player != null) { if (player != null) {
player.setName(msg.getName()); player.setName(msg.getName());
player.setFigure(new Figure(1, -10, -10, Rotation.LEFT, msg.getFigure()));
//TODO add figure to the map
playerHandler.setPlayerReady(player, true); playerHandler.setPlayerReady(player, true);
LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName()); LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName());
} }

View File

@ -57,7 +57,6 @@ public class Board {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.eventBroker = eventBroker; this.eventBroker = eventBroker;
addItem(new Figure(5, 5, 5, Rotation.LEFT));
} }
/** /**

View File

@ -8,6 +8,7 @@ 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{
private final String type;
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
@ -19,7 +20,7 @@ public class Figure implements Item{
* at position (0, 0), with a default rotation of RIGHT. * at position (0, 0), with a default rotation of RIGHT.
*/ */
private Figure() { private Figure() {
this(0, 0, 0, Rotation.RIGHT); this(0, 0, 0, Rotation.RIGHT, "cube");
} }
/** /**
@ -30,11 +31,12 @@ public class Figure implements Item{
* @param y the y-coordinate of the Figure's initial position * @param y the y-coordinate of the Figure's initial position
* @param rot the rotation of the Figure * @param rot the rotation of the Figure
*/ */
public Figure(int length, int x, int y, Rotation rot) { public Figure(int length, int x, int y, Rotation rot, String type) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.rot = rot; this.rot = rot;
this.length = length; this.length = length;
this.type = type;
} }
/** /**