This commit is contained in:
Gnieark 2016-06-19 20:46:15 +02:00
parent 4ac9cd769b
commit 97add3146f

View File

@ -78,7 +78,6 @@ switch($message['action']){
case "init": case "init":
//file_put_contents(__DIR__."/log.txt",print_r($_POST,true)); //file_put_contents(__DIR__."/log.txt",print_r($_POST,true));
$wantedVars=array( $wantedVars=array(
'match_id' => false, //false-> string ; true -> integer
'opponent' => false, 'opponent' => false,
'width' => true, 'width' => true,
'height' => true, 'height' => true,
@ -90,10 +89,10 @@ switch($message['action']){
'ship6' => true 'ship6' => true
); );
foreach($wantedVars as $key => $shouldBeInteger){ foreach($wantedVars as $key => $shouldBeInteger){
if(($shouldBeInteger) && (!is_numeric($_POST[$key]))){ if(($shouldBeInteger) && (!is_numeric($message['board'][$key]))){
echo "var is not numeric"; die; echo "var is not numeric"; die;
} }
$$key=$_POST[$key]; $$key=$message['board'][$key];
} }
if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){ if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){
echo "parametre incorrect"; die; echo "parametre incorrect"; die;
@ -200,7 +199,7 @@ switch($message['action']){
case 'left': case 'left':
$shipsCoords[]=$x.",".$y."-".($x - $shipWidth + 1).",".$y; $shipsCoords[]=$x.",".$y."-".($x - $shipWidth + 1).",".$y;
$map= place_ship_on_map($x,$y,$x - $shipWidth + 1 ,$y,$map); $map= place_ship_on_map($x,$y,$x - $shipWidth + 1 ,$y,$map);
break; break;$message['board']
case 'right': case 'right':
$shipsCoords[]=$x.",".$y."-".($x + $shipWidth - 1 ).",".$y; $shipsCoords[]=$x.",".$y."-".($x + $shipWidth - 1 ).",".$y;
$map= place_ship_on_map($x,$y,$x + $shipWidth -1 ,$y,$map); $map= place_ship_on_map($x,$y,$x + $shipWidth -1 ,$y,$map);
@ -210,12 +209,11 @@ switch($message['action']){
} }
} }
echo json_encode($shipsCoords);
file_put_contents(__DIR__."/log.txt",json_encode($shipsCoords),FILE_APPEND); echo json_encode(array("name" => "gnieark", "boats" => $shipsCoords);
break; break;
case "fight": case "fight":
//for debog arena //for debog arena
file_put_contents(__DIR__."/log.txt",print_r($_POST,true),FILE_APPEND);
echo rand(0,$_POST['width'] -1).",".rand(0,$_POST['height'] -1); echo rand(0,$_POST['width'] -1).",".rand(0,$_POST['height'] -1);