[FIX] Ajoute les point, cependant recompose et relance une partie à chaque fois

RepositoryAndroid
Renaud BEURET 1 year ago
parent a9fd6dbe74
commit a093d38820

@ -22,22 +22,22 @@ class KahootViewModel: ViewModel() {
nbPoints = uiState.value.nbPoints, nbPoints = uiState.value.nbPoints,
reponseChoisie = false) reponseChoisie = false)
}, },
uiState.value.duréePartie * 1000 uiState.value.duréePartie
) )
} }
// NOTE : tpsReponse en ms // NOTE : tpsReponse en ms
fun ajouterPoints(tpsReponse: Long) { fun ajouterPoints(tpsReponse: Long) {
Log.d("KahootViewModel","Je reçois une réponse")
val nbPoints: Int = if(uiState.value.reponseChoisie) { if (uiState.value.reponseChoisie) {
(10_000 - tpsReponse).toInt() Log.d("KahootViewModel","Le joueur a déjà répondu")
} else { return
0
} }
val nbPoints: Int = (10_000 - tpsReponse).toInt()
uiState.value = KahootUIState(uiState.value.question, uiState.value = KahootUIState(uiState.value.question,
duréePartie = uiState.value.duréePartie, duréePartie = uiState.value.duréePartie,
nbPoints = uiState.value.nbPoints + nbPoints, nbPoints = uiState.value.nbPoints + nbPoints,
reponseChoisie = false) reponseChoisie = true)
Log.d("KahootViewModel","Le joueur à ${uiState.value.nbPoints}") Log.d("KahootViewModel","Le joueur à ${uiState.value.nbPoints}")
} }
} }
Loading…
Cancel
Save