|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.example.mathseduc.ui
|
|
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
@ -28,29 +29,49 @@ import androidx.compose.ui.platform.LocalContext
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import com.example.mathseduc.MainActivity
|
|
|
|
|
import com.example.mathseduc.ServerDetailsActivity
|
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
|
import com.example.mathseduc.controllers.ControllerQuestion
|
|
|
|
|
import com.example.mathseduc.ui.theme.Colors
|
|
|
|
|
import kotlinx.coroutines.channels.ticker
|
|
|
|
|
import okhttp3.MultipartBody
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
|
fun QuizMultiScreen(lobbyId: Int,serverName: String) {
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
var progressBar1Value by remember { mutableStateOf(0.0f) }
|
|
|
|
|
var chronoValue by remember { mutableStateOf(0.0f) }
|
|
|
|
|
var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId))) }
|
|
|
|
|
var listPlayer by remember { mutableStateOf(ControllerLobby.getPlayerInLobby(lobbyId)) }
|
|
|
|
|
var currentQuestionIndex by remember { mutableIntStateOf(0) }
|
|
|
|
|
val progressBarValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) }
|
|
|
|
|
val progressBarTotalValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) }
|
|
|
|
|
var quizFinished by remember { mutableStateOf(false) } // Variable pour indiquer si le quiz est terminé ou non
|
|
|
|
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
|
|
val timer = ticker(delayMillis = 100) // Update every 100 milliseconds
|
|
|
|
|
for (tick in timer) {
|
|
|
|
|
progressBar1Value += 0.1f
|
|
|
|
|
if (quizFinished) break
|
|
|
|
|
for ((index, player) in listPlayer.withIndex()) {
|
|
|
|
|
progressBarValues[index] += 0.1f
|
|
|
|
|
}
|
|
|
|
|
chronoValue += 0.1f
|
|
|
|
|
if (chronoValue >= 30f) {
|
|
|
|
|
currentQuestionIndex++
|
|
|
|
|
break
|
|
|
|
|
chronoValue = 0.0f
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
|
|
val timer = ticker(delayMillis = 3000)
|
|
|
|
|
for (tick in timer) {
|
|
|
|
|
if (quizFinished) break
|
|
|
|
|
var valueBD = ControllerLobby.getPlayerInLobby(lobbyId)
|
|
|
|
|
for ((index, player) in listPlayer.withIndex()) {
|
|
|
|
|
progressBarTotalValues[index] = progressBarValues[index] + valueBD[index].playertime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -62,8 +83,9 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
|
verticalArrangement = Arrangement.SpaceBetween
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
// ProgressBar1
|
|
|
|
|
CustomProgressBar(progressBar1Value)
|
|
|
|
|
for ((index, player) in listPlayer.withIndex()) {
|
|
|
|
|
CustomProgressBar(progressBarTotalValues[index])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Chrono ProgressBar
|
|
|
|
|
ChronoProgressBar(chronoValue)
|
|
|
|
@ -114,7 +136,12 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
|
onClick = {
|
|
|
|
|
if (answer.id == currentQuestion.idanswergood) {
|
|
|
|
|
Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show()
|
|
|
|
|
progressBar1Value += 10f
|
|
|
|
|
|
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|
val playertime = ControllerLobby.getLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected) + 10
|
|
|
|
|
formDataBuilder.addFormDataPart("playertime", playertime.toString())
|
|
|
|
|
|
|
|
|
|
ControllerLobby.updateLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected,formDataBuilder)
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(context, "Oh nan !!", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
@ -152,6 +179,11 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(context, "Fini !!", Toast.LENGTH_SHORT).show()
|
|
|
|
|
val intent = Intent(context, MainActivity::class.java)
|
|
|
|
|
//intent.putExtra("serverName", serverName)
|
|
|
|
|
//intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
quizFinished = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|