From 1ee2ccd147d58cf0cea708326f7672423341d856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 16:49:44 +0100 Subject: [PATCH 01/11] =?UTF-8?q?Changement=20d'affichage=20+=20Passage=20?= =?UTF-8?q?en=20seconde=20+=20Ajout=20du=20temps=20qu'a=20mis=20l'utilisat?= =?UTF-8?q?eur=20pour=20r=C3=A9soudre=20l'=C3=A9nigme=20dans=20a=20bd=20+?= =?UTF-8?q?=20Calcule=20du=20classement=20en=20bd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/ResoudreGateway.php | 43 +++++++++++++++++++++- WEB/Controller/UserController.php | 2 +- WEB/Model/UserModel.php | 16 +++++++- WEB/View/src/pages/Multijoueur/GameEnd.php | 4 +- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index addce10f..6b350325 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -168,6 +168,34 @@ class ResoudreGateway "enigme" => array($enigmeId, SQLITE3_INTEGER), "ended" => array(1, SQLITE3_INTEGER))); } + public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId, int $tempDeResolution, $classement){ + $query="UPDATE Resoudre + SET ended=:ended + WHERE utilisateur=:utilisateur + AND enigme=:enigme"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "ended" => array(1, SQLITE3_INTEGER))); + + $query="UPDATE Resoudre + SET temps=:temps + WHERE utilisateur=:utilisateur + AND enigme=:enigme"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "temps" => array($tempDeResolution, SQLITE3_INTEGER))); + + $query="UPDATE Resoudre + SET classement=:classement + WHERE utilisateur=:utilisateur + AND enigme=:enigme"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "classement" => array($classement, SQLITE3_INTEGER))); + } public function saveCode(string $mailUtilisateur, int $enigmeId, string $code){ $query="UPDATE Resoudre @@ -216,7 +244,6 @@ class ResoudreGateway WHERE utilisateur=:utilisateur AND ended=:ended ORDER BY ended DESC LIMIT 1"; - // $query = "SELECT * FROM Partie ORDER BY id DESC LIMIT 1"; $this->con->executeQuery($query, array( "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), "ended" => array(1, SQLITE3_INTEGER))); @@ -241,4 +268,18 @@ class ResoudreGateway } return $results[0]['max(indexEnigme)']; } + public function getMaxClassement($enigmeId, $idPartie) : int{ + $query="SELECT classement FROM Resoudre + WHERE enigme=:enigme + AND partie=:partie + ORDER BY classement DESC LIMIT 1"; + $this->con->executeQuery($query, array( + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "partie" => array($idPartie, SQLITE3_INTEGER))); + $results=$this->con->getResults(); + if (empty($results) || $results[0]['classement'] == null) { + return 0; + } + return $results[0]['classement']; + } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index f61d6912..ded2d137 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -190,7 +190,7 @@ class UserController $index = $_REQUEST['index']; $enigme = $model->getEnigmebyPartieIdAndIndex($_SESSION['idPartie'],$index); $utilisateur=$_SESSION['utilisateur']; - $model->enigmeEnded($utilisateur->getEmail(),$enigme->getIdEnigme()); + $model->enigmeMultiEnded($utilisateur->getEmail(),$enigme->getIdEnigme()); $index = $index + 1; header("Location: index.php?action=goToGame&idPartie=" . $_SESSION['idPartie'] . "&index=". $index); } catch (Exception $e) { diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 09d2f6e5..5a0ca9f1 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -95,8 +95,20 @@ class UserModel return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId); } - public function enigmeEnded(string $mailUtilisateur, int $enigmeId){ - $this->resoudre_gateway->enigmeEnded($mailUtilisateur,$enigmeId); + public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){ + $end_time = $_SESSION['tpsMaxPartie']; + $now = new DateTime(); + $interval = $now->diff($end_time); + $tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; + $idPartie = $_SESSION['idPartie']; + $result = $this->resoudre_gateway->getMaxClassement($enigmeId, $idPartie); + if ($result == 0){ + $classement = 1; + } + else{ + $classement = $result + 1; + } + $this->resoudre_gateway->enigmeMultiEnded($mailUtilisateur,$enigmeId, $tempDeResolution, $classement); } public function saveCode(string $mailUtilisateur, int $enigmeId,string $code ){ diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index a3974740..aa7cc6f8 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -21,7 +21,7 @@

Vous avez terminer toute les énimges.

Temps restant avant la fin de la partie :

modify('+'. $_SESSION['tpsMaxPartie'] .'minutes'); + $end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds'); $now = new DateTime(); $interval = $now->diff($end_time); $remaining_seconds = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; @@ -42,7 +42,7 @@ if (remainingSeconds < 10) { remainingSeconds = "0" + remainingSeconds; } - document.getElementById('countdown').innerHTML = days + " jours " + hours + " heures " + minutes + " minutes " + remainingSeconds + " secondes"; + document.getElementById('countdown').innerHTML = hours + " heures " + minutes + " minutes " + remainingSeconds + " secondes"; if (seconds == 0) { clearInterval(countdown); document.getElementById('countdown').innerHTML = "Expired"; From d402bddb81c2864ded8628dc586109b8a58afd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:06:04 +0100 Subject: [PATCH 02/11] =?UTF-8?q?D=C3=A9l=C3=A9guations=20du=20calcul=20du?= =?UTF-8?q?=20temps=20max=20par=20partie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/PartieGateway.php | 17 ++++++++++++++--- WEB/Model/UserModel.php | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 35d6f795..b927e860 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -161,7 +161,6 @@ class PartieGateway ) ); $partie = $this->findLastPartie(); - $tpsMaxPartie = 0; $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)"; foreach ($lesEnigmes as $enigme) { $this->con->executeQuery($query, array( @@ -169,9 +168,7 @@ class PartieGateway "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), @@ -320,6 +317,20 @@ class PartieGateway $row = $results[0]; return $row['enigme']; } + + public function findAllEnigmeIdInPartie ($idPartie) : array{ + $query = "SELECT * FROM Contenir WHERE partie = :idPartie"; + $this->con->executeQuery($query, array( + "idPartie" => array($idPartie, SQLITE3_INTEGER) + ) + ); + $results = $this->con->getResults(); + $lesEnigmes = array(); + foreach ($results as $row){ + $lesEnigmes[] = $row['enigme']; + } + return $lesEnigmes; + } public function getDateDebut($idPartie) : DateTime{ $query = "SELECT dateDebut FROM Partie WHERE id = :idPartie"; $this->con->executeQuery($query, array( diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 5a0ca9f1..7ac9870f 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -33,18 +33,28 @@ class UserModel $this->partie_gateway->createPartieMulti($lesEnigmes, $mailUtilisateur); $idPartie=$this->partie_gateway->findPartieInQueue(); $etat=$this->partie_gateway->getEtat($idPartie); - return array($idPartie, $etat); } else{ $this->partie_gateway->addToPartie($mailUtilisateur, $idPartie); $etat=$this->partie_gateway->getEtat($idPartie); - return array($idPartie, $etat); } + $tpsMaxPartie = $this->calculTpsMaXPartie($idPartie); + $_SESSION['tpsMaxPartie'] = $tpsMaxPartie; + return array($idPartie, $etat); } - public function findUserGroup() : int { - return $this->partie_gateway->findPartieInQueue(); + public function calculTpsMaXPartie( int $idPartie) : int { + $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); + foreach ($lesIdEnigmes as $idEnigme){ + $enigme = $this->enigme_gateway->findById($idEnigme->getIdEnigme())[0]; + $tpsMaxPartie += $enigme->getTempsMax(); } + return $tpsMaxPartie; + } + + public function findUserGroup() : int { + return $this->partie_gateway->findPartieInQueue(); + } public function launchGame() { From 967d3a5a329d5e99d8656dfb4906c242443087f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:07:10 +0100 Subject: [PATCH 03/11] Correction --- WEB/Model/UserModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 7ac9870f..b7046955 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -46,7 +46,7 @@ class UserModel public function calculTpsMaXPartie( int $idPartie) : int { $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); foreach ($lesIdEnigmes as $idEnigme){ - $enigme = $this->enigme_gateway->findById($idEnigme->getIdEnigme())[0]; + $enigme = $this->enigme_gateway->findById($idEnigme)[0]; $tpsMaxPartie += $enigme->getTempsMax(); } return $tpsMaxPartie; From b95ffb98ffcfffffb85570357d65326bbf44522d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:08:38 +0100 Subject: [PATCH 04/11] Correction --- WEB/Model/UserModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index b7046955..d4cae90c 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -47,7 +47,7 @@ class UserModel $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); foreach ($lesIdEnigmes as $idEnigme){ $enigme = $this->enigme_gateway->findById($idEnigme)[0]; - $tpsMaxPartie += $enigme->getTempsMax(); + $tpsMaxPartie += $enigme->getTempsDeResolution(); } return $tpsMaxPartie; } From a5f2c707bf6d638c2526ca14373883064e68c759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:12:14 +0100 Subject: [PATCH 05/11] Correction d'erreur --- WEB/Model/UserModel.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index d4cae90c..f345eab4 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -106,11 +106,12 @@ class UserModel } public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){ - $end_time = $_SESSION['tpsMaxPartie']; + $idPartie = $_SESSION['idPartie']; + $dateDebut = $this->partie_gateway->getDateDebut($idPartie); + $end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds'); $now = new DateTime(); $interval = $now->diff($end_time); $tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; - $idPartie = $_SESSION['idPartie']; $result = $this->resoudre_gateway->getMaxClassement($enigmeId, $idPartie); if ($result == 0){ $classement = 1; From eb341f9494511e1da0ea70d787dd6db734c2a2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:19:13 +0100 Subject: [PATCH 06/11] test --- WEB/View/src/pages/Multijoueur/GameEnd.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index aa7cc6f8..f09bd8af 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -21,6 +21,7 @@

Vous avez terminer toute les énimges.

Temps restant avant la fin de la partie :

modify('+'. $_SESSION['tpsMaxPartie'] .'seconds'); $now = new DateTime(); $interval = $now->diff($end_time); From b85b57cf3ff1ddcc72e3f744be1dd2435d68a827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:22:32 +0100 Subject: [PATCH 07/11] test --- WEB/Model/UserModel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index f345eab4..f13d3f76 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -45,6 +45,7 @@ class UserModel public function calculTpsMaXPartie( int $idPartie) : int { $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); + var_dump($lesIdEnigmes); foreach ($lesIdEnigmes as $idEnigme){ $enigme = $this->enigme_gateway->findById($idEnigme)[0]; $tpsMaxPartie += $enigme->getTempsDeResolution(); From d370898f6b9e70169fe1d0dc7591dc9dc6e85e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:33:01 +0100 Subject: [PATCH 08/11] =?UTF-8?q?Corection=20du=20calcul=20du=20temps=20de?= =?UTF-8?q?=20r=C3=A9solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Model/UserModel.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index f13d3f76..e572f807 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -45,7 +45,6 @@ class UserModel public function calculTpsMaXPartie( int $idPartie) : int { $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); - var_dump($lesIdEnigmes); foreach ($lesIdEnigmes as $idEnigme){ $enigme = $this->enigme_gateway->findById($idEnigme)[0]; $tpsMaxPartie += $enigme->getTempsDeResolution(); @@ -109,9 +108,8 @@ class UserModel public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){ $idPartie = $_SESSION['idPartie']; $dateDebut = $this->partie_gateway->getDateDebut($idPartie); - $end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds'); $now = new DateTime(); - $interval = $now->diff($end_time); + $interval = $now->diff($dateDebut); $tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; $result = $this->resoudre_gateway->getMaxClassement($enigmeId, $idPartie); if ($result == 0){ From 6364da5c04e4ae64d87c2d89a152ac2c50dbd163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:56:06 +0100 Subject: [PATCH 09/11] Calcul des points du joueurs en fin de partie --- WEB/Controller/ResoudreGateway.php | 10 ++++++++++ WEB/Controller/UserController.php | 1 + WEB/Model/UserModel.php | 17 +++++++++++++++++ WEB/View/src/pages/Multijoueur/GameEnd.php | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index 6b350325..1e1a3d02 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -282,4 +282,14 @@ class ResoudreGateway } return $results[0]['classement']; } + + public function getAllByPartieAndUtilisateur(string $mailUtilisateur, int $idPartie) : array{ + $query = "SELECT * FROM Resoudre + WHERE utilisateur=:utilisateur + AND partie=:partie"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "partie" => array($idPartie, SQLITE3_INTEGER))); + $results=$this->con->getResults(); + } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index ded2d137..7982ea95 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -244,6 +244,7 @@ class UserController $lastIndex = $model->getLastIndex($idPartie); if($lastIndex != 0 && $index == $lastIndex + 1){ $dateDebut = $model->getDateDebut($idPartie); + $points = $model->getPointsAtTheEnd($utilisateur->getEmail(), $idPartie); require($rep . $vues['gameEnd']); } else{ diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index e572f807..81e53437 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -173,4 +173,21 @@ class UserModel public function getDateDebut($idPartie) : DateTime{ return $this->partie_gateway->getDateDebut($idPartie); } + + public function getPointsAtTheEnd(string $mailUtilisateur, int $idPartie) : int{ + $points = 0; + $result = $this->resoudre_gateway->getAllByPartieAndUtilisateur($mailUtilisateur, $idPartie); + foreach ($result as $row){ + if ($row['classement'] == 1){ + $points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints(); + } + else if ($row['classement'] == 2){ + $points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.75; + } + else{ + $points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.5; + } + } + return $points; + } } \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index f09bd8af..73b7f5bc 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -19,9 +19,9 @@

Vous avez terminer toute les énimges.

+

Votre score est de : points.

Temps restant avant la fin de la partie :

modify('+'. $_SESSION['tpsMaxPartie'] .'seconds'); $now = new DateTime(); $interval = $now->diff($end_time); From 6566c967b4b4cb7a0100273feedafc71a1e41328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:57:38 +0100 Subject: [PATCH 10/11] Correction --- WEB/Controller/ResoudreGateway.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index 1e1a3d02..d80d4723 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -291,5 +291,6 @@ class ResoudreGateway "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), "partie" => array($idPartie, SQLITE3_INTEGER))); $results=$this->con->getResults(); + return $results; } } \ No newline at end of file From b1e604f91ad6da3ee3778d53d076ee7ea352de57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 18:00:24 +0100 Subject: [PATCH 11/11] =?UTF-8?q?L=C3=A9ger=20changement=20d'affichage=20d?= =?UTF-8?q?ans=20=20GameEnd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/View/src/pages/Multijoueur/GameEnd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index 73b7f5bc..d4e4a224 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -19,7 +19,7 @@

Vous avez terminer toute les énimges.

-

Votre score est de : points.

+

Votre score est de : points.

Temps restant avant la fin de la partie :

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