Updated 'Game' class.

Updated the 'Game' class by removing the 'allReady' attribute in it. In Addtion, the 'areAllReady' method was added.
This commit is contained in:
Daniel Grigencha
2024-12-02 20:19:13 +01:00
parent 44f893ccef
commit c4304ae99a

View File

@@ -48,9 +48,6 @@ public class Game {
// The color of the active player.
private Color activeColor;
// A flag indicating whether all players are ready.
private boolean allReady = false;
/**
* This constructor creates a new Game object.
*/
@@ -114,6 +111,21 @@ public boolean isColorTaken(Color color) {
return false;
}
/**
* This method will be used to return the first unused color if possible.
*
* @return color as a Color enumeration.
*/
public Color getFirstUnusedColor() {
for (Color color : Color.values()) {
if (!isColorTaken(color)) {
return color;
}
}
return null;
}
/**
* This method will be used to return the player which has the given id parameter.
*
@@ -156,6 +168,22 @@ public int getNumberOfActivePlayers() {
return activePlayers;
}
/**
* This method will be used to check if all players are ready.
* If yes it will return true, otherwise false.
*
* @return true or false.
*/
public boolean areAllReady() {
for (Map.Entry<Integer, Player> entry : this.players.entrySet()) {
if (!entry.getValue().isReady()) {
return false;
}
}
return true;
}
/**
* This method will be used to return a piece based on the UUID.
*
@@ -351,22 +379,4 @@ public void setDie(Die die) {
public void setHost(int host) {
this.host = host;
}
/**
* This method returns the all ready state.
*
* @return the already state
*/
public Boolean allReady() {
return allReady;
}
/**
* This method sets the all ready state.
*
* @param allReady the new all-ready state
*/
public void setAllReady(Boolean allReady) {
this.allReady = allReady;
}
}