From cd3946aeebcae4265ca621529ae0795fd5462fba Mon Sep 17 00:00:00 2001 From: adrien Date: Fri, 5 Dec 2025 21:22:52 +0100 Subject: [PATCH] =?UTF-8?q?r=C3=A9f=C3=A9renement=20des=20labels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Grille.php | 37 +++--- index.php | 354 ++++++++++++++++++++++++++++------------------------- 2 files changed, 207 insertions(+), 184 deletions(-) diff --git a/Grille.php b/Grille.php index f4d3883..9bba935 100644 --- a/Grille.php +++ b/Grille.php @@ -20,19 +20,20 @@ function explode_pos(string $separator, string $string): array { $mots = []; $mot = ""; $longueur = strlen($string); + $debut = 0; for ($i = 0; $i < $longueur; $i++) { $lettre = $string[$i]; if ($lettre == $separator) { - $mots[$i] = $mot; + $mots[] = ["mot" => $mot, "debut" => $debut, "fin" => $i - 1, "longueur" => $i - $debut]; $mot = ""; + $debut = $i + 1; } else { $mot .= $lettre; } } - $mots[$i] = $mot; - + $mots[] = ["mot" => $mot, "debut" => $debut, "fin" => $longueur - 1, "longueur" => $longueur - $debut]; return $mots; } @@ -101,29 +102,35 @@ class Grille implements ArrayAccess for ($y = 0; $y < $this->hauteur; $y++) { $mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur)); $this->definitions["horizontales"][$y] = []; - foreach($mots as $fin => $mot) { - $definitions = $this->dico[strlen($mot)][$mot]; + foreach($mots as $mot) { + $definitions = $this->dico[$mot["longueur"]][$mot["mot"]]; if (count($definitions)) { $definition = $definitions[mt_rand(0, count($definitions) - 1)]; - if (isset($definitions["nb_mots"])) { - $definition["nb_mots"] = $definitions["nb_mots"]; - } - $this->definitions["horizontales"][$y][$fin] = $definition; + if (isset($definition[DEFINITION])) $mot["definition"] = $definition[DEFINITION]; + if (isset($definition[AUTEUR])) $mot["auteur"] = $definition[AUTEUR]; } + if (isset($definitions["nb_mots"])) { + $mot["nb_mots"] = $definitions["nb_mots"]; + } + unset($mot["mot"]); + $this->definitions["horizontales"][$y][] = $mot; } } for ($x = 0; $x < $this->largeur; $x++) { $mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur)); $this->definitions["verticales"][$x] = []; - foreach($mots as $fin => $mot) { - $definitions = $this->dico[strlen($mot)][$mot]; + foreach($mots as $mot) { + $definitions = $this->dico[$mot["longueur"]][$mot["mot"]]; if (count($definitions)) { $definition = $definitions[mt_rand(0, count($definitions) - 1)]; - if (isset($definitions["nb_mots"])) { - $definition["nb_mots"] = $definitions["nb_mots"]; - } - $this->definitions["verticales"][$x][$fin] = $definition; + if (isset($definition[DEFINITION])) $mot["definition"] = $definition[DEFINITION]; + if (isset($definition[AUTEUR])) $mot["auteur"] = $definition[AUTEUR]; } + if (isset($definitions["nb_mots"])) { + $mot["nb_mots"] = $definitions["nb_mots"]; + } + unset($mot["mot"]); + $this->definitions["verticales"][$x][] = $mot; } } $this->save($id); diff --git a/index.php b/index.php index 5785e1a..6f8f073 100644 --- a/index.php +++ b/index.php @@ -1,13 +1,16 @@ 1){ + if (isset($definition["nb_mots"]) && $definition["nb_mots"] > 1) { $nb_mots = $definition["nb_mots"]; $nb_mots = " ($nb_mots mots)"; } else { $nb_mots = ""; } - if (array_key_exists(AUTEUR, $definition)) { - $auteur = $definition[AUTEUR]; + if (isset($definition["auteur"])) { + $auteur = $definition["auteur"]; $auteur = " $auteur"; } else { $auteur = ""; } - return ucfirst($definition[DEFINITION]) . $nb_mots . $auteur; + return ucfirst($definition["definition"]) . $nb_mots . $auteur; } -function mot_courant($mots, $position) { - foreach ($mots as $fin => $mot) { - if ($position <= $fin) return $mot; +function definition_courante($definitions, $position) { + foreach ($definitions as $id => $definition) { + if ($position <= $definition["fin"]) + return [$id, $definition]; } return []; } - -function debuts($definitions) { - $debut = 0; - $retour = []; - foreach ($definitions as $fin => $definition) { - if ($fin - $debut > 1) { - $retour[$debut] = $definition; - } - $debut = $fin + 1; - } - return $retour; -} ?> - - - πŸ„ΌπŸ„ΎπŸ…ƒπŸ…‚β–£πŸ„²πŸ…πŸ„ΎπŸ„ΈπŸ…‚πŸ„΄πŸ…‚ - - - - - - - - - - - - - - - - "/> - + + + πŸ„ΌπŸ„ΎπŸ…ƒπŸ…‚β–£πŸ„²πŸ…πŸ„ΎπŸ„ΈπŸ…‚πŸ„΄πŸ…‚ + + + + + + + + + + + + + + + + " /> + - -
-

- - - - - - - - - - - - - - - - - - - - - - - - - -
M
croisΓ©s
t
s
-
-

-

Motsβ– croisΓ©s

-
- + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
M
croisΓ©s
t
s
+
+

+

Motsβ– croisΓ©s

+
+
- - - + + + - - - - - - - - - - - - + + + + + + + + + + + +
- - - definitions["horizontales"][$y], $x); - $definition_verticale = mot_courant($grille->definitions["verticales"][$x], $y); - if (isset($definition_horizontale[0])) $title[0] = "β†’ " . $definition_horizontale[0]; - if (isset($definition_horizontale[1])) $title[0] .= " (" . $definition_horizontale[1] . ")"; - if (isset($definition_verticale[0])) $title[1] = "↓ " . $definition_verticale[0]; - if (isset($definition_verticale[1])) $title[1] .= " (" . $definition_verticale[1] . ")"; - $title = htmlspecialchars(implode("\n", $title)); - ?> - -
+ + +definitions["horizontales"][$y], $x); + [$iddv, $definition_verticale] = definition_courante($grille->definitions["verticales"][$x], $y); + if (isset($definition_horizontale["definition"])) + $title[0] = "β†’ " . $definition_horizontale["definition"]; + if (isset($definition_horizontale["nb_mots"])) + $title[0] .= " (" . $definition_horizontale["nb_mots"] . ")"; + if (isset($definition_horizontale["auteur"])) + $title[0] .= " (" . $definition_horizontale["auteur"] . ")"; + if (isset($definition_verticale["definition"])) + $title[1] = "↓ " . $definition_verticale["definition"]; + if (isset($definition_verticale["nb_mots"])) + $title[0] .= " (" . $definition_verticale["nb_mots"] . ")"; + if (isset($definition_verticale["auteur"])) + $title[1] .= " (" . $definition_verticale["auteur"] . ")"; + $title = htmlspecialchars(implode("\n", $title)); +?> + " + data-iddv="" + /> +

Horizontalement

    - definitions["horizontales"] as $y => $definitions): - $definitions = debuts($definitions); - ?> -
  1. - - - - -
      - $definition) : ?> - - -
    - - -
  2. - +definitions["horizontales"] as $y => $definitions): + $definitions = array_filter($definitions, function($definition) { + return isset($definition["definition"]); + }); +?> +
  3. + + + $definition): ?> + + + +
      + $definition): ?> + + +
    + + +
  4. +

Verticalement

    - definitions["verticales"] as $x => $definitions): - $definitions = debuts($definitions); - ?> -
  1. - - - - -
      - $definition) : ?> - - -
    - - -
  2. - +definitions["verticales"] as $x => $definitions): + $definitions = array_filter($definitions, function($definition) { + return isset($definition["definition"]); + }); +?> +
  3. + + + $definition): ?> + + + +
      + $definition): ?> + + +
    + + +
  4. +
- +

Erreur de gΓ©nΓ©ration de la grille

- -
- -
- - - de - value="" min="" max=""/> - lignes et - value="" min="" max=""/> - colonnes -
- + +
- - - +
+ + + de + + value="" min="" max="" /> + lignes et + + value="" min="" max="" /> + colonnes +
+ + + + + \ No newline at end of file