This commit is contained in:
2026-01-10 22:11:50 +01:00
parent 02f17f78bf
commit b08e89490f
2 changed files with 21 additions and 36 deletions

View File

@@ -103,46 +103,20 @@ class Grille implements ArrayAccess
$mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur)); $mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
$this->definitions["horizontales"][$y] = []; $this->definitions["horizontales"][$y] = [];
foreach($mots as $mot) { foreach($mots as $mot) {
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]]; $definition = $this->dico[$mot["longueur"]][$mot["mot"]];
if (count($definitions)) { $definition["debut"] = $mot["debut"];
$definition = $definitions[mt_rand(0, count($definitions) - 1)]; $definition["fin"] = $mot["fin"];
if (is_array($definition)) { $this->definitions["horizontales"][$y][] = $definition;
foreach ($definition as $auteur => $def) {
$mot["definition"] = $def;
$mot["auteur"] = $auteur;
}
} else if (is_string($definition)) {
$mot["definition"] = $definition;
}
}
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++) { for ($x = 0; $x < $this->largeur; $x++) {
$mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur)); $mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
$this->definitions["verticales"][$x] = []; $this->definitions["verticales"][$x] = [];
foreach($mots as $mot) { foreach($mots as $mot) {
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]]; $definition = $this->dico[$mot["longueur"]][$mot["mot"]];
if (count($definitions)) { $definition["debut"] = $mot["debut"];
$definition = $definitions[mt_rand(0, count($definitions) - 1)]; $definition["fin"] = $mot["fin"];
if (is_array($definition)) { $this->definitions["verticales"][$x][] = $definition;
foreach ($definition as $auteur => $def) {
$mot["definition"] = $def;
$mot["auteur"] = $auteur;
}
} else if (is_string($definition)) {
$mot["definition"] = $definition;
}
}
if (isset($definitions["nb_mots"])) {
$mot["nb_mots"] = $definitions["nb_mots"];
}
unset($mot["mot"]);
$this->definitions["verticales"][$x][] = $mot;
} }
} }
$this->save($id); $this->save($id);

View File

@@ -29,8 +29,19 @@ function dico($longueur_max) {
} }
if (strlen($mot) > $longueur_max) continue; if (strlen($mot) > $longueur_max) continue;
$dico[strlen($mot)][$mot] = $definitions; $dico[strlen($mot)][$mot] = [];
if (count($definitions)) {
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (is_array($definition)) {
foreach ($definition as $auteur => $def) {
$dico[strlen($mot)][$mot]["definition"] = $def;
$dico[strlen($mot)][$mot]["auteur"] = $auteur;
}
} else if (is_string($definition)) {
$dico[strlen($mot)][$mot]["definition"] = $definition;
}
}
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots; if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
} }