Compare commits

..

3 Commits

Author SHA1 Message Date
ef49f35e2a title style 2025-04-24 17:32:31 +02:00
1689b54570 title and hash 2025-04-24 17:25:50 +02:00
c4ab6cb09d favicon 2025-04-24 14:26:19 +02:00
4 changed files with 95 additions and 32 deletions

View File

@ -130,4 +130,12 @@ class Grille {
unset($this->mots_utilises[$mot_col]);
}
}
public function hash() {
$string = "";
foreach ($this->grille as $ligne) {
$string .= implode("", $ligne);
}
return hash('sha256', $string);
}
}

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

View File

@ -34,9 +34,37 @@ $grille = new Grille($hauteur, $largeur);
<meta charset="utf-8">
<title>Mots croisés</title>
<link rel="stylesheet" href="style.css">
<link rel="icon" href="favicon.ico">
</head>
<body>
<h1>
<table>
<tbody>
<tr>
<td colspan="2"></td>
<td>M</td>
</tr>
<tr>
<td>c</td>
<td>r</td>
<td>o</td>
<td>i</td>
<td>s</td>
<td>é</td>
<td>s</td>
</tr>
<tr>
<td colspan="2"></td>
<td>t</td>
</tr>
<tr>
<td colspan="2"></td>
<td>s</td>
</tr>
</tbody>
</table>
</h1>
<form id="grilleForm" class="grille">
<table>
<tr>
@ -83,22 +111,24 @@ $grille = new Grille($hauteur, $largeur);
<script>
const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]'))
let largeur = <?= $largeur ?>;
let nb_cases = inputs.length
let index = 0
let nb_cases = inputs.length;
let index = 0;
async function sha256(text) {
const encoder = new TextEncoder();
const data = encoder.encode(text);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
inputs.forEach(input => {
input.index = index++
input.onfocus = function() {
this.select();
}
input.oninput = function() {
this.value = this.value.toUpperCase()
if (!input.checkValidity()) {
input.value = ""
}
if (grilleForm.checkValidity()) {
window.setTimeout(() => alert("Grille validée !"), 100)
}
input.onfocus = function(event) {
input.select();
}
input.onkeydown = function(event) {
switch (event.key) {
case "ArrowUp":
@ -115,7 +145,27 @@ $grille = new Grille($hauteur, $largeur);
break;
}
}
input.oninput = function(event) {
this.value = this.value.toUpperCase()
if (!input.checkValidity()) {
input.value = ""
}
if (grilleForm.checkValidity()) {
sha256(inputs.map(input => input.value).join("")).then(
hash => {
if (hash == "<?= $grille->hash() ?>") {
alert("Bravo ! Vous avez trouvé la grille !")
if (confirm("Bravo ! \nUne nouvelle partie ?")) {
location = "."
}
}
}
)
}
}
})
// <?= $grille->hash() ?>
</script>
</html>

View File

@ -7,9 +7,18 @@ body {
justify-content: space-evenly;
}
.grille {
margin: 2rem auto;
width: unset;
h1 table {
margin: auto;
line-height: 0.7;
}
h1 td {
width: 0.7em;
}
h1, h2 {
font-variant-caps: petite-caps;
text-align: center;
}
.grille table {
@ -17,35 +26,36 @@ body {
margin: 0 auto;
}
tr:nth-of-type(2) td {
.grille tr:nth-of-type(2) td {
border-top: 3px solid black;
}
tr:last-of-type td {
.grille tr:last-of-type td {
border-bottom: 3px solid black;
}
td:first-of-type {
.grille td:first-of-type {
border-left: 3px solid black;
}
td:last-child {
.grille td:last-child {
border-right: 3px solid black;
}
td {
.grille td {
border: 1px solid black;
padding: 2px;
}
th, td {
.grille th,
.grille td {
width: 30px;
height: 30px;
text-align: center;
}
.case.noire {
.grille .case.noire {
background-color: black;
}
input {
.grille input {
width: 100%;
height: 100%;
border: none;
@ -54,7 +64,7 @@ input {
font-size: 1.2em;
}
input[disabled] {
.grille input[disabled] {
background-color: black;
}
@ -68,11 +78,6 @@ input[disabled] {
width: 45%;
}
.definitions h2 {
font-variant-caps: petite-caps;
text-align: center;
}
li::marker {
.definitions li::marker {
font-weight: bold;
}