From deb74b073e668a86b1cf7859508ffb757899bee3 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 14 Dec 2015 23:19:10 +0100 Subject: [PATCH] case ship outside map --- src/arenas/Battleship/act.php | 4 ++-- src/arenas/Battleship/functions.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index d948505..091e900 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -99,8 +99,8 @@ switch ($_POST['act']){ } //init grid - for($y = 0; $y < $height; $y++){ - for($x = 0; $x < $width; $x++){ + for($y = 0; $y < $postValues['gridHeight']; $y++){ + for($x = 0; $x < $postValues['gridWidth']; $x++){ $grid[$player][$y][$x]=0; } } diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php index 7f1e08e..deca0ce 100644 --- a/src/arenas/Battleship/functions.php +++ b/src/arenas/Battleship/functions.php @@ -54,9 +54,12 @@ function get_IA_Response($iaUrl,$postParams){ return htmlentities($output); } function place_ship_on_map($x1,$y1,$x2,$y2,$map){ - if (($x1 <> $x2) && ($y1 <> $y2)){ - return false; + if ((($x1 <> $x2) && ($y1 <> $y2)) + OR (!isset($map[$y1][$x1])) + OR (!isset($map[$y2][$x2]))){ + return false; } + if($x1 == $x2){ //horizontal ship