From 305ba1daa17261cd50c86c13f111fb90d9cca434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 14:25:35 +0100 Subject: [PATCH 01/10] =?UTF-8?q?Corection=20de=20bug=20lors=20de=20la=20f?= =?UTF-8?q?in=20du=20mode=20Histoire=20+=20Ajout=20page=20GameEnd=20+=20Ge?= =?UTF-8?q?stion=20du=20cas=20un=20joeur=20a=20finit=20toute=20ses=20enigm?= =?UTF-8?q?esq=20multi=20(en=20cours)=20+=20Am=C3=A9liorations=20des=20err?= =?UTF-8?q?eurs=20afficher=20aux=20visiteur=20+=20Calcule=20du=20temps=20m?= =?UTF-8?q?ax=20d'une=20partie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Config/Config.php | 20 ++++++++--- WEB/Controller/EnigmeGateway.php | 8 +++++ WEB/Controller/FrontController.php | 8 ++--- WEB/Controller/PartieGateway.php | 28 ++++++--------- WEB/Controller/ResoudreGateway.php | 10 +++++- WEB/Controller/UserController.php | 41 ++++++++++++++++++---- WEB/Model/UserModel.php | 15 +++++--- WEB/View/src/pages/Multijoueur/GameEnd.php | 37 +++++++++++++++++++ WEB/View/src/pages/Multijoueur/Partie.php | 2 +- 9 files changed, 130 insertions(+), 39 deletions(-) create mode 100644 WEB/View/src/pages/Multijoueur/GameEnd.php diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index edae634a..e8ede847 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -13,12 +13,18 @@ $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; //Page $vues['main'] = 'View/src/pages/Main.php'; $vues['presentation'] = 'View/src/pages/Presentation.html'; + +//LogSign $vues['login'] = 'View/src/pages/LogSign/Login.php'; $vues['signUp'] = 'View/src/pages/LogSign/SignUp.php'; $vues['mail'] = 'View/src/pages/LogSign/Mail.php'; $vues['confirm'] = 'View/src/pages/LogSign/Confirm.php'; + +//Test $vues['test'] = 'View/src/pages/FirstTests/FirstTest1.php'; $vues['next'] = 'View/src/pages/FirstTests/FirstTest'; + +//Admin $vues['admin'] = 'View/src/pages/Admin/Admin.php'; $vues['addEnigmeSolo'] = 'View/src/pages/Admin/AddEnigmeSolo.php'; $vues['enigmeMultiManager'] = 'View/src/pages/Admin/EnigmeMultiManager.php'; @@ -28,20 +34,26 @@ $vues['modifEnigmeSolo'] = 'View/src/pages/Admin/ModifEnigmeSolo.php'; $vues['adminSolo'] = 'View/src/pages/Admin/AdminSolo.php'; $vues['seeOrdre'] = 'View/src/pages/Admin/SeeOrdre.php'; $vues['modifOrdre'] = 'View/src/pages/Admin/ModifOrdre.php'; + +//Mulijoueur $vues['partie'] = 'View/src/pages/Multijoueur/Partie.php'; $vues['queue'] = 'View/src/pages/Multijoueur/FileAttente.php'; +$vues['queue'] = 'View/src/pages/Multijoueur/GameEnd.php'; // Enigme $vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php'; + +//Error +$vues['erreur'] = 'View/src/pages/Erreur.php'; +$error = ""; + // Server $BUFFER_SIZE = 1024; $serverAdress = "82.165.180.114"; $port= "3000"; $playerNumberPerGame = 2; -//modules + +// Modules $modules = 'node_module/'; -//Error -$vues['erreur'] = 'View/src/pages/Erreur.php'; -$error = ""; diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 481deda5..b35bb7e4 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -159,6 +159,14 @@ class EnigmeGateway $tabEnigme=EnigmeFactory::create($results); return $tabEnigme; } + + public function getLastOrdre() : int + { + $query = "SELECT ordre FROM Enigme ORDER BY ordre DESC LIMIT 1"; + $this->con->executequery($query); + $results = $this->con->getResults(); + return $results[0]['ordre']; + } public function findByOrdre(int $ordre) : array { $query = "SELECT * FROM Enigme WHERE ordre = :ordre"; diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 2660e2ea..928587a2 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -14,8 +14,6 @@ class FrontController $role = "visitor"; } // Check if action exists - //echo "FrontConroller : action = " . $_REQUEST['action'] . "
"; - //echo "role = " . $role . "
"; $action = $nettoyage->clean($_REQUEST['action']); if ($role == "user") { if ($action == NULL) { @@ -23,9 +21,11 @@ class FrontController new UserController(); } else if (method_exists('UserController', $action) == false) { $error = "Action non valide " . $action; + if ($role == "visitor"){ + $error = $error . " Pour accéder à cette page, vous devez vous connecter"; + } require($rep . $vues['erreur']); } else { - //echo "action user valide"; $_REQUEST['action'] = $action; new UserController(); } @@ -38,12 +38,10 @@ class FrontController $error = "Action non valide" . $action; require($rep . $vues['erreur']); } else { - //echo "action admin valide"; $_REQUEST['action'] = $action; new AdminController(); } } else { - //echo "action visiteur"; $_REQUEST['action'] = $action; new VisitorController(); } diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 2d9b1d6e..2c741f9d 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -152,7 +152,7 @@ class PartieGateway ); } - public function createPartieMulti(Enigme $enigme, string $mailUtilisateur) + public function createPartieMulti(array $lesEnigmes, string $mailUtilisateur) { $query = "INSERT INTO Partie VALUES (NULL,:date)"; $currentDate = date('Y-m-d H:i:s'); @@ -161,12 +161,17 @@ class PartieGateway ) ); $partie = $this->findLastPartie(); + $tpsMaxPartie = 0; $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)"; - $this->con->executeQuery($query, array( - "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), - "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER) - ) - ); + foreach ($lesEnigmes as $enigme) { + $this->con->executeQuery($query, array( + "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), + "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER) + ) + ); + $tpsMaxPartie += $enigme->getTemps(); + } + $_SESSION['tpsMaxPartie'] = $tpsMaxPartie; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), @@ -316,17 +321,6 @@ class PartieGateway return $row['enigme']; } - public function getIndex(int $idPartie, int $idEnigme){ - $query = "SELECT * FROM Contenir WHERE partie = :idPartie AND enigme = :idEnigme"; - $this->con->executeQuery($query, array( - "idPartie" => array($idPartie, SQLITE3_INTEGER), - "idEnigme" => array($idEnigme, SQLITE3_INTEGER) - ) - ); - $results = $this->con->getResults(); - $row = $results[0]; - return $row['indexEnigme']; - } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index 1e17fed4..e241fc0c 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -229,5 +229,13 @@ class ResoudreGateway { return $results[0]['enigme']; } - } + } + public function getLastIndex(int $idPartie) : int{ + $query="SELECT max(indexEnigme) FROM Resoudre + WHERE partie=:partie"; + $this->con->executeQuery($query, array( + "partie" => array($idPartie, SQLITE3_INTEGER))); + $results=$this->con->getResults(); + return $results[0]['max(indexEnigme)']; + } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 982264ee..be9ad63e 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -34,6 +34,9 @@ class UserController case "enigmeEnded": $this->enigmeEnded(); break; + case "enigmeMultiEnded": + $this->enigmeMultiEnded(); + break; case "goToQueue": $this->goToQueue(); break; @@ -168,12 +171,32 @@ class UserController $utilisateur=$_SESSION['utilisateur']; $model->enigmeEnded($utilisateur->getEmail(),$enigme->getIdEnigme()); $_REQUEST['ordre'] = $ordre + 1; - header("Location: index.php?action=goToEnigme&ordre=" . $_REQUEST['ordre']); + $lastOrdre = $model->getLastOrdre(); + if ($_REQUEST['ordre'] = $lastOrdre) { + $this->goToHome(); + } + else { + header("Location: index.php?action=goToEnigme&ordre=" . $_REQUEST['ordre']); + } + } catch (Exception $e) { + $error = "Erreur Inconnue"; + require($rep . $vues['erreur']); + } + } + public function enigmeMultiEnded(){ + try { + global $rep, $vues; + $model = new UserModel(); + $index = $_REQUEST['index']; + $enigme = $model->getEnigmebyPartieIdAndIndex($_SESSION['idPartie'],$index); + $utilisateur=$_SESSION['utilisateur']; + $model->enigmeEnded($utilisateur->getEmail(),$enigme->getIdEnigme()); + $index = $index + 1; + header("Location: index.php?action=goToGame&index=" . $index); } catch (Exception $e) { $error = "Erreur Inconnue"; require($rep . $vues['erreur']); } - } public function goToQueue() { @@ -218,10 +241,16 @@ class UserController $utilisateur = $_SESSION['utilisateur']; $idPartie = $_GET['idPartie']; $index = $_GET['index']; - $enigme = $model->getEnigmebyPartieIdAndIndex($idPartie, $index); - $model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie, $index); - $code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme()); - require($rep . $vues['partie']); + $lastIndex = $model->getLastIndex($idPartie); + if($index == $lastIndex + 1){ + require($rep . $vues['gameEnd']); + } + else{ + $enigme = $model->getEnigmebyPartieIdAndIndex($idPartie, $index); + $model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie, $index); + $code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme()); + require($rep . $vues['partie']); + } } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index cad47fe7..dca96fc1 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -29,7 +29,8 @@ class UserModel $idPartie=$this->partie_gateway->findPartieInQueue(); if ($idPartie == 0){ $enigme= $this->enigme_gateway->getRandomEnigme(); - $this->partie_gateway->createPartieMulti($enigme, $mailUtilisateur); + $lesEnigmes = array($enigme); + $this->partie_gateway->createPartieMulti($lesEnigmes, $mailUtilisateur); $idPartie=$this->partie_gateway->findPartieInQueue(); $etat=$this->partie_gateway->getEtat($idPartie); return array($idPartie, $etat); @@ -135,11 +136,15 @@ class UserModel return $this->enigme_gateway->findById($idEnigme)[0]; } - public function getIndex($mailUtilisateur, $idPartie){ - return $this->partie_gateway->getIndex($idPartie, $mailUtilisateur); - } - public function findEnigmeById(int $enigmeId) : Engine{ return $this->enigme_gateway->findById($enigmeId)[0]; } + + public function getLastIndex(int $idPartie) : int{ + return $this->resoudre_gateway->getLastIndex($idPartie); + } + + public function getLastOrdre() :int { + return $this->enigme_gateway->getLastOrdre(); + } } \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php new file mode 100644 index 00000000..8f77c1c4 --- /dev/null +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -0,0 +1,37 @@ + + + + + GameEnd + + + + + + +
+
+
+

lobby de fin de partie

+
+
+
+
+

Vous avez terminer toute les énimges.

+

Temps restant avant la fin de la partie :


+

+
+
+
+ + + + + + + \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/Partie.php b/WEB/View/src/pages/Multijoueur/Partie.php index 634a553c..0930744c 100644 --- a/WEB/View/src/pages/Multijoueur/Partie.php +++ b/WEB/View/src/pages/Multijoueur/Partie.php @@ -150,7 +150,7 @@