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 @@ <?php -//ini_set('display_errors', '1'); -//ini_set('error_reporting', E_ALL); +ini_set('display_errors', '1'); +ini_set('error_reporting', E_ALL); if (!isset($_GET["grille"])) { @@ -37,7 +37,16 @@ $largeur = filter_input(INPUT_GET, 'c', FILTER_VALIDATE_INT, [ $grille = new Grille($hauteur, $largeur, $id); $grille->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)]; +} ?> <!DOCTYPE HTML> @@ -100,7 +109,8 @@ $grille->current(); <?php if ($grille[$y][$x] == " "): ?> <input type="text" maxlength="1" size="1" value=" " disabled /> <?php else: ?> - <input type="text" maxlength="1" size="1" pattern="[A-Z]" placeholder="<?= $grille[$y][$x] ?>" /> + <input type="text" maxlength="1" size="1" pattern="[A-Z]" placeholder="<?= $grille[$y][$x] ?>" + title="<?= "Horizontalement\n" . strip_tags(implode("\n", $definitions["horizontales"][$y])) . "\nVerticalement\n" . strip_tags(implode("\n", $definitions["verticales"][$x])) ?>" /> <?php endif; ?> </td> <?php endfor; ?> @@ -113,12 +123,11 @@ $grille->current(); <ol> <?php for ($y = 0; $y < $hauteur; $y++): ?> <li> - <?php $definitions = $dico[$grille->get_ligne($y, $largeur)] ?> - <?php if (count($definitions) == 1): ?> - <?= $definitions[0] ?> + <?php if (count($definitions["horizontales"][$y]) == 1): ?> + <?= $definitions["horizontales"][$y][0] ?> <?php else: ?> <ol> - <?php foreach ($dico[$grille->get_ligne($y, $largeur)] as $definition) : ?> + <?php foreach ($definitions["horizontales"][$y] as $definition) : ?> <li><?= $definition ?></li> <?php endforeach ?> </ol> @@ -132,12 +141,11 @@ $grille->current(); <ol type="A"> <?php for ($x = 0; $x < $largeur; $x++): ?> <li> - <?php $definitions = $dico[$grille->get_colonne($x, $hauteur)] ?> - <?php if (count($definitions) == 1): ?> - <?= $definitions[0] ?> + <?php if (count($definitions["horizontales"][$x]) == 1): ?> + <?= $definitions["horizontales"][$x][0] ?> <?php else: ?> <ol> - <?php foreach ($dico[$grille->get_colonne($x, $hauteur)] as $definition) : ?> + <?php foreach ($definitions["horizontales"][$x] as $definition) : ?> <li><?= $definition ?></li> <?php endforeach ?> </ol>