From 09fda6b1675d36789c6ab598f7e67ef10682ccf2 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Mon, 2 Dec 2024 18:18:04 +0100 Subject: [PATCH] Updated 'Game' class. Updated the 'Game' class by adding the 'isColorTaken' method to it. --- .../model/src/main/java/pp/mdga/game/Game.java | 17 +++++++++++++++++ 1 file changed, 17 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 666f1b8b..69bab269 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 @@ -96,6 +96,23 @@ public void updatePlayerActiveState(int id, boolean active) { this.players.get(id).setActive(active); } + /** + * This method will be used to check if the given color parameter is already taken. + * 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. + */ + public boolean isColorTaken(Color color) { + for (Map.Entry entry : this.players.entrySet()) { + if (entry.getValue().getColor() == color) { + return true; + } + } + + return false; + } + /** * This method will be used to return the player which has the given id parameter. *