From 351e8387bba89192817c30516440acc8580edab1 Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 1 May 2025 14:23:27 +0200 Subject: [PATCH] publier les mots entiers en ligne et colonne --- Grille.php | 17 ++++++++++++----- index.php | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Grille.php b/Grille.php index e8ced83..4ec09c9 100644 --- a/Grille.php +++ b/Grille.php @@ -20,13 +20,16 @@ class Grille implements Iterator, ArrayAccess { private $lettres_suivantes; private $positions; private $nb_positions; - public $mots_utilises; + public $lignes; + public $colonnes; public function __construct($hauteur, $largeur, $id = "") { $this->hauteur = $hauteur; $this->largeur = $largeur; $this->grille = array_fill(0, $hauteur, array_fill(0, $largeur, '')); + $this->lignes = []; + $this->colonnes = []; $this->lettres_suivantes = []; foreach ($hauteur == $largeur ? [$hauteur] : [$hauteur, $largeur] as $longueur) { @@ -53,7 +56,6 @@ class Grille implements Iterator, ArrayAccess { $this->nb_positions = count($this->positions); mt_srand($id == "" ? null : crc32($id)); - $this->mots_utilises = []; $this->grilles = $this->generateur(); } @@ -101,14 +103,19 @@ class Grille implements Iterator, ArrayAccess { $this->grille[$y][$x] = $lettre; if ($x == $this->largeur - 1) { - $this->mots_utilises[$y] = $this->get_ligne($y, $x); + $this->lignes[$y] = $this->get_ligne($y, $this->largeur); } else { - unset($this->mots_utilises[$y]); + unset($this->lignes[$y]); } if ($y == $this->hauteur - 1) { - if (in_array($this->get_colonne($x, $y), $this->mots_utilises)) { + $colonne = $this->get_colonne($x, $this->hauteur); + if (in_array($this->get_colonne($x, $y), $this->lignes)) { continue; + } else { + $this->colonnes[$x] = $colonne; } + } else { + unset($this->colonnes[$x]); } if ($i < $this->nb_positions) { diff --git a/index.php b/index.php index 333b3d5..9e6ab2d 100644 --- a/index.php +++ b/index.php @@ -42,10 +42,10 @@ $definitions = [ "colonnes" => [] ]; for ($y = 0; $y < $hauteur; $y++) { - $definitions["lignes"][$y] = $dico[$grille->get_ligne($y, $largeur)]; + $definitions["lignes"][$y] = $dico[$grille->lignes[$y]]; } for ($x = 0; $x < $largeur; $x++) { - $definitions["colonnes"][$x] = $dico[$grille->get_colonne($x, $hauteur)]; + $definitions["colonnes"][$x] = $dico[$grille->colonnes[$x]]; } ?>