diff --git a/happy.gif b/happy.gif new file mode 100644 index 0000000..58cf1bd Binary files /dev/null and b/happy.gif differ diff --git a/index.php b/index.php new file mode 100644 index 0000000..a08afc8 --- /dev/null +++ b/index.php @@ -0,0 +1,161 @@ + isset($_POST['sizeX']) ? $_POST['sizeX'] : 10, + 'sizeY' => isset($_POST['sizeY']) ? $_POST['sizeY'] : 10, + 'bombs' => isset($_POST['bombs']) ? $_POST['bombs'] : 10 +); + +if(!isset($_SESSION['cases']) || isset($_POST['Reset'])){ + $_SESSION['cases'] = array_fill(0, $_SESSION['config']['sizeX'], array_fill(0, $_SESSION['config']['sizeY'], array('bomb' => false, 'visible' => false))); + + for ($i=0; $i < $_SESSION['config']['bombs']; $i++) { + $x; $y; + do{ + $x = rand(0, count($_SESSION['cases'])-1); + $y = rand(0, count($_SESSION['cases'][$x])-1); + }while($_SESSION['cases'][$x][$y]['bomb']); + $_SESSION['cases'][$x][$y]['bomb'] = true; + } +} + +$alive = true; + +if(isset($_POST['xPos']) && isset($_POST['yPos'])){ + if(!$_SESSION['cases'][$_POST['xPos']][$_POST['yPos']]['visible']){ + if($_SESSION['cases'][$_POST['xPos']][$_POST['yPos']]['bomb']){ + $alive = false; + for ($x=0; $x < count($_SESSION['cases']); $x++){ + for ($y=0; $y < count($_SESSION['cases'][$x]); $y++){ + $_SESSION['cases'][$x][$y]['visible'] = true; + } + } + }else{ + set_visible_rec($_POST['xPos'], $_POST['yPos']); + } + } +} + +$win = true; +for ($x=0; $x < count($_SESSION['cases']) && $win; $x++){ + for ($y=0; $y < count($_SESSION['cases'][$x]) && $win; $y++){ + if(!$_SESSION['cases'][$x][$y]['bomb'] && !$_SESSION['cases'][$x][$y]['visible']) $win = false; + } +} + +function get_bomb_count($x, $y){ + $count = 0; + for ($i=-1; $i <= 1; $i++) { + for ($j=-1; $j <= 1; $j++) { + if(isset($_SESSION['cases'][$x+$i][$y+$j]) && $_SESSION['cases'][$x+$i][$y+$j]['bomb']) $count++; + } + } + return $count; +} + +function set_visible_rec($x, $y){ + if(!$_SESSION['cases'][$x][$y]['visible']){ + $_SESSION['cases'][$x][$y]['visible'] = true; + if(get_bomb_count($x, $y) == 0){ + for ($i=-1; $i <= 1; $i++) { + for ($j=-1; $j <= 1; $j++) { + if(isset($_SESSION['cases'][$x+$i][$y+$j])) set_visible_rec($x+$i, $y+$j); + } + } + } + } +} +?> + + + + + + + Demineur + + +

Demineur

+ + + + + + + + + +
+ 0){ + echo ''.$count.''; + } + } + }else{ + ?> +
+ + + +
+ +
+
+
+

+ + +

+

+ + +

+

+ + +

+ +
+
+ + \ No newline at end of file diff --git a/ok.gif b/ok.gif new file mode 100644 index 0000000..b6df3ed Binary files /dev/null and b/ok.gif differ diff --git a/sad.gif b/sad.gif new file mode 100644 index 0000000..141395f Binary files /dev/null and b/sad.gif differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..047cae3 --- /dev/null +++ b/style.css @@ -0,0 +1,34 @@ +* { + margin: 0; + padding: 0; +} + +body { + text-align: center; +} + +#reset { + height: 2em; + width: auto; +} + +#cases { + border-collapse: collapse; + margin: auto; +} +#cases td { + background-color: #ddd; + border: 1px solid black; + width: 2em; + height: 2em; + text-align: center; + font-weight: bold; +} +#cases form, #cases input { + width: 100%; + height: 100%; +} +#cases input { + border: 4px outset grey; + box-sizing: border-box; +} \ No newline at end of file