Compare commits

..

No commits in common. "ef49f35e2a53bab043ae09d72bb8b9e8960161ab" and "7a29d4d12d1e43b2925d76f4932d462661d1eee6" have entirely different histories.

4 changed files with 32 additions and 95 deletions

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 518 B

View File

@ -34,37 +34,9 @@ $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>
@ -111,24 +83,22 @@ $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;
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('');
}
let nb_cases = inputs.length
let index = 0
inputs.forEach(input => {
input.index = index++
input.onfocus = function(event) {
input.select();
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.onkeydown = function(event) {
switch (event.key) {
case "ArrowUp":
@ -145,27 +115,7 @@ $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

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