Premier pas : fin de partie
continuous-integration/drone/push Build is passing Details

ServeurDeTest
Noé GARNIER 2 years ago
parent 2def56ba67
commit 8b1e0fc1d8

@ -19,9 +19,6 @@ class PartieGateway
}
}
/**
* @param array $listeUtilisateur
*/
public function partieInQueueExists(): bool
{
$query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0";
@ -43,22 +40,6 @@ class PartieGateway
else
return $results[0]['max(id)'];
}
// public function creerPartieMulti(int $max, array $tabEnigme) : Partie{
// $partie=PartieFactory::createPartieMulti($max+1,$tabEnigme);
// $query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)";
// $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER)));
// if (count($partie->getListeEnigme()) != 0) {
// foreach ($partie->getListeEnigme() as $Enigme) {
// $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
// $this->con->executeQuery($query, array(
// ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
// ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
// )
// );
// }
// }
// return $partie;
// }
public function rejoindrePartieMulti(int $idPartieInQueue, array $tabEnigme): Partie
{
@ -305,6 +286,19 @@ class PartieGateway
}
return $lesJoueurs;
}
public function getLesIdEnigmes($idPartie){
$query = "SELECT enigme 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 findEnigmeIdInPartieWithIndex($idPartie, $index) : int{
$query = "SELECT * FROM Contenir WHERE partie = :idPartie AND indexEnigme = :index";
@ -341,6 +335,13 @@ class PartieGateway
$date = new DateTime ($results[0]['dateDebut']);
return $date;
}
public function endGame(int $idPartie){
$query = "UPDATE Participer SET etat = 1 WHERE partie = :idPartie";
$this->con->executeQuery($query, array(
"idPartie" => array($idPartie, SQLITE3_INTEGER)
)
);
}
public function showAll(): void
{
$query = "SELECT * FROM Partie";

@ -243,6 +243,9 @@ class UserController
$index = $_GET['index'];
$lastIndex = $model->getLastIndex($idPartie);
if($lastIndex != 0 && $index == $lastIndex + 1){
if ($model->checkGameIsEnd($idPartie)){
$this->endGame();
}
$dateDebut = $model->getDateDebut($idPartie);
$points = $model->getPointsAtTheEnd($utilisateur->getEmail(), $idPartie);
require($rep . $vues['lobbyEnd']);
@ -324,4 +327,32 @@ class UserController
require($rep . $vues['erreur']);
}
}
public function checkGameIsEnd(){
try {
global $rep, $vues, $error;
$model = new UserModel();
$idPartie = $_SESSION['idPartie'];
$result = $model->checkGameIsEnd($idPartie);
echo $result;
}
catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
// A appeler après avoir vérifié que la partie est finie
public function endGame(){
try {
global $rep, $vues, $error;
$model = new UserModel();
$idPartie = $_SESSION['idPartie'];
$model->endGame($idPartie);
require ($rep . $vues['gameEnd']);
}
catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
}

@ -192,4 +192,19 @@ class UserModel
}
return $points;
}
public function checkGameIsEnd(int $idPartie) : bool{
$lesMailJoueurs = $this->partie_gateway->getLesMailJoueurs($idPartie);
$lesIdEnigmes = $this->partie_gateway->getLesIdEnigmes($idPartie);
foreach ($lesMailJoueurs as $mail){
foreach ($lesIdEnigmes as $idEnigme){
if ($this->resoudre_gateway->checkEnigmeIsEnded($mail, $idEnigme) == false){
return false;
}
}
}
return true;
}
public function endGame(int $idPartie) {
$this->partie_gateway->endGame($idPartie);
}
}

@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<title>Scripted</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS v5.2.1 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
</head>
<body>
<p> Coucou </p>
<!-- Bootstrap JavaScript Libraries -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"
integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js"
integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous">
</script>
</body>
</html>
Loading…
Cancel
Save