Updated 'Game' class.

Updated the 'Game' class by adding the 'getPlayerIdByColor' method to it.
This commit is contained in:
Daniel Grigencha
2024-12-03 03:36:22 +01:00
parent a012402a85
commit 3353a890d3

View File

@@ -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<Integer, Player> 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.
*