From 029f474f2167dc7eeb56e37ba7a71351ffcf0b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Thu, 12 Jan 2023 19:27:48 +0100 Subject: [PATCH] Skip eningme en partie + corections du calcul des points --- WEB/Controller/PartieGateway.php | 2 ++ WEB/Controller/ResoudreGateway.php | 31 ++++++++++++++++++ WEB/Controller/UserController.php | 38 +++++++++++++++++++++++ WEB/Model/UserModel.php | 18 ++++++++++- WEB/View/src/pages/Multijoueur/Partie.php | 5 +-- 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index c2173666..f42a9967 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -383,6 +383,8 @@ class PartieGateway ) ); } + // public function quitGame(string $mailUtilisateur,int $idPartie){ + // } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index 4806fbe8..f1d1c782 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -316,4 +316,35 @@ class ResoudreGateway $results=$this->con->getResults(); return $results; } + + public function skipEnigme(string $mailUtilisateur, int $idPartie, int $idEnigme) { + global $playerNumberPerGame; + $query = "UPDATE Resoudre + SET ended=:ended + WHERE utilisateur=:utilisateur + AND partie=:partie"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "partie" => array($idPartie, SQLITE3_INTEGER), + "ended" => array(1, SQLITE3_INTEGER))); + + $query = "UPDATE Resoudre + SET temps=:temps + WHERE utilisateur=:utilisateur + AND partie=:partie"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "partie" => array($idPartie, SQLITE3_INTEGER), + "temps" => array(0, SQLITE3_INTEGER))); + + $query = "UPDATE Resoudre + SET classement=:classement + WHERE utilisateur=:utilisateur + AND partie=:partie"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "partie" => array($idPartie, SQLITE3_INTEGER), + "classement" => array($playerNumberPerGame, SQLITE3_INTEGER))); + + } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 53f35885..ee5da7e7 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -67,6 +67,12 @@ class UserController case "quitQueue": $this->quitQueue(); break; + case "quitGame": + $this->quitGame(); + break; + case "skipEnigme": + $this->skipEnigme(); + break; default: $error = "Action non valide"; require($rep . $vues['erreur']); @@ -389,4 +395,36 @@ class UserController require($rep . $vues['erreur']); } } + public function quitGame(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $idPartie = $_SESSION['idPartie']; + $utilisateur = $_SESSION['utilisateur']; + // $model->quitGame($utilisateur->getEmail(), $idPartie); + // echo ''; + // require ($rep . $vues['lobby']); + } + catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } + public function skipEnigme(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $idPartie = $_SESSION['idPartie']; + $utilisateur = $_SESSION['utilisateur']; + $idEnigme = $_GET['idEnigme']; + $index = $_GET['index']; + $model->skipEnigme($utilisateur->getEmail(), $idPartie, $idEnigme); + $index = $index + 1; + header("Location: index.php?action=goToGame&idPartie=" . $idPartie . "&index=". $index); + } + catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } } \ No newline at end of file diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 0065e0bf..d723dea6 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -188,6 +188,7 @@ class UserModel } public function getPointsAtTheEnd(string $mailUtilisateur, int $idPartie) : int{ + global $playerNumberPerGame; $points = 0; $result = $this->resoudre_gateway->getAllByPartieAndUtilisateur($mailUtilisateur, $idPartie); foreach ($result as $row){ @@ -197,9 +198,15 @@ class UserModel else if ($row['classement'] == 2){ $points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.75; } - else{ + else if ($row['classement'] == 3){ $points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.5; } + else if ($row['ended'] == 0){ + $points += 0; + } + else{ + $points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.25; + } } return $points; } @@ -254,4 +261,13 @@ class UserModel $this->partie_gateway->delete($idPartie); } } + public function skipEnigme(string $mailUtilisateur, int $idPartie, int $idEnigme) { + $this->resoudre_gateway->skipEnigme($mailUtilisateur, $idPartie, $idEnigme); + } + // public function quitGame(string $mailUtilisateur, int $idPartie) { + // $this->partie_gateway->quitGame($mailUtilisateur, $idPartie); + // if ($this->partie_gateway->getPlayerNumber($idPartie) == 0){ + // $this->partie_gateway->delete($idPartie); + // } + // } } \ 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 c27c7d04..a693e642 100644 --- a/WEB/View/src/pages/Multijoueur/Partie.php +++ b/WEB/View/src/pages/Multijoueur/Partie.php @@ -31,8 +31,9 @@
- -
+ getId() . '&index='. $index .'"' ?>>Skip +
+

Temps restant :

modify('+'. $_SESSION['tpsMaxPartie'] .'seconds');