Add QuizMenu Button + Finish view

pull/35/head
tomivt 2 months ago
parent 347f28b7b3
commit 89678928fb

@ -34,7 +34,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz4 = Quiz(
id = 3,
@ -44,7 +44,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz5 = Quiz(
@ -55,7 +55,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz6 = Quiz(
id = 3,
@ -65,7 +65,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz7 = Quiz(
id = 3,
@ -75,7 +75,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz8 = Quiz(
id = 3,
@ -85,7 +85,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz9 = Quiz(
id = 3,
@ -95,7 +95,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz10 = Quiz(
id = 3,
@ -105,7 +105,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val quiz11 = Quiz(
id = 3,
@ -115,7 +115,7 @@ object QuizStub {
QuestionStub.question5,
QuestionStub.question6
),
img = "hp"
img = "quiz"
)
val allQuizzes: List<Quiz> = listOf(quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9, quiz10, quiz11)

@ -71,6 +71,7 @@ fun AppNavigator() {
navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts))
},
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) },
navControllerMenu = { navController.navigate(Destination.Accueil.route) },
idQuiz
)
}
@ -80,7 +81,8 @@ fun AppNavigator() {
QuizEndPage(
idQuiz,
pts,
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) },
navControllerMenu = { navController.navigate(Destination.Accueil.route) }
)
}
composable(Destination.Profil.route) {

@ -26,6 +26,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.QuestionStub
import com.example.what_the_fantasy.data.local.QuizStub
import com.example.what_the_fantasy.ui.navigations.Destination
val gradient = Brush.linearGradient(
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)),
@ -34,7 +36,12 @@ val gradient = Brush.linearGradient(
)
@Composable
fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
fun QuizEndPage(
idQuiz: Int,
points: Int,
navControllerQuizMenu: () -> Unit,
navControllerMenu: () -> Unit
) {
Column(
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) {
@ -80,14 +87,13 @@ fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceEvenly
) {
val quiz = QuizStub.getQuizById(idQuiz)
val nbQuestions = quiz?.questions?.size
Text (
text = "Quiz N°$idQuiz",
text = "${quiz?.name}",
color = Color.White,
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
val nbQuestions = QuestionStub.allQuestions.size
Text (
text = "Nombres de Questions : $nbQuestions",
color = Color.White,
@ -99,13 +105,17 @@ fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
style = TextStyle(fontSize = 15.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
val pourcentage = (points.toDouble() / nbQuestions!!) * 100
val note = when {
points == 10 -> "S"
points >= 7 -> "A"
points >= 4 -> "B"
pourcentage == 100.0 -> "S"
pourcentage >= 70.0 -> "A"
pourcentage >= 40.0 -> "B"
else -> "C"
}
println("Note obtenue : $note")
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
@ -145,13 +155,15 @@ fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
Image(
painter = painterResource(R.drawable.wf_logo),
contentDescription = "Menu Button",
Modifier.clickable { navControllerQuizMenu() }
Modifier.clickable { navControllerMenu() }
)
// Bouton Quiz
// Bouton Menu Quiz
Image(
painter = painterResource(id = R.drawable.quiz_icon),
contentDescription = "Bouton",
modifier = Modifier.size(50.dp)
modifier = Modifier
.size(50.dp)
.clickable { navControllerQuizMenu() }
)
}
}

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 284 KiB

Loading…
Cancel
Save