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{ ?>