petites améliorations

This commit is contained in:
Adrien MALINGREY 2025-04-24 21:41:50 +02:00
parent e234dd0ff8
commit 65e31d71c6
4 changed files with 18 additions and 9 deletions

View File

@ -3,7 +3,7 @@
include_once "dico.php"; include_once "dico.php";
const MIN_LETTRES = 0; const MIN_LETTRES = 1;
class Grille { class Grille {
@ -42,7 +42,6 @@ class Grille {
} }
public function get_ligne($l, $longueur = 100) { public function get_ligne($l, $longueur = 100) {
$longueur = min($longueur, $this->largeur);
$ligne = ""; $ligne = "";
for ($i = 0; $i < $longueur; $i++) { for ($i = 0; $i < $longueur; $i++) {
$ligne .= $this->grille[$l][$i]; $ligne .= $this->grille[$l][$i];
@ -57,7 +56,6 @@ class Grille {
} }
public function get_colonne($c, $longueur = 100) { public function get_colonne($c, $longueur = 100) {
$longueur = min($longueur, $this->hauteur);
$colonne = ""; $colonne = "";
for ($i = 0; $i < $longueur; $i++) { for ($i = 0; $i < $longueur; $i++) {
$colonne .= $this->grille[$i][$c]; $colonne .= $this->grille[$i][$c];

View File

@ -24,7 +24,7 @@ foreach ($dico as $mot => $definition) {
function fisherYatesShuffle(&$items, $seed) function fisherYatesShuffle(&$items, $seed)
{ {
@mt_srand($seed); mt_srand($seed);
for ($i = count($items) - 1; $i > 0; $i--) for ($i = count($items) - 1; $i > 0; $i--)
{ {
$j = @mt_rand(0, $i); $j = @mt_rand(0, $i);
@ -32,6 +32,7 @@ function fisherYatesShuffle(&$items, $seed)
$items[$i] = $items[$j]; $items[$i] = $items[$j];
$items[$j] = $tmp; $items[$j] = $tmp;
} }
mt_srand();
} }
function mots_espaces($max, $min=0, $seed=0) { function mots_espaces($max, $min=0, $seed=0) {

View File

@ -3,6 +3,10 @@
const HAUTEUR_PAR_DEFAUT = 6; const HAUTEUR_PAR_DEFAUT = 6;
const LARGEUR_PAR_DEFAUT = 6; const LARGEUR_PAR_DEFAUT = 6;
echo "<!--\n";
var_dump($_SERVER);
echo "\n-->\n";
$id = filter_input(INPUT_GET, 'grille', FILTER_VALIDATE_REGEXP, [ $id = filter_input(INPUT_GET, 'grille', FILTER_VALIDATE_REGEXP, [
"options" => [ "options" => [
@ -11,7 +15,7 @@ $id = filter_input(INPUT_GET, 'grille', FILTER_VALIDATE_REGEXP, [
]); ]);
if (!$id) { if (!$id) {
$_GET["grille"] = uniqid(); $_GET["grille"] = uniqid();
header("Location: " . $_SERVER['PHP_SELF'] . "?" . http_build_query($_GET)); header("Location: " . $_SERVER['REQUEST_URI'] . "?" . http_build_query($_GET));
exit; exit;
} }

View File

@ -19,20 +19,26 @@ inputs.forEach(input => {
}; };
input.onkeydown = function (event) { input.onkeydown = function (event) {
next_input = null;
switch (event.key) { switch (event.key) {
case 'ArrowUp': case 'ArrowUp':
inputs[(input.index - largeur + nb_cases) % nb_cases].focus(); next_input = inputs[(input.index - largeur + nb_cases) % nb_cases];
break; break;
case 'ArrowDown': case 'ArrowDown':
inputs[(input.index + largeur) % nb_cases].focus(); next_input = inputs[(input.index + largeur) % nb_cases];
break; break;
case 'ArrowLeft': case 'ArrowLeft':
inputs[(input.index - 1 + nb_cases) % nb_cases].focus(); next_input = inputs[(input.index - 1 + nb_cases) % nb_cases];
break; break;
case 'ArrowRight': case 'ArrowRight':
inputs[(input.index + 1) % nb_cases].focus(); next_input = inputs[(input.index + 1) % nb_cases];
break; break;
} }
if (next_input) {
next_input.focus();
next_input.select();
event.preventDefault();
}
}; };
input.oninput = function (event) { input.oninput = function (event) {