Skip to content

Commit

Permalink
Fix withTurnFinished
Browse files Browse the repository at this point in the history
  • Loading branch information
balthaB committed Apr 2, 2024
1 parent a201489 commit d6f2f0d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/ch/epfl/chacun/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public GameState withPlacedTile(PlacedTile placedTile) {
yield normalNextGameState;
}
/*
The hunting trap tile allows the player to gets the points corresponding
The hunting trap tile allows the player to get the points corresponding
to the animals present in the adjacent meadow.
*/
case HUNTING_TRAP_TILE_ID -> {
Expand Down Expand Up @@ -330,12 +330,15 @@ private GameState withTurnFinished() {
}
// Determine the next action : END_GAME if the current player can't play again and if the normal
// tiles deck is empty, PLACE_TILE otherwise
Action nextAction = !canPlayAgain && tileDecks.normalTiles().isEmpty()
? Action.END_GAME
: Action.PLACE_TILE;
Action nextAction = Action.PLACE_TILE;
GameState updatedGameState = new GameState(updatedPlayers, updatedTileDecks,
updatedTileDecks.topTile(nextTileKind), updatedBoard, nextAction, updatedMessageBoard);
// Check if the game has to end
if(!canPlayAgain && tileDecks.normalTiles().isEmpty()) {
updatedGameState = updatedGameState.withFinalPointsCounted();
}
// Return a new game state with updated parameters
return new GameState(updatedPlayers, updatedTileDecks, updatedTileDecks.topTile(nextTileKind),
updatedBoard, nextAction, updatedMessageBoard);
return updatedGameState;
}

/**
Expand Down Expand Up @@ -388,7 +391,7 @@ private GameState withFinalPointsCounted() {
updatedMessageBoard = updatedMessageBoard.withWinners(winners, maxPoints);
// Return a new game state with updated data
return new GameState(this.players, this.tileDecks, this.tileToPlace, updatedBoard,
this.nextAction, updatedMessageBoard);
Action.END_GAME, updatedMessageBoard);
}

/**
Expand Down

0 comments on commit d6f2f0d

Please sign in to comment.