Compare commits
4 Commits
ed5795a6cc
...
21e8f4134f
Author | SHA1 | Date | |
---|---|---|---|
21e8f4134f | |||
31a40a7e93 | |||
ad3992ac30 | |||
5feaa65955 |
3
400.php
3
400.php
@ -6,6 +6,9 @@
|
|||||||
<title>Requête incorrecte</title>
|
<title>Requête incorrecte</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<nav class="navbar mb-4">
|
||||||
|
<h1 class="display-4 text-center m-auto">Sudoku</h1>
|
||||||
|
</nav>
|
||||||
<main class="container my-4">
|
<main class="container my-4">
|
||||||
<header>
|
<header>
|
||||||
<h1 class="mb-4">Requête incorrecte</h1>
|
<h1 class="mb-4">Requête incorrecte</h1>
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Grid {
|
class Grid {
|
||||||
function __construct() {
|
function __construct($gridStr="") {
|
||||||
$this->boxes = array();
|
$this->boxes = array();
|
||||||
$this->rows = array_fill(0, 9, array());
|
$this->rows = array_fill(0, 9, array());
|
||||||
$this->columns = array_fill(0, 9, array());
|
$this->columns = array_fill(0, 9, array());
|
||||||
@ -74,6 +74,12 @@
|
|||||||
if ($box != $neighbour && !in_array($neighbour, $box->neighbourhood))
|
if ($box != $neighbour && !in_array($neighbour, $box->neighbourhood))
|
||||||
$box->neighbourhood[] = $neighbour;
|
$box->neighbourhood[] = $neighbour;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($gridStr) {
|
||||||
|
$this->import($gridStr);
|
||||||
|
} else {
|
||||||
|
$this->generate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function import($gridStr) {
|
function import($gridStr) {
|
||||||
|
16
index.php
16
index.php
@ -1,18 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
require("classes.php");
|
require("classes.php");
|
||||||
session_start();
|
|
||||||
|
global $sudokuGridSolutions;
|
||||||
|
if (!isset($sudokuGridSolutions)) $sudokuGridSolutions = array();
|
||||||
|
|
||||||
$fullUrl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"];
|
$fullUrl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"];
|
||||||
$dirUrl = dirname($fullUrl);
|
$dirUrl = dirname($fullUrl);
|
||||||
$currentGrid = strip_tags($_SERVER['QUERY_STRING']);
|
$currentGrid = strip_tags($_SERVER['QUERY_STRING']);
|
||||||
|
|
||||||
if (preg_match("/^[1-9.]{81}$/", $currentGrid)) {
|
if (preg_match("/^[1-9.]{81}$/", $currentGrid)) {
|
||||||
if (!array_key_exists($currentGrid, $_SESSION)) {
|
if (!array_key_exists($currentGrid, $sudokuGridSolutions)) {
|
||||||
$grid = new Grid();
|
$grid = new Grid($currentGrid);
|
||||||
$grid->import($currentGrid);
|
$sudokuGridSolutions[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
|
||||||
$_SESSION[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
|
|
||||||
}
|
}
|
||||||
switch($_SESSION[$currentGrid]) {
|
switch($sudokuGridSolutions[$currentGrid]) {
|
||||||
case -1:
|
case -1:
|
||||||
$warning = "Cette grille contient des doublons.";
|
$warning = "Cette grille contient des doublons.";
|
||||||
break;
|
break;
|
||||||
@ -27,10 +28,9 @@
|
|||||||
require("sudoku.php");
|
require("sudoku.php");
|
||||||
} else {
|
} else {
|
||||||
$grid = new Grid();
|
$grid = new Grid();
|
||||||
$grid->generate();
|
|
||||||
$gridAsString = $grid->toString();
|
$gridAsString = $grid->toString();
|
||||||
$newGridUrl = "$dirUrl/?$gridAsString";
|
$newGridUrl = "$dirUrl/?$gridAsString";
|
||||||
$_SESSION[$gridAsString] = 1;
|
$sudokuGridSolutions[$gridAsString] = 1;
|
||||||
if ($currentGrid) {
|
if ($currentGrid) {
|
||||||
require("400.php");
|
require("400.php");
|
||||||
} else {
|
} else {
|
||||||
|
12
sudoku.js
12
sudoku.js
@ -35,12 +35,12 @@ window.onload = function() {
|
|||||||
for (let box of row.getElementsByTagName('input')) {
|
for (let box of row.getElementsByTagName('input')) {
|
||||||
let regionId = rowId - rowId % 3 + Math.floor(columnId / 3)
|
let regionId = rowId - rowId % 3 + Math.floor(columnId / 3)
|
||||||
if (!box.disabled) {
|
if (!box.disabled) {
|
||||||
box.onfocus = onfocus
|
box.onfocus = onfocus
|
||||||
box.oninput = oninput
|
box.oninput = oninput
|
||||||
box.onblur = onblur
|
box.onblur = onblur
|
||||||
box.onclick = onclick
|
box.onclick = onclick
|
||||||
box.onmouseenter = onmouseenter
|
box.onmouseenter = onmouseenter
|
||||||
box.onmouseleave = onmouseleave
|
box.onmouseleave = onmouseleave
|
||||||
}
|
}
|
||||||
box.oncontextmenu = oncontextmenu
|
box.oncontextmenu = oncontextmenu
|
||||||
box.rowId = rowId
|
box.rowId = rowId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user