Skip to content

Commit

Permalink
fix crash on the first turn of a new game
Browse files Browse the repository at this point in the history
happened when the previous game had a winner (indicated by a popup about giving up), then playing another turn, exiting the game to the main menu, and starting a new game in which the player is not the first to do their turn

closes #40
  • Loading branch information
Sesu8642 committed Mar 8, 2023
1 parent fccb7d4 commit a7b10fc
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -165,8 +165,7 @@ void handleUnconfirmedRetryGame() {
}

private void resetGame() {
cachedGameState = null;
winnerBeforeBotTurn = null;
clearCache();
eventBus.post(new GameExitedEvent());
eventBus.post(new RegenerateMapEvent(parameterInputStage.getBotIntelligence(),
new MapParameters(parameterInputStage.getSeedParam(),
Expand All @@ -175,9 +174,15 @@ private void resetGame() {
activateStage(IngameStages.PARAMETERS);
}

private void clearCache() {
cachedGameState = null;
winnerBeforeBotTurn = null;
}

/** Displays a warning about lost progress and exits the game if confirmed. */
public void handleExitGameAttempt() {
Dialog confirmDialog = dialogFactory.createConfirmDialog("Your progress will be lost. Are you sure?\n", () -> {
clearCache();
eventBus.post(new GameExitedEvent());
eventBus.post(new ScreenTransitionTriggerEvent(ScreenTransitionTarget.MAIN_MENU_SCREEN));
});
Expand Down Expand Up @@ -300,6 +305,7 @@ private void showGiveUpGameMessage(boolean win, Color winningPlayerColor) {
switch ((byte) result) {
case 1:
// exit button
clearCache();
eventBus.post(new GameExitedEvent());
eventBus.post(new ScreenTransitionTriggerEvent(ScreenTransitionTarget.MAIN_MENU_SCREEN));
break;
Expand Down Expand Up @@ -388,7 +394,6 @@ public void render(float delta) {
while (!uiChangeActions.isEmpty()) {
Runnable action = uiChangeActions.poll();
action.run();

}
getViewport().apply();
mapRenderer.render();
Expand Down

0 comments on commit a7b10fc

Please sign in to comment.