FiX: Score is not updated for the last word

Issue link: https://github.com/google-developer-training/android-kotlin-fundamentals-apps/pull/19
This commit is contained in:
Jhansi 2020-01-16 15:36:46 -08:00
parent b3ed6a4ecf
commit 0510d8a860
4 changed files with 8 additions and 24 deletions

View File

@ -94,15 +94,11 @@ class GameViewModel : ViewModel() {
/** Methods for updating the UI **/ /** Methods for updating the UI **/
fun onSkip() { fun onSkip() {
if (!wordList.isEmpty()) {
_score.value = (_score.value)?.minus(1) _score.value = (_score.value)?.minus(1)
}
nextWord() nextWord()
} }
fun onCorrect() { fun onCorrect() {
if (!wordList.isEmpty()) {
_score.value = (_score.value)?.plus(1) _score.value = (_score.value)?.plus(1)
}
nextWord() nextWord()
} }

View File

@ -94,15 +94,11 @@ class GameViewModel : ViewModel() {
/** Methods for updating the UI **/ /** Methods for updating the UI **/
fun onSkip() { fun onSkip() {
if (!wordList.isEmpty()) {
_score.value = (_score.value)?.minus(1) _score.value = (_score.value)?.minus(1)
}
nextWord() nextWord()
} }
fun onCorrect() { fun onCorrect() {
if (!wordList.isEmpty()) {
_score.value = (_score.value)?.plus(1) _score.value = (_score.value)?.plus(1)
}
nextWord() nextWord()
} }

View File

@ -138,15 +138,11 @@ class GameViewModel : ViewModel() {
/** Methods for updating the UI **/ /** Methods for updating the UI **/
fun onSkip() { fun onSkip() {
if (!wordList.isEmpty()) {
_score.value = (_score.value)?.minus(1) _score.value = (_score.value)?.minus(1)
}
nextWord() nextWord()
} }
fun onCorrect() { fun onCorrect() {
if (!wordList.isEmpty()) {
_score.value = (_score.value)?.plus(1) _score.value = (_score.value)?.plus(1)
}
nextWord() nextWord()
} }

View File

@ -80,15 +80,11 @@ class GameViewModel : ViewModel() {
/** Methods for updating the UI **/ /** Methods for updating the UI **/
fun onSkip() { fun onSkip() {
if (!wordList.isEmpty()) {
score-- score--
}
nextWord() nextWord()
} }
fun onCorrect() { fun onCorrect() {
if (!wordList.isEmpty()) {
score++ score++
}
nextWord() nextWord()
} }