From eba391d3d84b05f9ac520f4bfcf122f7b9be3c9f Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Tue, 14 Nov 2023 16:41:57 +0100 Subject: [PATCH] feat : Score management :fire: --- Website/controllers/ControllerUser.php | 23 ++++++++++++------- Website/js/passer.js | 3 ++- Website/js/scriptChrono.js | 31 ++++++++++++++------------ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 7bf6a97..fe9539e 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -88,6 +88,8 @@ class ControllerUser function verifySingleplayer() { + $_SESSION["Score"]=0; + $_SESSION["PrevTime"]= new DateTime('now'); $difficulty = $_POST['difficulty']; $chapter = $_POST['chapter']; $difficultyIsOk = TRUE; @@ -121,25 +123,29 @@ class ControllerUser function verifQuestion() //Only Handdle solo game { + $_SESSION["CurrTime"]= new DateTime('now'); $answerNumber = $_POST["answer"]; $numQuestion = $_POST["numQuestion"] + 1; - if ($answerNumber != 1 or $answerNumber != 2 or $answerNumber != 3 or $answerNumber != 4) { + if (!($answerNumber == 0 or $answerNumber == 1 or $answerNumber == 2 or $answerNumber == 3)) { $_SESSION["error"] = "Valeur de choix de réponse invalide"; echo $this->twig->render($this->vues["singleplayer"], [ 'questions' => $_SESSION["Questions"], - 'numQuestion' => $numQuestion, + 'numQuestion' => $numQuestion-1, ]); } else { if ($numQuestion > 9) { - echo $this->twig->render($this->vues["home"]); - //EN GROS IL FAUT AFFICHER LE SCORE (C'est copilot qui a fait ça, la fin du commentaire j'veux dire) - //Si faut paser un param score de page en page dittes le moi je le ferais dw + var_dump($_SESSION["Score"]); + /// echo $this->twig->render($this->vues["ViewScore"], [ + /// 'score' => $_SESSION["Score"], + /// ]; } else { + var_dump($_SESSION["Questions"][$numQuestion - 1]['idanswergood']); + var_dump($_SESSION["Questions"][$numQuestion - 1]['answers'][$answerNumber]['id']); if ($_SESSION["Questions"][$numQuestion - 1]['idanswergood'] == $_SESSION["Questions"][$numQuestion - 1]['answers'][$answerNumber]['id']) { - // Player won - } else { - //Player lost + $time = $_SESSION["PrevTime"]->diff($_SESSION["CurrTime"]); + $_SESSION["Score"]= $_SESSION["Score"] + 80 + 40*((30-$time->s)/100*10/3); } + $_SESSION["PrevTime"] = $_SESSION["CurrTime"]; echo $this->twig->render($this->vues["singleplayer"], [ 'questions' => $_SESSION["Questions"], 'numQuestion' => $numQuestion, @@ -155,6 +161,7 @@ class ControllerUser //EN GROS IL FAUT AFFICHER LE SCORE (C'est copilot qui a fait ça, la fin du commentaire j'veux dire) //Si faut paser un param score de page en page dittes le moi je le ferais dw } else { + $_SESSION["PrevTime"] = $_SESSION["CurrTime"]; echo $this->twig->render($this->vues["singleplayer"], [ 'questions' => $_SESSION["Questions"], 'numQuestion' => $numQuestion, diff --git a/Website/js/passer.js b/Website/js/passer.js index ef7f160..942534a 100644 --- a/Website/js/passer.js +++ b/Website/js/passer.js @@ -2,4 +2,5 @@ document.querySelector('#passerButton').addEventListener('click', passerAction); function passerAction() { document.getElementById("FormQuestion").action = "/passer"; document.getElementById("FormQuestion").submit(); -} \ No newline at end of file +} +export {passerAction}; \ No newline at end of file diff --git a/Website/js/scriptChrono.js b/Website/js/scriptChrono.js index 11d25c2..f0e59b4 100644 --- a/Website/js/scriptChrono.js +++ b/Website/js/scriptChrono.js @@ -1,20 +1,21 @@ +import { passerAction } from "./passer.js"; let tempsExport = 0; const dureeQuiz = 30; // Durée du quiz en secondes - const aiguilleElement = document.getElementById("aiguille"); - const fondElement = document.getElementById("fond"); - let tempsRestant = dureeQuiz; - let debutAnimation; - const animationDuration = 30 * 1000; // Durée de l'animation en millisecondes - +const aiguilleElement = document.getElementById("aiguille"); +const fondElement = document.getElementById("fond"); +let tempsRestant = dureeQuiz; +let debutAnimation; +const animationDuration = 30 * 1000; // Durée de l'animation en millisecondes - function mettreAJourTempsExport(newTemps) { - tempsExport = newTemps; - } - function mettreAJourAiguille(timestamp) { - if (!debutAnimation) { - debutAnimation = timestamp; - } +function mettreAJourTempsExport(newTemps) { + tempsExport = newTemps; +} + +function mettreAJourAiguille(timestamp) { + if (!debutAnimation) { + debutAnimation = timestamp; + } const tempsEcoule = timestamp - debutAnimation; mettreAJourTempsExport(tempsEcoule); const pourcentageTempsEcoule = tempsEcoule / animationDuration; @@ -25,7 +26,9 @@ const dureeQuiz = 30; // Durée du quiz en secondes if (tempsEcoule < animationDuration) { requestAnimationFrame(mettreAJourAiguille); + } else { + passerAction(); } } requestAnimationFrame(mettreAJourAiguille); -export {tempsExport}; \ No newline at end of file +export { tempsExport }; \ No newline at end of file