diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index a883ef7b..d3f10fd1 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -342,6 +342,11 @@ class PartieGateway ) ); } + public function launchGame(int $idPartie){ + $query = "UPDATE Participer SET etat=1 WHERE etat=0 AND partie=:partie"; + $this->con->executeQuery($query,array( + 'partie' => array($idPartie,SQLITE3_INTEGER))); + } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index c5694997..af80c93a 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -219,10 +219,11 @@ class UserController $_SESSION['idPartie'] = $idPartie; $lesJoueurs = $model->getLesJoueurs($idPartie); if($etat == 1){ + $model->launchGame($idPartie); header("Location: index.php?action=goToGame&idPartie=" . $idPartie . "&index=1"); } else{ - while ($etat == 0){ + while ($etat != 1){ sleep(5); $etat = $model->getEtatPartie($idPartie); } @@ -234,7 +235,8 @@ class UserController } } - public function goToGame(){ + public function goToGame() + { try { global $rep, $vues, $error; $model = new UserModel(); @@ -242,15 +244,15 @@ class UserController $idPartie = $_GET['idPartie']; $index = $_GET['index']; $lastIndex = $model->getLastIndex($idPartie); - if($lastIndex != 0 && $index == $lastIndex + 1){ - if ($model->checkGameIsEnd($idPartie)){ + if ($lastIndex != 0 && $index == $lastIndex + 1) { + if ($model->checkGameIsEnd($idPartie)) { $this->endGame(); + return; } $dateDebut = $model->getDateDebut($idPartie); $points = $model->getPointsAtTheEnd($utilisateur->getEmail(), $idPartie); require($rep . $vues['lobbyEnd']); - } - else{ + } else { $enigme = $model->getEnigmebyPartieIdAndIndex($idPartie, $index); $model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie, $index); $code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme()); @@ -261,18 +263,6 @@ class UserController require($rep . $vues['erreur']); } } - public function launchGame(){ - try { - global $rep, $vues, $error; - $model = new UserModel(); - $model->launchGame(); - require($rep . $vues['partie']); - } - catch (Exception $e) { - $error = $e->getMessage(); - require($rep . $vues['erreur']); - } - } public function logout() { $_SESSION['role'] = 'visitor'; @@ -347,6 +337,7 @@ class UserController global $rep, $vues, $error; $model = new UserModel(); $idPartie = $_SESSION['idPartie']; + $lesInfos = $model->getEndGameInfo($idPartie); $model->endGame($idPartie); require ($rep . $vues['gameEnd']); } diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index cb7b6bd2..8bc3c80a 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -118,89 +118,6 @@ class UtilisateurGateway return False; } - public function launchGame(Utilisateur $utilisateur){ - $query = "UPDATE Participer SET etat=1 WHERE etat=0 AND utilisateur=:utilisateur"; - $this->con->executeQuery($query,array( - 'utilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT))); - } - - /*public function resoudreEnigmeMulti(string $emailUtilisateur) - { - $query="SELECT c.partie FROM Contenir - WHERE c.utilisateur = :emailUtilisateur - and c.enCours = TRUE"; - $this->con->executeQuery($query, array( - ':emailUtilisateur' => array($emailUtilisateur,SQLITE3_TEXT) - )); - $idPartie=$this->con->getResults()[0]["partie"]; - - $query="SELECT e.id, c2.indexEnigme FROM Resoudre r, Contenir c1,Contenir c2, Enigme e WHERE - r.id = :idPartie - AND r.utilisateur=:idutilisateur - AND r.partie=:idPartie - AND r.temps IS NOT NULL - AND c1.partie = r.partie - AND c2.index=c1.index + 1 - AND e.id = c1.enigme - AND r.temps = (SELECT max(r.temps))"; - $results=$this->con->getResults(); - if(empty($results)) - { - $query="SELECT c.enigme, c.indexEnigme FROM Contenir c WHERE - c.partie = :idPartie - AND c.indexEnigme = 0"; - $results=$this->con->getResults(); - } - $idEnigme=$results[0]["enigme"]; - $index=$results[0]["indexEnigme"]; - - $query="SELECT max(classement) FROM Enigme e,Partie p, Resoudre r - WHERE p.id=r.partie - AND e.id=r.enigme"; - $this->con->executeQuery($query); - $results=$this->con->getResults(); - if(empty($results)) - $classement=1; - else - $classement=$results[0]["max"]+1; - - $query="SELECT * FROM Resoudre - WHERE r.utilisateur=:utilisateur - AND r.enigme=:idEnigme - AND r.partie=:idPartie"; - $this->con->executeQuery($query, array( - "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), - "enigme" => array($idEnigme, SQLITE3_INTEGER), - "partie" => array($idPartie, SQLITE3_INTEGER))); - $results=$this->con->getResults(); - if(empty($results)) - { - $query="INSERT INTO Resoudre VALUES (:utilisateur, :enigme,:partie,:classement,:index,:temps,TRUE)"; - $this->con->executeQuery($query, array( - "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), - "enigme" => array($idEnigme, SQLITE3_INTEGER), - "partie" => array($idPartie, SQLITE3_INTEGER), - "classement" => array($classement, SQLITE3_INTEGER), - "index" => array($index, SQLITE3_INTEGER), - "temps" => array($temps, SQLITE3_FLOAT))); - return array($emailUtilisateur => array($points,$temps)) - } - else - { - $query="UPDATE Resoudre - SET classement=:classement; - WHERE utilisateur=:utilisateur - AND enigme=:idEnigme - AND partie=:idPartie"; - $this->con->executeQuery($query, array( - "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), - "enigme" => array($idEnigme, SQLITE3_INTEGER), - "partie" => array($idPartie, SQLITE3_INTEGER), - "classement" => array($classement, SQLITE3_INTEGER))); - return array(); - } - }*/ - public function passerEnigmeMulti(string $emailUtilisateur){ $query="SELECT p.partie FROM Participer WHERE p.utilisateur = :emailUtilisateur diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 95e039f9..493a8925 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -56,9 +56,9 @@ class UserModel return $this->partie_gateway->findPartieInQueue(); } - public function launchGame() + public function launchGame($idPartie) { - $this->utilisateur_gateway->launchGame($_SESSION['utilisateur']); + $this->partie_gateway->launchGame($idPartie); } public function logout() @@ -146,7 +146,7 @@ class UserModel return $this->partie_gateway->getEtat($idPartie); } - public function getLesJoueurs($idPartie){ + public function getLesJoueurs($idPartie) : array{ $lesMailJoeurs = $this->partie_gateway->getLesMailJoueurs($idPartie); $lesJoueurs = array(); foreach ($lesMailJoeurs as $mail){ @@ -192,6 +192,24 @@ class UserModel } return $points; } + public function getTempsAtTheEnd(string $mailUtilisateur, int $idPartie) : int{ + $temps = 0; + $result = $this->resoudre_gateway->getAllByPartieAndUtilisateur($mailUtilisateur, $idPartie); + foreach ($result as $row){ + $temps += $this->enigme_gateway->findById($row['enigme'])[0]->getTempsDeResolution(); + } + return $temps; + } + public function getEndGameInfo(int $idPartie) : array{ + $lesJoueurs = $this->getLesJoueurs($idPartie); + $lesPoints = array(); + $lesTemps = array(); + foreach ($lesJoueurs as $joueur){ + $lesPoints[] = $this->getPointsAtTheEnd($joueur->getEmail(), $idPartie); + $lesTemps[] = $this->getTempsAtTheEnd($joueur->getEmail(), $idPartie); + } + return array($lesJoueurs, $lesPoints, $lesTemps); + } public function checkGameIsEnd(int $idPartie) : bool{ $lesMailJoueurs = $this->partie_gateway->getLesMailJoueurs($idPartie); $lesIdEnigmes = $this->partie_gateway->getLesIdEnigmes($idPartie); diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index 3864e0a8..545bdd14 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -14,7 +14,36 @@
-Coucou
+Bien joué à tous la partie est finis, voici le classement :
+Classement | +Nom | +Point | +Temps | +X | "; + echo "".$info[0]." | "; + echo "".$info[1]." | "; + echo "".$info[2]." | "; + echo ""; + } + ?> +
---|---|---|---|
1 | +John | +100 | +00:00:00 | +