From 0b9cbb0f5f9f3aa9a5874aa8b8bab32bdf279374 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Fri, 22 Nov 2024 00:42:07 +0100 Subject: [PATCH] view assets response now send alls properties and fixed which players properties are sent --- .../pp/monopoly/game/server/ServerGameLogic.java | 9 +++++---- .../monopoly/message/client/ViewAssetsRequest.java | 13 +++++++++++++ .../monopoly/message/server/ViewAssetsResponse.java | 9 ++++++++- .../java/pp/monopoly/model/fields/BoardManager.java | 6 +++++- 4 files changed, 31 insertions(+), 6 deletions(-) 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 759cb38..a1f61e8 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 @@ -246,11 +246,12 @@ public class ServerGameLogic implements ClientInterpreter { */ @Override public void received(ViewAssetsRequest msg, int from) { - Player player = playerHandler.getPlayerById(from); - if (player != null) { - LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", player.getName()); + Player sender = playerHandler.getPlayerById(from); + Player player = msg.getPlayer(); + if (sender != null && player != null) { + LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName()); - send(player, new ViewAssetsResponse(player.getProperties(), player.getAccountBalance(), player.getNumJailCard())); + send(sender, new ViewAssetsResponse(boardManager, player.getProperties(), player.getAccountBalance(), player.getNumJailCard())); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java index f78d778..afbdc79 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/ViewAssetsRequest.java @@ -1,12 +1,25 @@ package pp.monopoly.message.client; + +import pp.monopoly.game.server.Player; + /** * Represents a request from a player to view their assets. */ public class ViewAssetsRequest extends ClientMessage{ + private final Player player; + + public ViewAssetsRequest(Player player) { + this.player = player; + } + @Override public void accept(ClientInterpreter interpreter, int from) { interpreter.received(this, from); } + public Player getPlayer() { + return player; + } + } \ No newline at end of file diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java index 9a00833..be75108 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java @@ -2,13 +2,16 @@ package pp.monopoly.message.server; import java.util.List; +import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.PropertyField; + /** * Represents a response containing the player's assets. */ public class ViewAssetsResponse extends ServerMessage{ private final List properties; + private final BoardManager board; private final int accountBalance; private final int jailCards; @@ -18,7 +21,8 @@ public class ViewAssetsResponse extends ServerMessage{ * @param properties a List of PropertyField objects representing the player's properties * @param accountBalance the player's current account balance */ - public ViewAssetsResponse(List properties, int accountBalance, int jailCards) { + public ViewAssetsResponse(BoardManager board, List properties, int accountBalance, int jailCards) { + this.board = board; this.properties = properties; this.accountBalance = accountBalance; this.jailCards = jailCards; @@ -47,4 +51,7 @@ public class ViewAssetsResponse extends ServerMessage{ return jailCards; } + public BoardManager getboard() { + return board; + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java index 769a148..6cf575b 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java @@ -22,7 +22,7 @@ public class BoardManager { * Creates a Monopoly GameBoard * @return the List of Fields in correct Order */ - private static List createBoard() { + private List createBoard() { ArrayList fields = new ArrayList<>(); fields.add(new GoField()); @@ -88,4 +88,8 @@ public class BoardManager { if (board.contains(field)) return field.getId(); else throw new NoSuchElementException(); } + + public List getBoard() { + return board; + } }