From 9cc74ed9cad6e9d853e282a256b42570be334efd Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 14 Dec 2015 22:05:50 +0100 Subject: [PATCH] verif nbe bateaux --- src/arenas/Battleship/act.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index dd55199..5576a05 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -87,10 +87,31 @@ switch ($_POST['act']){ echo $bot1['name']." a fait une réponse non conforme, il perd.".$anwserPlayer1; save_battle('Battleship',$bot1['name'],$bot2['name'],2); } - //vérifier si'il y a le bon nombre de bateaux - print_r($boatsPlayer1); - //echo $anwserPlayer1; die; + + //vérifier si'il y a le bon nombre de bateaux + $nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], + $postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']); + foreach($boatsPlayer1 as $boat){ + list($startCoord,$endCoord) = explode("-",$boat); + list($xStart,$yStart)=explode(",",$startCoord); + list($xEnd,$yEnd)=explode(",",$endCoord); + if($xStart == $xEnd){ + $long=abs($yStart - $yEnd); + }else{ + $long=abs($xStart - $xEnd); + } + $nbBoatsIwant[$long]-=1; + } + foreach($nbBoatsIwant as $nb){ + if($nb <> 0){ + echo $bot1['name']." n'a pas placé correctement ses bateaux. Il perd"; + save_battle('Battleship',$bot1['name'],$bot2['name'],2); + } + } + + + die; break; default: