diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index edae634a..0fd5cb14 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['gameEnd'] = '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..148503b8 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -14,18 +14,15 @@ 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) { $_REQUEST['action'] = $action; new UserController(); } else if (method_exists('UserController', $action) == false) { - $error = "Action non valide " . $action; + $error = "Action non valide "; require($rep . $vues['erreur']); } else { - //echo "action user valide"; $_REQUEST['action'] = $action; new UserController(); } @@ -35,15 +32,13 @@ class FrontController $_REQUEST['action'] = $action; new AdminController(); } else if (method_exists('AdminController', $action) == false) { - $error = "Action non valide" . $action; + $error = "Action non valide"; 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..35d6f795 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->getTempsDeResolution(); + } + $_SESSION['tpsMaxPartie'] = $tpsMaxPartie; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), @@ -314,18 +319,16 @@ class PartieGateway $results = $this->con->getResults(); $row = $results[0]; return $row['enigme']; - } - public function getIndex(int $idPartie, int $idEnigme){ - $query = "SELECT * FROM Contenir WHERE partie = :idPartie AND enigme = :idEnigme"; + public function getDateDebut($idPartie) : DateTime{ + $query = "SELECT dateDebut FROM Partie WHERE id = :idPartie"; $this->con->executeQuery($query, array( - "idPartie" => array($idPartie, SQLITE3_INTEGER), - "idEnigme" => array($idEnigme, SQLITE3_INTEGER) + "idPartie" => array($idPartie, SQLITE3_INTEGER) ) ); $results = $this->con->getResults(); - $row = $results[0]; - return $row['indexEnigme']; + $date = new DateTime ($results[0]['dateDebut']); + return $date; } public function showAll(): void { diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index 1e17fed4..addce10f 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -229,5 +229,16 @@ 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(); + if (empty($results) || $results[0]['max(indexEnigme)'] == null) { + return 0; + } + 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..f61d6912 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&idPartie=" . $_SESSION['idPartie'] . "&index=". $index); } catch (Exception $e) { $error = "Erreur Inconnue"; require($rep . $vues['erreur']); } - } public function goToQueue() { @@ -218,10 +241,17 @@ 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($lastIndex != 0 && $index == $lastIndex + 1){ + $dateDebut = $model->getDateDebut($idPartie); + 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/Controller/VisitorController.php b/WEB/Controller/VisitorController.php index 204892d2..a4bd17a0 100644 --- a/WEB/Controller/VisitorController.php +++ b/WEB/Controller/VisitorController.php @@ -41,7 +41,7 @@ class VisitorController $this->goToReset(); break; default: - $error = "Action non valide"; + $error = "Action non valide. Pour accéder à cette page, vous devez peut être vous connecter"; require($rep . $vues['erreur']); break; } diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index cad47fe7..09d2f6e5 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,19 @@ 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(); + } + + public function getDateDebut($idPartie) : DateTime{ + return $this->partie_gateway->getDateDebut($idPartie); + } } \ 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..a3974740 --- /dev/null +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -0,0 +1,65 @@ + + + + + GameEnd + + + + + + +
+
+
+

Lobby de fin de partie

+
+
+
+
+

Vous avez terminer toute les énimges.

+

Temps restant avant la fin de la partie :

+ modify('+'. $_SESSION['tpsMaxPartie'] .'minutes'); + $now = new DateTime(); + $interval = $now->diff($end_time); + $remaining_seconds = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; + ?> +
+
+
+
+ + + + + + + + \ 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 @@