Calcul des points du joueurs en fin de partie
continuous-integration/drone/push Build is passing Details

ServeurDeTest
Noé GARNIER 2 years ago
parent d370898f6b
commit 6364da5c04

@ -282,4 +282,14 @@ class ResoudreGateway
} }
return $results[0]['classement']; 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();
}
} }

@ -244,6 +244,7 @@ class UserController
$lastIndex = $model->getLastIndex($idPartie); $lastIndex = $model->getLastIndex($idPartie);
if($lastIndex != 0 && $index == $lastIndex + 1){ if($lastIndex != 0 && $index == $lastIndex + 1){
$dateDebut = $model->getDateDebut($idPartie); $dateDebut = $model->getDateDebut($idPartie);
$points = $model->getPointsAtTheEnd($utilisateur->getEmail(), $idPartie);
require($rep . $vues['gameEnd']); require($rep . $vues['gameEnd']);
} }
else{ else{

@ -173,4 +173,21 @@ class UserModel
public function getDateDebut($idPartie) : DateTime{ public function getDateDebut($idPartie) : DateTime{
return $this->partie_gateway->getDateDebut($idPartie); 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;
}
} }

@ -19,9 +19,9 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<p>Vous avez terminer toute les énimges.</p> <p>Vous avez terminer toute les énimges.</p>
<p>Votre score est de : <?php echo $points ?>points.</p>
<p>Temps restant avant la fin de la partie :</p> <p>Temps restant avant la fin de la partie :</p>
<?php <?php
echo $_SESSION['tpsMaxPartie'];
$end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds'); $end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds');
$now = new DateTime(); $now = new DateTime();
$interval = $now->diff($end_time); $interval = $now->diff($end_time);

Loading…
Cancel
Save