Commits (5)
......@@ -17,6 +17,7 @@ class PartieSquadro {
// Constructeur : Crée une nouvelle partie avec un premier joueur
public function __construct(JoueurSquadro $playerOne) {
$this->joueurs[self::PLAYER_ONE] = $playerOne;
$this->joueurs[self::PLAYER_TWO] = null;
$this->joueurActif = self::PLAYER_ONE;
$this->plateau = new PlateauSquadro();
}
......@@ -62,7 +63,7 @@ class PartieSquadro {
'partieId' => $this->partieId,
'joueurs' => [
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,
'gameStatus' => $this->gameStatus,
......@@ -71,8 +72,13 @@ class PartieSquadro {
}
// 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);
$joueurs = $data['joueurs'];
$partie = new PartieSquadro($joueurs[self::PLAYER_ONE]);
if (isset($joueurs[self::PLAYER_TWO])) {
......
......@@ -137,14 +137,14 @@ class SquadroUIGenerator
public static function entete(string $title): string
{
$entete = '<!DOCTYPE html>
<html lang="fr" class="has-background-grey-light">
<html lang="fr" class="has-background-white-ter">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Squadro</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css">
</head>
<body >
<body>
<section class="hero is-link">
<div class="hero-body has-text-centered">
<p class="title is-spaced"> Squadro </p>
......@@ -256,6 +256,7 @@ class SquadroUIGenerator
* Génère la page d'accueil de la salle de jeux (Home).
*
* @return string Le code HTML de la page Home.
* @throws Exception
*/
public static function pageHome(JoueurSquadro $player): string
{
......@@ -266,14 +267,62 @@ class SquadroUIGenerator
$allGames = PDOSquadro::getAllPartieSquadro();
$allPlayerGames = PDOSquadro::getAllPartieSquadroByPlayerName($player->getNomJoueur());
$html .= '<div class="container has-text-centered">
<form action="traiteActionSquadro.php" method="post">
<button class="button" type="submit" name="action" value="creerPartie">Créer une nouvelle partie</button>
</form>
$html .= '
<div class="card has-text-centered">
<header class = "card-header"><h2 class="card-header-title">Créer une partie</h2> </header>
<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 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
$html .= self::pied();
......