Compare commits

..

No commits in common. "c8ecb504ef311babc26656af26156af274717715" and "fcf7977e1a19a218591e3e7257ee1d526cf045dd" have entirely different histories.

5 changed files with 226 additions and 266 deletions

View File

@ -20,7 +20,7 @@ class Grille implements Iterator, ArrayAccess {
private $lettres_suivantes; private $lettres_suivantes;
private $positions; private $positions;
private $nb_positions; private $nb_positions;
public $mots_utilises; private $mots_utilises;
public function __construct($hauteur, $largeur, $id = "") public function __construct($hauteur, $largeur, $id = "")
{ {

View File

@ -35,9 +35,6 @@ foreach ($dico as $mot => $definition) {
$mots_de_n_lettres[$n] = []; $mots_de_n_lettres[$n] = [];
} }
$mots_de_n_lettres[$n][] = $mot; $mots_de_n_lettres[$n][] = $mot;
if (!empty($definitions)) {
$dico[$mot] = [$definitions[array_rand($definitions)]];
}
} }
function mots_espaces($longueur) function mots_espaces($longueur)

View File

@ -38,14 +38,14 @@ $largeur = filter_input(INPUT_GET, 'c', FILTER_VALIDATE_INT, [
$grille = new Grille($hauteur, $largeur, $id); $grille = new Grille($hauteur, $largeur, $id);
$grille->current(); $grille->current();
$definitions = [ $definitions = [
"lignes" => [], "horizontales" => [],
"colonnes" => [] "verticales" => []
]; ];
for ($y = 0; $y < $hauteur; $y++) { for ($y = 0; $y < $hauteur; $y++) {
$definitions["lignes"][$y] = $dico[$grille->get_ligne($y, $largeur)]; $definitions["horizontales"][$y] = $dico[$grille->get_ligne($y, $largeur)];
} }
for ($x = 0; $x < $largeur; $x++) { for ($x = 0; $x < $largeur; $x++) {
$definitions["colonnes"][$x] = $dico[$grille->get_colonne($x, $hauteur)]; $definitions["verticales"][$x] = $dico[$grille->get_colonne($x, $hauteur)];
} }
?> ?>
@ -107,10 +107,10 @@ for ($x = 0; $x < $largeur; $x++) {
<?php for ($x = 0; $x < $largeur; $x++): ?> <?php for ($x = 0; $x < $largeur; $x++): ?>
<td class="case <?= $grille[$y][$x] == " " ? "noire" : "blanche" ?>"> <td class="case <?= $grille[$y][$x] == " " ? "noire" : "blanche" ?>">
<?php if ($grille[$y][$x] == " "): ?> <?php if ($grille[$y][$x] == " "): ?>
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value=" " disabled /> <input type="text" maxlength="1" size="1" value=" " disabled />
<?php else: ?> <?php else: ?>
<input id="<?= chr($x + 65) . ($y + 1) ?>" 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="<?= "" . strip_tags(implode("\n→ ", $definitions["lignes"][$y])) . "\n↓ " . strip_tags(implode("\n↓ ", $definitions["colonnes"][$x])) ?>" /> title="<?= "Horizontalement\n" . strip_tags(implode("\n", $definitions["horizontales"][$y])) . "\nVerticalement\n" . strip_tags(implode("\n", $definitions["verticales"][$x])) ?>" />
<?php endif; ?> <?php endif; ?>
</td> </td>
<?php endfor; ?> <?php endfor; ?>
@ -121,37 +121,37 @@ for ($x = 0; $x < $largeur; $x++) {
<div class="definitions horizontales"> <div class="definitions horizontales">
<h2>Horizontalement</h2> <h2>Horizontalement</h2>
<ol> <ol>
<?php foreach ($definitions["lignes"] as $y => $definitions_ligne): ?> <?php for ($y = 0; $y < $hauteur; $y++): ?>
<li> <li>
<?php if (count($definitions_ligne) == 1): ?> <?php if (count($definitions["horizontales"][$y]) == 1): ?>
<?= $definitions_ligne[0] ?> <?= $definitions["horizontales"][$y][0] ?>
<?php else: ?> <?php else: ?>
<ol> <ol>
<?php foreach ($definitions_ligne as $definition) : ?> <?php foreach ($definitions["horizontales"][$y] as $definition) : ?>
<li><?= $definition ?></li> <li><?= $definition ?></li>
<?php endforeach ?> <?php endforeach ?>
</ol> </ol>
<?php endif ?> <?php endif ?>
</li> </li>
<?php endforeach; ?> <?php endfor; ?>
</ol> </ol>
</div> </div>
<div class="definitions verticales"> <div class="definitions verticales">
<h2>Verticalement</h2> <h2>Verticalement</h2>
<ol type="A"> <ol type="A">
<?php foreach ($definitions["colonnes"] as $x => $definitions_colonne): ?> <?php for ($x = 0; $x < $largeur; $x++): ?>
<li> <li>
<?php if (count($definitions_colonne) == 1): ?> <?php if (count($definitions["horizontales"][$x]) == 1): ?>
<?= $definitions_colonne[0] ?> <?= $definitions["horizontales"][$x][0] ?>
<?php else: ?> <?php else: ?>
<ol> <ol>
<?php foreach ($definitions_colonne as $definition) : ?> <?php foreach ($definitions["horizontales"][$x] as $definition) : ?>
<li><?= $definition ?></li> <li><?= $definition ?></li>
<?php endforeach ?> <?php endforeach ?>
</ol> </ol>
<?php endif ?> <?php endif ?>
</li> </li>
<?php endforeach; ?> <?php endfor; ?>
</ol> </ol>
</div> </div>
<?php else: ?> <?php else: ?>

View File

@ -1,44 +1,36 @@
async function sha256(text) { async function sha256(text) {
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const data = encoder.encode(text); const data = encoder.encode(text);
const hashBuffer = await crypto.subtle.digest("SHA-256", data); const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
} }
const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]')); const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]'));
let largeur = Number(colonnes.value); let largeur = Number(colonnes.value);
let nb_cases = inputs.length; let nb_cases = inputs.length;
let index = 0; let index = 0;
inputs.forEach((input) => {
inputs.forEach(input => {
input.index = index++; input.index = index++;
input.x = input.index % largeur;
input.y = Math.floor(input.index / largeur);
input.onfocus = function (event) { input.onfocus = function (event) {
for (li of document.querySelectorAll(`.definitions.horizontales > ol > li:nth-child(${input.y+1}), .definitions.verticales > ol > li:nth-child(${input.x+1})`)) {
li.classList.add("selectionee")
}
for (li of document.querySelectorAll(`.definitions.horizontales > ol > li:not(:nth-child(${input.y+1})), .definitions.verticales > ol > li:not(:nth-child(${input.x+1}))`)) {
li.classList.add("non-selectionee")
}
input.select(); input.select();
}; };
input.onkeydown = function (event) { input.onkeydown = function (event) {
next_input = null; next_input = null;
switch (event.key) { switch (event.key) {
case "ArrowUp": case 'ArrowUp':
next_input = inputs[(input.index - largeur + nb_cases) % nb_cases]; next_input = inputs[(input.index - largeur + nb_cases) % nb_cases];
break; break;
case "ArrowDown": case 'ArrowDown':
next_input = inputs[(input.index + largeur) % nb_cases]; next_input = inputs[(input.index + largeur) % nb_cases];
break; break;
case "ArrowLeft": case 'ArrowLeft':
next_input = inputs[(input.index - 1 + nb_cases) % nb_cases]; next_input = inputs[(input.index - 1 + nb_cases) % nb_cases];
break; break;
case "ArrowRight": case 'ArrowRight':
next_input = inputs[(input.index + 1) % nb_cases]; next_input = inputs[(input.index + 1) % nb_cases];
break; break;
} }
@ -52,28 +44,16 @@ inputs.forEach((input) => {
input.oninput = function (event) { input.oninput = function (event) {
this.value = this.value.toUpperCase(); this.value = this.value.toUpperCase();
if (!input.checkValidity()) { if (!input.checkValidity()) {
input.value = ""; input.value = '';
} }
if ( if (inputs.every(input => input.value.length == 1) && grilleForm.checkValidity()) {
inputs.every((input) => input.value.length == 1) && sha256(inputs.map(input => input.value).join('')).then(hash => {
grilleForm.checkValidity()
) {
sha256(inputs.map((input) => input.value).join("")).then((hash) => {
if (hash == solution_hashee.value) { if (hash == solution_hashee.value) {
if (confirm("Bravo ! \nUne nouvelle partie ?")) { if (confirm('Bravo ! \nUne nouvelle partie ?')) {
grilleForm.submit(); grilleForm.submit();
} }
} }
}); });
} }
}; };
input.onblur = function (event) {
for (li of document.querySelectorAll(`.definitions.horizontales > ol > li:nth-child(${input.y+1}), .definitions.verticales > ol > li:nth-child(${input.x+1})`)) {
li.classList.remove("selectionee")
}
for (li of document.querySelectorAll(`.definitions.horizontales > ol > li:not(:nth-child(${input.y+1})), .definitions.verticales > ol > li:not(:nth-child(${input.x+1}))`)) {
li.classList.remove("non-selectionee")
}
};
}); });

View File

@ -1,16 +1,14 @@
body { body {
margin: 0; margin: 0;
padding: 0; padding: 2rem 1rem;
background-color: white; background-color: white;
font-family: Times, "Times New Roman", Georgia, serif; font-family: Times, 'Times New Roman', Georgia, serif;
} }
form { form {
display: flex; display: flex;
padding: 1rem;
min-height: calc(100vh - 2rem);
flex-flow: column; flex-flow: column;
justify-content: space-between; min-height: calc(100vh - 4rem);
} }
h1 { h1 {
@ -20,7 +18,6 @@ h1 {
h1.large.width { h1.large.width {
display: inherit; display: inherit;
padding-top: 1rem;
} }
h1.small.width { h1.small.width {
@ -49,7 +46,8 @@ h2 {
justify-content: space-evenly; justify-content: space-evenly;
flex-wrap: wrap; flex-wrap: wrap;
height: max-content; height: max-content;
gap: 1em; flex-grow: 1;
align-items: center;
} }
.grille table { .grille table {
@ -101,7 +99,7 @@ h2 {
padding: 0; padding: 0;
text-align: center; text-align: center;
font-size: 1.2em; font-size: 1.2em;
font-family: "Comic Sans MS", "Comic Sans", sans; font-family: 'Comic Sans MS', 'Comic Sans', sans;
color: darkblue; color: darkblue;
background-color: white; background-color: white;
} }
@ -153,34 +151,18 @@ h2 {
text-wrap: nowrap; text-wrap: nowrap;
} }
.definitions.case ol.horizontales {
list-style-type: "→ ";
}
.definitions.case ol.verticales {
list-style-type: "↓ ";
}
.definitions li {
transition: opacity 0.3s;
}
.definitions li.non-selectionee {
opacity: 30%;
}
.erreur { .erreur {
text-align: center; text-align: center;
} }
button[type="submit"] { button[type='submit'] {
width: fit-content; width: fit-content;
margin: 0 auto; margin: 0 auto;
} }
button[type="submit"] { button[type='submit'] {
width: 100%; width: 100%;
margin: 1em auto 0 auto; margin: auto;
border: none; border: none;
background: none; background: none;
font-family: inherit; font-family: inherit;
@ -201,7 +183,12 @@ button[type="submit"]:active {
color: darkorchid; color: darkorchid;
} }
@media (max-width: 1024px) { @media (max-width: 1024px) {
body {
padding: 1.5rem 1rem;
}
h1.large.width { h1.large.width {
display: none; display: none;
} }
@ -214,6 +201,10 @@ button[type="submit"]:active {
line-height: 0.7; line-height: 0.7;
} }
form {
min-height: calc(100vh - 2rem);
}
.grille { .grille {
width: 100%; width: 100%;
margin: auto; margin: auto;
@ -224,7 +215,7 @@ button[type="submit"]:active {
} }
.definitions.horizontales { .definitions.horizontales {
order: inherit; order: inherit
} }
} }
@ -252,26 +243,18 @@ button[type="submit"]:active {
height: 2.5rem; height: 2.5rem;
} }
h2 { .definitions {
font-size: 1.2em; display: flex;
margin: 1em 0 0.5em 0; flex-flow: column;
} }
.definitions.horizontales, .definitions.horizontales,
.definitions.verticales { .definitions.verticales {
width: 100%; width: 100%;
} }
.definitions > ol {
margin: 0;
}
.definitions li.non-selectionee {
display: none;
}
} }
@media (max-device-width: 768px) and (orientation: landscape) { @media (max-device-width:768px) and (orientation: landscape) {
html { html {
-webkit-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%; -ms-text-size-adjust: 100%;