From da0c36047542bde84ce1d33af36853425c307183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Wed, 11 Jan 2023 18:22:20 +0100 Subject: [PATCH] Test signalement de fin de parttie a tous les jouur en lobby de fin de partie --- WEB/Controller/PartieGateway.php | 3 +++ WEB/Controller/UserController.php | 20 +++++++++++++++++--- WEB/View/src/pages/Multijoueur/GameEnd.php | 2 +- WEB/View/src/pages/Multijoueur/LobbyEnd.php | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index a2104c37..a71716f3 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -266,6 +266,9 @@ class PartieGateway ); $results = $this->con->getResults(); foreach ($results as $row){ + if($row['etat'] == 2){ + return 2; + } if($row['etat'] == 1){ return 1; } diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index af80c93a..e6ea56bd 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -46,9 +46,6 @@ class UserController case "logout": $this->logout(); break; - case "launchGame": - $this->launchGame(); - break; case "saveCode": $this->saveCode(); break; @@ -58,6 +55,9 @@ class UserController case "saveCodeInCookie": $this->saveCodeInCookie(); break; + case "getGameEtat": + $this->getGameEtat(); + break; default: $error = "Action non valide"; require($rep . $vues['erreur']); @@ -331,6 +331,20 @@ class UserController } } + public function getGameEtat(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $idPartie = $_SESSION['idPartie']; + $etat = $model->getEtatPartie($idPartie); + echo $etat; + } + catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } + // A appeler après avoir vérifié que la partie est finie public function endGame(){ try { diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index dc1981ac..4ec81d12 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -23,7 +23,7 @@ Classement Nom Point - Temps + Temps (en secondes) diff --git a/WEB/View/src/pages/Multijoueur/LobbyEnd.php b/WEB/View/src/pages/Multijoueur/LobbyEnd.php index d4e4a224..4d1a0dad 100644 --- a/WEB/View/src/pages/Multijoueur/LobbyEnd.php +++ b/WEB/View/src/pages/Multijoueur/LobbyEnd.php @@ -52,6 +52,24 @@ } } var countdownTimer = setInterval('countdown()', 1000); + + function checkIsEnd() { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=endGame', true); + xhr.responseType = 'text'; + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onload = function () { + if (xhr.status === 200) { + if (xhr.responseText == "2") { + window.location.href = 'http://82.165.180.114/Scripted/WEB/index.php?action=getGameEtat' + } + }; + xhr.send(null); + } + } + while (1){ + checkIsEnd(); + }