From de5c8bf44c3897dba3edee52a9a9d156e8c4007d Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Wed, 4 Dec 2024 02:43:29 +0100 Subject: [PATCH] Updated 'Game' class. Updated the 'Game' class by adding the 'getPlayersAsList' method to it. --- .../model/src/main/java/pp/mdga/game/Game.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java index 9f0cee8f..3752c00f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java @@ -99,7 +99,7 @@ public void updatePlayerActiveState(int id, boolean active) { * If yes it will return true, otherwise false. * * @param color as the color which should be checked if taken as a Color enumeration. - * @return true or false. + * @return true or false. */ public boolean isColorTaken(Color color) { for (Map.Entry entry : this.players.entrySet()) { @@ -152,6 +152,15 @@ public Player getPlayerByColor(Color color) { return null; } + /** + * This method will be used to return all connected players as a list. + * + * @return players as a List of Player objects. + */ + public List getPlayersAsList() { + return new ArrayList<>(this.players.values()); + } + /** * This method will be used to return the id of the active player depending on the activeColor attribute of Game * class. @@ -166,7 +175,7 @@ public int getActivePlayerId() { * This method will be used to return the id of the Player defined by the given color parameter. * * @param color as the color of the player as a Color enumeration. - * @return the id of the player as an Integer. + * @return the id of the player as an Integer. */ public int getPlayerIdByColor(Color color) { for (Map.Entry entry : this.players.entrySet()) { @@ -216,8 +225,8 @@ public boolean areAllReady() { * @return the piece specified by the UUID */ public Piece getPieceThroughUUID(UUID pieceId) { - for (var playerData : board.getPlayerData().values()) { - for (var piece : playerData.getPieces()) { + for (var player : this.getPlayers().values()) { + for (var piece : player.getPieces()) { if (piece.getUuid().equals(pieceId)) { return piece; }