diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 704ef52..49a266b 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -126,7 +126,7 @@ switch ($_POST['act']){ $nbBoatsIwant[$long]-=1; $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); if(!$grid[$player]){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd
".$anwserPlayer." ".$xStart.$yStart.$xEnd.$yEnd."
"; + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd."; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ @@ -137,7 +137,7 @@ switch ($_POST['act']){ } foreach($nbBoatsIwant as $nb){ if($nb <> 0){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd. sa réponse:
".$anwserPlayer."
"; + echo $currentBot['name']." n'a pas placé le bon nombre de bateaux. Il perd."; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ @@ -148,7 +148,7 @@ switch ($_POST['act']){ } } - $_SESSION['grids']=$grid; + //$_SESSION['grids']=$grid; echo json_encode($grid); die; die; diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index dfaa90a..2c41adf 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -82,30 +82,32 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ - if(xhr.status == 200) { - //debug - //alert(xhr.responseText); - try{ - var grids = JSON.parse(xhr.responseText); - for( var player=1; player <= 2 ; player ++){ - var p=createElem("p"); - p.innerHTML='Reponse joueurs:' + xhr.responseText; - document.getElementById('logs').appendChild(p); + if(xhr.status == 200) { + //debug + //alert(xhr.responseText); + try{ + var grids = JSON.parse(xhr.responseText); + catch(e){ + document.getElementById('logs').innerHTML = xhr.responseText; + return; + } + + for( var player=1; player <= 2 ; player ++){ + var p=createElem("p"); + p.innerHTML='Reponse joueurs:' + xhr.responseText; + document.getElementById('logs').appendChild(p); - for (var y=0; y < grids[player].length ; y++){ - for (var x=0; x < grids[player][y].length ; x++){ - if (grids[player][y][x] == 1){ - document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; - } - } - } - } - - } - catch(e){ - document.getElementById('logs').innerHTML = xhr.responseText; - - } + for (var y=0; y < grids[player].length ; y++){ + for (var x=0; x < grids[player][y].length ; x++){ + if (grids[player][y][x] == 1){ + document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; + } + } + } + } + + } + } }}; xhr.open("POST", '/Battleship', true);