|
|
|
@ -5,8 +5,7 @@ import androidx.lifecycle.ViewModel
|
|
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
|
|
import fr.iut.sciencequest.ViewModels.UiStates.PenduUIState
|
|
|
|
|
import fr.iut.sciencequest.model.buisness.Scientifique.fetchScientifiqueById
|
|
|
|
|
import fr.iut.sciencequest.model.buisness.Scientifique.fetchScientifiques
|
|
|
|
|
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
|
|
|
|
import fr.iut.sciencequest.model.buisness.Scientifique.fetchScientifiquesInfos
|
|
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
@ -16,7 +15,9 @@ class PenduViewModel : ViewModel() {
|
|
|
|
|
fun InitPartie() {
|
|
|
|
|
Log.d("PenduViewModel","Un utilisateur initialise une partie")
|
|
|
|
|
viewModelScope.launch {
|
|
|
|
|
fetchScientifiqueById(1).collect {
|
|
|
|
|
fetchScientifiquesInfos().collect { scientifiquesInfos ->
|
|
|
|
|
Log.e("PenduViewModel",scientifiquesInfos.nbScientfiques.toString())
|
|
|
|
|
fetchScientifiqueById((1..scientifiquesInfos.nbScientfiques).random()).collect {
|
|
|
|
|
val nomComplet = it.prenom + " " + it.nom
|
|
|
|
|
Log.d("ViewModelPendu",nomComplet)
|
|
|
|
|
var motATrou = ""
|
|
|
|
@ -34,6 +35,8 @@ class PenduViewModel : ViewModel() {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mot : mot à trouver
|
|
|
|
@ -60,10 +63,9 @@ class PenduViewModel : ViewModel() {
|
|
|
|
|
nvMotATrou = nvMotATrou.replaceRange(index,index + 1, letterToCheck.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var isWon = false
|
|
|
|
|
if (nvMotATrou.equals(uiState.value.motATrouver)) {
|
|
|
|
|
isWon = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val isWon = nvMotATrou == uiState.value.motATrouver
|
|
|
|
|
|
|
|
|
|
uiState.value = PenduUIState(isWon,
|
|
|
|
|
true,
|
|
|
|
|
uiState.value.nbViesRestantes,
|
|
|
|
|