From fcf7977e1a19a218591e3e7257ee1d526cf045dd Mon Sep 17 00:00:00 2001 From: adrien Date: Wed, 30 Apr 2025 15:47:09 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9finitions=20en=20infobulle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Grille.php | 26 +++++++++++++++++++------- index.php | 32 ++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Grille.php b/Grille.php index ee6322c..c0e5d7d 100644 --- a/Grille.php +++ b/Grille.php @@ -12,7 +12,7 @@ function melanger_cles($tableau) } -class Grille implements ArrayAccess { +class Grille implements Iterator, ArrayAccess { public $grille; public $hauteur; public $largeur; @@ -96,17 +96,17 @@ class Grille implements ArrayAccess { $lettres_suivantes_ligne, $lettres_suivantes_colonne )); - + foreach ($lettres_communes as $lettre => $_) { $this->grille[$y][$x] = $lettre; if ($x == $this->largeur - 1) { - $mots_utilises[$y] = $this->get_ligne($y, $x); + $this->mots_utilises[$y] = $this->get_ligne($y, $x); } else { - unset($mots_utilises[$y]); + unset($this->mots_utilises[$y]); } if ($y == $this->hauteur - 1) { - if (in_array($this->get_colonne($x, $y), $mots_utilises)) { + if (in_array($this->get_colonne($x, $y), $this->mots_utilises)) { continue; } } @@ -128,12 +128,24 @@ class Grille implements ArrayAccess { return hash('sha256', $string); } - public function current() + public function current(): mixed { return $this->grilles->current(); } - public function valid() + public function key(): mixed { + return $this->grilles->key(); + } + + public function next(): void { + $this->grilles->next(); + } + + public function rewind(): void { + $this->grilles->rewind(); + } + + public function valid(): bool { return $this->grilles->valid(); } diff --git a/index.php b/index.php index 1a67598..9affcc7 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ current(); - +$definitions = [ + "horizontales" => [], + "verticales" => [] +]; +for ($y = 0; $y < $hauteur; $y++) { + $definitions["horizontales"][$y] = $dico[$grille->get_ligne($y, $largeur)]; +} +for ($x = 0; $x < $largeur; $x++) { + $definitions["verticales"][$x] = $dico[$grille->get_colonne($x, $hauteur)]; +} ?> @@ -100,7 +109,8 @@ $grille->current(); - + " /> @@ -113,12 +123,11 @@ $grille->current();
  1. - get_ligne($y, $largeur)] ?> - - + +
      - get_ligne($y, $largeur)] as $definition) : ?> +
    @@ -132,12 +141,11 @@ $grille->current();
    1. - get_colonne($x, $hauteur)] ?> - - + +
        - get_colonne($x, $hauteur)] as $definition) : ?> +