|
|
@ -21,14 +21,17 @@ import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
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.local.QuizStub
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun QuizPage(
|
|
|
|
fun QuizPage(
|
|
|
|
navControllerQuizEnd: (Int, Int) -> Unit,
|
|
|
|
navControllerQuizEnd: (Int, Int) -> Unit,
|
|
|
|
navControllerQuizMenu: () -> Unit,
|
|
|
|
navControllerQuizMenu: () -> Unit,
|
|
|
|
id: Int
|
|
|
|
navControllerMenu: () -> Unit,
|
|
|
|
|
|
|
|
idQuiz: Int
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
val questions = QuestionStub.allQuestions
|
|
|
|
val quiz = QuizStub.getQuizById(idQuiz)
|
|
|
|
|
|
|
|
val questions = quiz?.questions ?: emptyList()
|
|
|
|
var idCurrentQuestion by remember { mutableIntStateOf(0) }
|
|
|
|
var idCurrentQuestion by remember { mutableIntStateOf(0) }
|
|
|
|
var pts by remember { mutableIntStateOf(0) }
|
|
|
|
var pts by remember { mutableIntStateOf(0) }
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +52,7 @@ fun QuizPage(
|
|
|
|
|
|
|
|
|
|
|
|
if (answer == correctAnswer) pts++
|
|
|
|
if (answer == correctAnswer) pts++
|
|
|
|
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
|
|
|
|
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
|
|
|
|
else navControllerQuizEnd(0, pts) // Retour menu
|
|
|
|
else navControllerQuizEnd(idQuiz, pts) // Retour menu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Column (
|
|
|
|
Column (
|
|
|
@ -84,22 +87,24 @@ fun QuizPage(
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
val question = questions[idCurrentQuestion]
|
|
|
|
val question = questions[idCurrentQuestion]
|
|
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
Column(
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (quiz != null) {
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
text = "▶ Quiz ◀",
|
|
|
|
text = "▶ ${quiz.name} ◀",
|
|
|
|
color = Color.White,
|
|
|
|
color = Color.White,
|
|
|
|
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
|
|
|
|
style = TextStyle(fontSize = 20.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer(Modifier.height(20.dp))
|
|
|
|
Column (
|
|
|
|
Column (
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.background(brush = gradient, shape = RoundedCornerShape(20.dp)),
|
|
|
|
.background(brush = gradient, shape = RoundedCornerShape(20.dp)),
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
"Question ${question.id}",
|
|
|
|
"Question ${idCurrentQuestion+1}",
|
|
|
|
color = Color.White,
|
|
|
|
color = Color.White,
|
|
|
|
fontSize = 18.sp,
|
|
|
|
fontSize = 18.sp,
|
|
|
|
modifier = Modifier.padding(top = 20.dp),
|
|
|
|
modifier = Modifier.padding(top = 20.dp),
|
|
|
@ -162,12 +167,13 @@ fun QuizPage(
|
|
|
|
Image(
|
|
|
|
Image(
|
|
|
|
painter = painterResource(R.drawable.wf_logo),
|
|
|
|
painter = painterResource(R.drawable.wf_logo),
|
|
|
|
contentDescription = "Menu Button",
|
|
|
|
contentDescription = "Menu Button",
|
|
|
|
Modifier.clickable { navControllerQuizMenu() }
|
|
|
|
Modifier.clickable { navControllerMenu() }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
// Bouton Quiz
|
|
|
|
// Bouton Menu Quiz
|
|
|
|
Image(
|
|
|
|
Image(
|
|
|
|
painter = painterResource(id = R.drawable.quiz_icon),
|
|
|
|
painter = painterResource(id = R.drawable.quiz_icon),
|
|
|
|
contentDescription = "Bouton"
|
|
|
|
contentDescription = "Bouton",
|
|
|
|
|
|
|
|
Modifier.clickable { navControllerQuizMenu() }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|