From 3353a890d353c31a3ad1156f68b9fa971345d6b1 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Tue, 3 Dec 2024 03:36:22 +0100 Subject: [PATCH] Updated 'Game' class. Updated the 'Game' class by adding the 'getPlayerIdByColor' method to it. --- .../model/src/main/java/pp/mdga/game/Game.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 515aa1da..199f2481 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 @@ -152,6 +152,22 @@ public Player getPlayerByColor(Color color) { return null; } + /** + * 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. + */ + public int getPlayerIdByColor(Color color) { + for (Map.Entry entry : this.players.entrySet()) { + if (entry.getValue().getColor() == color) { + return entry.getKey(); + } + } + + return -1; + } + /** * This method will be used to return the number of active players of this game. *