|
|
@ -1,33 +1,16 @@
|
|
|
|
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.*
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
|
|
|
|
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.layout.width
|
|
|
|
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
|
|
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
|
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
|
|
|
|
import androidx.compose.material3.ButtonColors
|
|
|
|
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.*
|
|
|
|
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
|
|
|
@ -37,124 +20,83 @@ import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val questions = QuestionStub.allQuestions
|
|
|
|
|
|
|
|
var pts = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun QuizPage(navController: NavController) {
|
|
|
|
fun QuizPage(navController: NavController) {
|
|
|
|
|
|
|
|
val questions = QuestionStub.allQuestions
|
|
|
|
var idCurrentQuestion by remember { mutableIntStateOf(0) }
|
|
|
|
var idCurrentQuestion by remember { mutableIntStateOf(0) }
|
|
|
|
fun goNext(correctAns: String, ans: String) {
|
|
|
|
var pts by remember { mutableIntStateOf(0) }
|
|
|
|
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)),
|
|
|
|
start = Offset(0f, 1000f), // Départ en bas à gauche
|
|
|
|
start = Offset(0f, 1000f),
|
|
|
|
end = Offset(1000f, 0f) // Fin en haut à droite
|
|
|
|
end = Offset(1000f, 0f)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun onAnswerSelected(answer: String) {
|
|
|
|
|
|
|
|
val currentQuestion = questions[idCurrentQuestion]
|
|
|
|
|
|
|
|
val correctAnswer = mapOf(
|
|
|
|
|
|
|
|
"A" to currentQuestion.ansA,
|
|
|
|
|
|
|
|
"B" to currentQuestion.ansB,
|
|
|
|
|
|
|
|
"C" to currentQuestion.ansC,
|
|
|
|
|
|
|
|
"D" to currentQuestion.ansD
|
|
|
|
|
|
|
|
)[currentQuestion.correctAns]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (answer == correctAnswer) pts++
|
|
|
|
|
|
|
|
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
|
|
|
|
|
|
|
|
else navController.popBackStack() // Retour menu
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxSize()
|
|
|
|
.fillMaxSize()
|
|
|
|
.background(Color(0xFF100C1B)) // Fond global de l'écran
|
|
|
|
.background(Color(0xFF100C1B))
|
|
|
|
.padding(16.dp) // Marges autour de tout le contenu
|
|
|
|
.padding(16.dp)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
IconButton(
|
|
|
|
Column(
|
|
|
|
onClick = {
|
|
|
|
|
|
|
|
navController.popBackStack() // Revenir à la page précédente (QuizAccueil)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.align(Alignment.TopStart)
|
|
|
|
.fillMaxSize(),
|
|
|
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Icon(
|
|
|
|
val question = questions[idCurrentQuestion]
|
|
|
|
imageVector = Icons.Default.ArrowBack, // Flèche de retour
|
|
|
|
|
|
|
|
contentDescription = "Retour",
|
|
|
|
|
|
|
|
tint = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Numéro de la question en haut
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Question numéro : " + questions[idCurrentQuestion].id.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 = 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
|
|
|
|
Column (
|
|
|
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Box(
|
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
IconButton(
|
|
|
|
|
|
|
|
onClick = { navController.popBackStack() },
|
|
|
|
|
|
|
|
modifier = Modifier.align(Alignment.TopStart)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Text("Question ${question.id}", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 20.dp))
|
|
|
|
|
|
|
|
Text("Points : $pts", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 40.dp))
|
|
|
|
|
|
|
|
Text(question.question, color = Color.White, fontSize = 22.sp, modifier = Modifier.padding(40.dp))
|
|
|
|
|
|
|
|
}
|
|
|
|
Column (
|
|
|
|
Column (
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxSize()
|
|
|
|
.padding(top = 30.dp)
|
|
|
|
.padding(top = 48.dp), // Réduit l'espace entre le numéro de la question et la question elle-même
|
|
|
|
|
|
|
|
verticalArrangement = Arrangement.Center, // Centre verticalement
|
|
|
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally // Centre horizontalement
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// Question principale
|
|
|
|
listOf(question.ansA, question.ansB, question.ansC, question.ansD).forEach { answer ->
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = questions[idCurrentQuestion].question,
|
|
|
|
|
|
|
|
color = Color.White,
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Liste des réponses
|
|
|
|
|
|
|
|
val answers = listOf(
|
|
|
|
|
|
|
|
questions[idCurrentQuestion].ansA,
|
|
|
|
|
|
|
|
questions[idCurrentQuestion].ansB,
|
|
|
|
|
|
|
|
questions[idCurrentQuestion].ansC,
|
|
|
|
|
|
|
|
questions[idCurrentQuestion].ansD,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pour chaque réponse, on applique une Box avec un espacement uniforme
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
answers.forEach { answer ->
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.width(220.dp) // Largeur plus petite pour que ça tienne mieux
|
|
|
|
.width(220.dp)
|
|
|
|
.height(50.dp) // Hauteur ajustée
|
|
|
|
.height(50.dp)
|
|
|
|
.background(
|
|
|
|
.background(brush = gradient, shape = RoundedCornerShape(16.dp))
|
|
|
|
brush = gradient,
|
|
|
|
.clickable { onAnswerSelected(answer) }
|
|
|
|
shape = RoundedCornerShape(16.dp) // Coins arrondis
|
|
|
|
.padding(horizontal = 8.dp),
|
|
|
|
)
|
|
|
|
|
|
|
|
.clickable { goNext(questions[idCurrentQuestion].correctAns, answer) }
|
|
|
|
|
|
|
|
.padding(horizontal = 8.dp), // Padding interne
|
|
|
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
Text(answer, color = Color.White, fontSize = 18.sp)
|
|
|
|
text = answer,
|
|
|
|
|
|
|
|
color = Color.White,
|
|
|
|
|
|
|
|
fontSize = 18.sp // Taille du texte ajustée pour un écran portrait
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer(modifier = Modifier.height(16.dp)) // Espacement réduit entre les réponses
|
|
|
|
Spacer(modifier = Modifier.height(60.dp))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|