diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 66b75e1..39d2f65 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -1,5 +1,28 @@ 0; $i--){ + $var='nbShipsSize'.$i; + if($$var > 0){ + $longestShip=$$var; + break; + } + } + if( (!isset($longestShip)) + OR(($longestShip > $gridWidth) && ($longestShip > $gridHeight)) + ){ + return false; + } + return true; +} + + function place_ship_on_map($x1,$y1,$x2,$y2,$map){ if ((($x1 <> $x2) && ($y1 <> $y2)) OR (!isset($map[$y1][$x1])) @@ -68,13 +91,20 @@ switch($_POST['act']){ if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){ echo "parametre incorrect"; die; } + + if(!is_it_possible_to_place_ships_on_grid($width,$height,$ship1,$ship2,$ship3,$ship4,$ship5,$ship6)){ + echo "I don't want play this game"; + die; + } + + $map=array(); //construire une grille for($i=0; $i < $width; $i++){ for($j=0; $j < $height; $j++){ $map[$j][$i]=0; } - } + } $shipsCoords=array(); @@ -132,9 +162,7 @@ switch($_POST['act']){ break; } } - - - + $directions=array(); if($top){ $directions[]='top'; @@ -173,7 +201,7 @@ switch($_POST['act']){ } } - print_r($map); + //print_r($map); echo json_encode($shipsCoords); break; default: