|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
@ -18,6 +19,11 @@ import androidx.compose.material3.ButtonColors
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableIntStateOf
|
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.geometry.Offset
|
|
|
|
import androidx.compose.ui.geometry.Offset
|
|
|
@ -28,16 +34,34 @@ import androidx.compose.ui.unit.sp
|
|
|
|
import com.example.what_the_fantasy.data.local.QuestionStub
|
|
|
|
import com.example.what_the_fantasy.data.local.QuestionStub
|
|
|
|
import com.example.what_the_fantasy.data.model.Question
|
|
|
|
import com.example.what_the_fantasy.data.model.Question
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val questions = QuestionStub.allQuestions
|
|
|
|
|
|
|
|
var pts = 0
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun QuizPage() {
|
|
|
|
fun QuizPage() {
|
|
|
|
|
|
|
|
var idCurrentQuestion by remember { mutableIntStateOf(0) }
|
|
|
|
|
|
|
|
fun goNext(correctAns: String, ans: String) {
|
|
|
|
|
|
|
|
if (correctAns == "A") {
|
|
|
|
|
|
|
|
if (questions[idCurrentQuestion].ansA == ans) pts += 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (correctAns == "B") {
|
|
|
|
|
|
|
|
if (questions[idCurrentQuestion].ansB == ans) pts += 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (correctAns == "C") {
|
|
|
|
|
|
|
|
if (questions[idCurrentQuestion].ansC == ans) pts += 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (correctAns == "D") {
|
|
|
|
|
|
|
|
if (questions[idCurrentQuestion].ansD == ans) pts += 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idCurrentQuestion < questions.size) idCurrentQuestion += 1
|
|
|
|
|
|
|
|
}
|
|
|
|
val gradient = Brush.linearGradient(
|
|
|
|
val gradient = Brush.linearGradient(
|
|
|
|
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé
|
|
|
|
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé
|
|
|
|
start = Offset(0f, 1000f), // Départ en bas à gauche
|
|
|
|
start = Offset(0f, 1000f), // Départ en bas à gauche
|
|
|
|
end = Offset(1000f, 0f) // Fin en haut à droite
|
|
|
|
end = Offset(1000f, 0f) // Fin en haut à droite
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
val questions = QuestionStub.allQuestions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxSize()
|
|
|
|
.fillMaxSize()
|
|
|
@ -46,13 +70,21 @@ fun QuizPage() {
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// Numéro de la question en haut
|
|
|
|
// Numéro de la question en haut
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
text = "Question numéro : " + questions.first().id.toString(),
|
|
|
|
text = "Question numéro : " + questions[idCurrentQuestion].id.toString(),
|
|
|
|
color = Color.White,
|
|
|
|
color = Color.White,
|
|
|
|
fontSize = 18.sp, // Taille réduite pour tenir sur un écran portrait
|
|
|
|
fontSize = 18.sp, // Taille réduite pour tenir sur un écran portrait
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.align(Alignment.TopCenter) // Position en haut au centre
|
|
|
|
.align(Alignment.TopCenter) // Position en haut au centre
|
|
|
|
.padding(top = 16.dp) // Un peu d'espace en haut
|
|
|
|
.padding(top = 16.dp) // Un peu d'espace en haut
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Nombre de points : " + pts.toString(),
|
|
|
|
|
|
|
|
color = Color.White,
|
|
|
|
|
|
|
|
fontSize = 18.sp, // Taille réduite pour tenir sur un écran portrait
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.align(Alignment.TopCenter) // Position en haut au centre
|
|
|
|
|
|
|
|
.padding(top = 50.dp) // Un peu d'espace en haut
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Contenu centré, mais avec une gestion plus équilibrée du placement
|
|
|
|
// Contenu centré, mais avec une gestion plus équilibrée du placement
|
|
|
|
Column(
|
|
|
|
Column(
|
|
|
@ -64,7 +96,7 @@ fun QuizPage() {
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// Question principale
|
|
|
|
// Question principale
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
text = questions.first().question,
|
|
|
|
text = questions[idCurrentQuestion].question,
|
|
|
|
color = Color.White,
|
|
|
|
color = Color.White,
|
|
|
|
fontSize = 22.sp, // Taille plus petite pour tenir sur un écran portrait
|
|
|
|
fontSize = 22.sp, // Taille plus petite pour tenir sur un écran portrait
|
|
|
|
modifier = Modifier.padding(bottom = 16.dp) // Réduit l'espacement entre la question et les réponses
|
|
|
|
modifier = Modifier.padding(bottom = 16.dp) // Réduit l'espacement entre la question et les réponses
|
|
|
@ -72,13 +104,15 @@ fun QuizPage() {
|
|
|
|
|
|
|
|
|
|
|
|
// Liste des réponses
|
|
|
|
// Liste des réponses
|
|
|
|
val answers = listOf(
|
|
|
|
val answers = listOf(
|
|
|
|
questions.first().ansA,
|
|
|
|
questions[idCurrentQuestion].ansA,
|
|
|
|
questions.first().ansB,
|
|
|
|
questions[idCurrentQuestion].ansB,
|
|
|
|
questions.first().ansC,
|
|
|
|
questions[idCurrentQuestion].ansC,
|
|
|
|
questions.first().ansD
|
|
|
|
questions[idCurrentQuestion].ansD,
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Pour chaque réponse, on applique une Box avec un espacement uniforme
|
|
|
|
// Pour chaque réponse, on applique une Box avec un espacement uniforme
|
|
|
|
|
|
|
|
|
|
|
|
answers.forEach { answer ->
|
|
|
|
answers.forEach { answer ->
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
@ -88,7 +122,7 @@ fun QuizPage() {
|
|
|
|
brush = gradient,
|
|
|
|
brush = gradient,
|
|
|
|
shape = RoundedCornerShape(16.dp) // Coins arrondis
|
|
|
|
shape = RoundedCornerShape(16.dp) // Coins arrondis
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.clickable { /* Action pour la réponse */ }
|
|
|
|
.clickable { goNext(questions[idCurrentQuestion].correctAns, answer) }
|
|
|
|
.padding(horizontal = 8.dp), // Padding interne
|
|
|
|
.padding(horizontal = 8.dp), // Padding interne
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|