|
|
|
@ -2,16 +2,12 @@ package fr.iut.sciencequest.view.games
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.foundation.text.KeyboardActions
|
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.material3.TextField
|
|
|
|
@ -21,9 +17,7 @@ import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.unit.Dp
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
|
@ -54,9 +48,16 @@ fun PenduScreen(viewModel: PenduViewModel = viewModel(),
|
|
|
|
|
TextField(value = "",
|
|
|
|
|
onValueChange = { onLetterEntered(it, viewModel, context, goToHome) },
|
|
|
|
|
modifier = Modifier.padding(20.dp),
|
|
|
|
|
enabled = !state.value.isWon && state.value.nbViesRestantes > 0,
|
|
|
|
|
placeholder = { Text(if(!state.value.isWon) "Entrez une lettre" else "Cliquez sur Nouvelle Partie") }
|
|
|
|
|
)
|
|
|
|
|
afficherVies(state.value.nbViesRestantes)
|
|
|
|
|
Text("Lettres utilisées: " + state.value.lettresUtilises)
|
|
|
|
|
if(state.value.isWon) {
|
|
|
|
|
Text(modifier = Modifier.padding(top=10.dp), text = "Vous avez gagné !")
|
|
|
|
|
} else if (state.value.nbViesRestantes == 0) {
|
|
|
|
|
Text(modifier = Modifier.padding(top=10.dp), text = "Vous avez perdu :(")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Button(onClick = { viewModel.InitPartie() }) {
|
|
|
|
|
Text(text = stringResource(id = R.string.reset_game))
|
|
|
|
@ -73,7 +74,7 @@ fun onLetterEntered(entered: String,
|
|
|
|
|
if (entered.isNotEmpty()) {
|
|
|
|
|
vm.PlayAction(entered[0])
|
|
|
|
|
if ((!state.value.isWon) && (state.value.nbViesRestantes == 0)) {
|
|
|
|
|
goToHome()
|
|
|
|
|
Toast.makeText(context,"Vous avez perdu :(",Toast.LENGTH_LONG).show()
|
|
|
|
|
} else if (state.value.isWon) {
|
|
|
|
|
Toast.makeText(context,"Vous avez gagné !",Toast.LENGTH_LONG).show()
|
|
|
|
|
}
|
|
|
|
|