diff --git a/app.js b/app.js index 8568dc8..0ca4f32 100644 --- a/app.js +++ b/app.js @@ -34,6 +34,14 @@ window.onload = function() { } rowId++ } + + let savedGame = localStorage[location.href] + if (savedGame) { + boxes.forEach((box, i) => { + if (!box.disabled && savedGame[i] != '.') box.value = savedGame[i] + }) + } + boxes.forEach(box => { box.neighbourhood = new Set(rows[box.rowId].concat(columns[box.columnId]).concat(regions[box.regionId])) box.neighbourhood.delete(box) @@ -59,8 +67,18 @@ window.onload = function() { function searchCandidatesOf(box) { box.candidates = new Set(VALUES) box.neighbourhood.forEach(neighbour => box.candidates.delete(neighbour.value)) - if (!box.disabled) - box.title = box.candidates.size + (box.candidates.size <= 1 ? " possibilité [Clic-droit]" : " possibilités [Clic-droit]") + if (!box.disabled) { + switch (box.candidates.size) { + case 0: + box.title = "Aucune possibilité !" + break + case 1: + box.title = "1 possibilité [Clic-droit]" + break + default: + box.title = box.candidates.size + " possibilités [Clic-droit]" + } + } } function onfocus() { @@ -74,7 +92,7 @@ function onfocus() { } function oninput() { - history.push({box: this, value: this.previousValue, placeholder: this.previousPlaceholder}) + history.push({box: this, value: this.previousValue || "", placeholder: this.previousPlaceholder || ""}) undoButton.disabled = false if (penStyle != "pencil") { refresh(this) @@ -92,6 +110,8 @@ function undo() { } function refresh(box) { + localStorage[location.href] = boxes.map(box => box.value || ".").join("") + box.neighbourhood.concat([box]).forEach(neighbour => { searchCandidatesOf(neighbour) neighbour.setCustomValidity("") @@ -239,7 +259,7 @@ function oncontextmenu(event) { }) } else { li = document.createElement("li") - li.innerText = "Aucun chiffre possible" + li.innerText = "Aucune possibilité !" li.classList.add("error") contextMenu.appendChild(li) } diff --git a/favicon.php b/favicon.php deleted file mode 100644 index 47c5879..0000000 --- a/favicon.php +++ /dev/null @@ -1,61 +0,0 @@ - $value) { - $x++; - if ($i % 3 == 0) $x++; - if ($i % 9 == 0) { - $y++; - $x = 2; - } - if ($i % 27 == 0) $y++; - if ($value == UNKNOWN) $pixelColor = $unknown; - else $pixelColor = $known; - ImageSetPixel($icon, $x, $y, $pixelColor); - } - } else { - $boxSize = floor(($size-5) / 9); - $start = 1; - $end = 9*$boxSize + 2; - for ($y=0; $y < $size; $y += 3*$boxSize + 1) - ImageLine($icon, $start, $y, $end, $y, $gridBorder); - for ($x=0; $x < $size; $x += 3*$boxSize +1) - ImageLine($icon, $x, $start, $x, $end, $gridBorder); - $x = 0; - $y = 0; - $boxSizeMinusOne = $boxSize - 1; - foreach(str_split($gridStr) as $i => $value) { - if ($i % 3 == 0) $x++; - if ($i % 27 == 0) $y++; - if ($value == UNKNOWN) $color = $unknown; - else $color = $known; - imagefilledrectangle($icon, $x, $y, $x+$boxSizeMinusOne, $y+$boxSizeMinusOne, $color); - $x += $boxSize; - if ($i % 9 == 8) { - $y += $boxSize; - $x = 0; - } - } - } - imagepng($icon); -?> diff --git a/nginx-example.conf b/nginx-example.conf index fb12511..b5a5295 100644 --- a/nginx-example.conf +++ b/nginx-example.conf @@ -19,5 +19,5 @@ location @sudoku { include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME sudoku/game.php; + fastcgi_param SCRIPT_FILENAME sudoku/sudoku.php; } diff --git a/style.css b/style.css index 31601c5..5e82add 100644 --- a/style.css +++ b/style.css @@ -78,6 +78,7 @@ section, div, footer { height: 2.5rem; font-size: 1.5rem; border: 0; + border-radius: 0; padding: 0; text-align: center; transition: background 0.5s; diff --git a/game.php b/sudoku.php similarity index 64% rename from game.php rename to sudoku.php index 3e2e95a..73baeea 100644 --- a/game.php +++ b/sudoku.php @@ -6,15 +6,36 @@ if (preg_match("#^[1-9.]{81}$#", $gridStr)) { ?> - +