Commits (5)
...@@ -17,6 +17,7 @@ class PartieSquadro { ...@@ -17,6 +17,7 @@ class PartieSquadro {
// Constructeur : Crée une nouvelle partie avec un premier joueur // Constructeur : Crée une nouvelle partie avec un premier joueur
public function __construct(JoueurSquadro $playerOne) { public function __construct(JoueurSquadro $playerOne) {
$this->joueurs[self::PLAYER_ONE] = $playerOne; $this->joueurs[self::PLAYER_ONE] = $playerOne;
$this->joueurs[self::PLAYER_TWO] = null;
$this->joueurActif = self::PLAYER_ONE; $this->joueurActif = self::PLAYER_ONE;
$this->plateau = new PlateauSquadro(); $this->plateau = new PlateauSquadro();
} }
...@@ -62,7 +63,7 @@ class PartieSquadro { ...@@ -62,7 +63,7 @@ class PartieSquadro {
'partieId' => $this->partieId, 'partieId' => $this->partieId,
'joueurs' => [ 'joueurs' => [
self::PLAYER_ONE => $this->joueurs[self::PLAYER_ONE]->getNomJoueur(), self::PLAYER_ONE => $this->joueurs[self::PLAYER_ONE]->getNomJoueur(),
self::PLAYER_TWO => $this->joueurs[self::PLAYER_TWO]->getNomJoueur() ?? null self::PLAYER_TWO => ($this->joueurs[self::PLAYER_TWO] != null)?$this->joueurs[self::PLAYER_TWO]->getNomJoueur() : ""
], ],
'joueurActif' => $this->joueurActif, 'joueurActif' => $this->joueurActif,
'gameStatus' => $this->gameStatus, 'gameStatus' => $this->gameStatus,
...@@ -71,8 +72,13 @@ class PartieSquadro { ...@@ -71,8 +72,13 @@ class PartieSquadro {
} }
// Restaure une partie à partir d'un JSON // Restaure une partie à partir d'un JSON
public static function fromJson(string $json, array $joueurs): PartieSquadro {
/**
* @throws Exception
*/
public static function fromJson(string $json): PartieSquadro {
$data = json_decode($json, true); $data = json_decode($json, true);
$joueurs = $data['joueurs'];
$partie = new PartieSquadro($joueurs[self::PLAYER_ONE]); $partie = new PartieSquadro($joueurs[self::PLAYER_ONE]);
if (isset($joueurs[self::PLAYER_TWO])) { if (isset($joueurs[self::PLAYER_TWO])) {
......
...@@ -137,14 +137,14 @@ class SquadroUIGenerator ...@@ -137,14 +137,14 @@ class SquadroUIGenerator
public static function entete(string $title): string public static function entete(string $title): string
{ {
$entete = '<!DOCTYPE html> $entete = '<!DOCTYPE html>
<html lang="fr" class="has-background-grey-light"> <html lang="fr" class="has-background-white-ter">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Squadro</title> <title>Squadro</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css">
</head> </head>
<body > <body>
<section class="hero is-link"> <section class="hero is-link">
<div class="hero-body has-text-centered"> <div class="hero-body has-text-centered">
<p class="title is-spaced"> Squadro </p> <p class="title is-spaced"> Squadro </p>
...@@ -256,6 +256,7 @@ class SquadroUIGenerator ...@@ -256,6 +256,7 @@ class SquadroUIGenerator
* Génère la page d'accueil de la salle de jeux (Home). * Génère la page d'accueil de la salle de jeux (Home).
* *
* @return string Le code HTML de la page Home. * @return string Le code HTML de la page Home.
* @throws Exception
*/ */
public static function pageHome(JoueurSquadro $player): string public static function pageHome(JoueurSquadro $player): string
{ {
...@@ -266,14 +267,62 @@ class SquadroUIGenerator ...@@ -266,14 +267,62 @@ class SquadroUIGenerator
$allGames = PDOSquadro::getAllPartieSquadro(); $allGames = PDOSquadro::getAllPartieSquadro();
$allPlayerGames = PDOSquadro::getAllPartieSquadroByPlayerName($player->getNomJoueur()); $allPlayerGames = PDOSquadro::getAllPartieSquadroByPlayerName($player->getNomJoueur());
$html .= '<div class="container has-text-centered"> $html .= '
<form action="traiteActionSquadro.php" method="post"> <div class="card has-text-centered">
<button class="button" type="submit" name="action" value="creerPartie">Créer une nouvelle partie</button> <header class = "card-header"><h2 class="card-header-title">Créer une partie</h2> </header>
</form> <form class="card-content" action="traiteActionSquadro.php" method="post">
<button class="button is-large is-centered" type="submit" name="action" value="creerPartie">+</button>
</form>
</div>
<div class="card has-text-centered"> <header class = "card-header"><h2 class="card-header-title">Continuer une partie</h2> </header> ';
foreach ($allPlayerGames as $game) {
if ($game['gamestatus'] === 'waitingForPlayer') {
$data = PartieSquadro::fromJson($game['json']);
$playeroneName = $data->getNomJoueurActif();
$html .= '<form class="card-content" action="traiteActionSquadro.php" method="post"> <span>En attente de: ' . $playeroneName . '</span>';
$html .= '<input type="hidden" name="partieid" value="' . $game['partieid'] . '>"</input>';
$html .= '<button class="button" type="submit" name="action" value="continuerPartie"> > </button></form>';
}
}
$html .= '
</div> </div>
<div class="card has-text-centered"> <header class = "card-header"><h2 class="card-header-title has-text-centered">Rejoindre une partie</h2> </header> ';
foreach ($allGames as $game) {
if ($game['gamestatus'] === 'constructed' && $game['playerone'] !== $_SESSION['player']->id) {
$data = PartieSquadro::fromJson($game['json']);
$playeroneName = $data->getJoueurs()[PartieSquadro::PLAYER_ONE]->getNomJoueur();
$html .= '<form class="card-content" action="traiteActionSquadro.php" method="post"> <span>Partie créée par: ' . $playeroneName . "</span>";
$html .= '<input type="hidden" name="partieid" value="' . $game['partieid'] . '>"</input>';
$html .= '<button class="button is-small" type="submit" name="action" value="rejoindrePartie"> > </button></form>';
}
}
$html .= '</div> <div class="card has-text-centered"> <header class = "card-header"><h2 class="card-header-title"">Consulter une partie terminée</h2> </header> ';
foreach ($allGames as $game) {
if ($game['gamestatus'] === 'finished') {
$data = PartieSquadro::fromJson($game['json']);
$nomGagnant = $data->getNomJoueurActif();
$html .= '<form class="card-content" action="traiteActionSquadro.php" method="post"> <span>Partie gagnée par: ' . $nomGagnant . "</span> ";
$html .= '<input type="hidden" name="partieid" value="' . $game['partieid'] . '>"</input>';
$html .= '<button class="button is-small" type="submit" name="action" value="continuerPartie"> > </button></form>';
}
}
$html .= '</div >
<div class="container">
<form action = "traiteActionSquadro.php" method = "post" >
<button class="button is-large is-danger" type = "submit" name = "action" value ="quitter">Quitter</button>
</form>
</div> </div>';
if (isset($_SESSION['partieCreer']) && $_SESSION['partieCreer']) {
$html .= '
<div class ="notification is-info has-text-centered">
<button class="delete" aria-label="delete"></button>
<strong>Une partie a été créée !</strong>
</div >';
$_SESSION['partieCreer'] = false;
}
';
// Pied de page // Pied de page
$html .= self::pied(); $html .= self::pied();
......