added more logic for the server state diagram

This commit is contained in:
Daniel Grigencha
2024-11-17 20:17:19 +01:00
parent 9662e1f684
commit f379a6b638
21 changed files with 374 additions and 16 deletions

View File

@@ -22,8 +22,12 @@ public class Game {
private Map<Color, Integer> playerConnectionID;
private ArrayList<Observer> observers = new ArrayList<>();
private Player startPlayer;
private Boolean gameHasStarted = false;
private Boolean playerHasDisconnected = false;
private Boolean gameIsInterrupted = false;
private Boolean allRanked = false;
private Boolean movablePieces = false;
private static final int AMOUNT_OF_TURBO_CARDS = 16;
private static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12;
@@ -309,6 +313,44 @@ public Boolean playerHasDisconnected() {
return playerHasDisconnected;
}
/**
* This method sets the game interruption state.
*
* @param gameIsInterrupted the new game interruption state
*/
public void setGameIsInterrupted(Boolean gameIsInterrupted) {
this.gameIsInterrupted = gameIsInterrupted;
if (!gameIsInterrupted) notifyObservers();
}
/**
* This method returns whether the game is interrupted.
*
* @return true if the game is interrupted, false otherwise
*/
public Boolean gameIsInterrupted() {
return gameIsInterrupted;
}
/**
* This method returns whether the game is interrupted.
*
* @return true if the game is interrupted, false otherwise
*/
public Boolean getMovablePieces() {
return movablePieces;
}
/**
* This method sets the game interruption state.
*
* @param movablePieces the new game interruption state
*/
public void setMovablePieces(Boolean movablePieces) {
this.movablePieces = movablePieces;
if (!movablePieces) notifyObservers();
}
/**
* This method sets the player has disconnected.
*
@@ -316,9 +358,44 @@ public Boolean playerHasDisconnected() {
*/
public void setPlayerHasDisconnected(Boolean playerHasDisconnected) {
this.playerHasDisconnected = playerHasDisconnected;
if (playerHasDisconnected) {
notifyObservers();
}
if (playerHasDisconnected) notifyObservers();
}
/**
* This method returns whether all players have ranked.
*
* @return true if all players have ranked, false otherwise
*/
public Boolean allRanked() {
return allRanked;
}
/**
* This method sets whether all players have ranked.
*
* @param allRanked the new all ranked state
*/
public void setAllRanked(Boolean allRanked) {
this.allRanked = allRanked;
if (allRanked) notifyObservers();
}
/**
* This method returns the start player.
*
* @return the start player
*/
public Player getStartPlayer() {
return startPlayer;
}
/**
* This method sets the start player.
*
* @param startPlayer the new start player
*/
public void setStartPlayer(Player startPlayer) {
this.startPlayer = startPlayer;
}
/**