From 1d3e013d901319d18f6d9d846aee3bc613bc4a3a Mon Sep 17 00:00:00 2001 From: Manas Malla Date: Sat, 21 Jan 2023 13:42:43 +0530 Subject: [PATCH] Fixing Update Logic On validating the last question, when we don't pick a new question, don't increment the currentWordCount and when initializing the ViewModel and setting up the first question, increment the currentWordCount as 1. Then the test cases given in the codelab work out of the box --- .../java/com/example/android/unscramble/ui/GameViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/android/unscramble/ui/GameViewModel.kt b/app/src/main/java/com/example/android/unscramble/ui/GameViewModel.kt index 6417297..2163941 100644 --- a/app/src/main/java/com/example/android/unscramble/ui/GameViewModel.kt +++ b/app/src/main/java/com/example/android/unscramble/ui/GameViewModel.kt @@ -53,7 +53,7 @@ class GameViewModel : ViewModel() { */ fun resetGame() { usedWords.clear() - _uiState.value = GameUiState(currentScrambledWord = pickRandomWordAndShuffle()) + _uiState.value = GameUiState(currentScrambledWord = pickRandomWordAndShuffle(), currentWordCount = 1) } /* @@ -102,7 +102,6 @@ class GameViewModel : ViewModel() { _uiState.update { currentState -> currentState.copy( isGuessedWordWrong = false, - currentWordCount = currentState.currentWordCount.inc(), score = updatedScore, isGameOver = true )