js reduce try catch
This commit is contained in:
parent
5cf7dd2615
commit
c4fa2974cf
|
@ -126,7 +126,7 @@ switch ($_POST['act']){
|
||||||
$nbBoatsIwant[$long]-=1;
|
$nbBoatsIwant[$long]-=1;
|
||||||
$grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]);
|
$grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]);
|
||||||
if(!$grid[$player]){
|
if(!$grid[$player]){
|
||||||
echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd<pre>".$anwserPlayer." ".$xStart.$yStart.$xEnd.$yEnd."</pre>";
|
echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd.";
|
||||||
if($player==1){
|
if($player==1){
|
||||||
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
|
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
|
||||||
}else{
|
}else{
|
||||||
|
@ -137,7 +137,7 @@ switch ($_POST['act']){
|
||||||
}
|
}
|
||||||
foreach($nbBoatsIwant as $nb){
|
foreach($nbBoatsIwant as $nb){
|
||||||
if($nb <> 0){
|
if($nb <> 0){
|
||||||
echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd. sa réponse: <pre>".$anwserPlayer."</pre>";
|
echo $currentBot['name']." n'a pas placé le bon nombre de bateaux. Il perd.";
|
||||||
if($player==1){
|
if($player==1){
|
||||||
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
|
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
|
||||||
}else{
|
}else{
|
||||||
|
@ -148,7 +148,7 @@ switch ($_POST['act']){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION['grids']=$grid;
|
//$_SESSION['grids']=$grid;
|
||||||
echo json_encode($grid); die;
|
echo json_encode($grid); die;
|
||||||
|
|
||||||
die;
|
die;
|
||||||
|
|
|
@ -87,6 +87,11 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
|
||||||
//alert(xhr.responseText);
|
//alert(xhr.responseText);
|
||||||
try{
|
try{
|
||||||
var grids = JSON.parse(xhr.responseText);
|
var grids = JSON.parse(xhr.responseText);
|
||||||
|
catch(e){
|
||||||
|
document.getElementById('logs').innerHTML = xhr.responseText;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for( var player=1; player <= 2 ; player ++){
|
for( var player=1; player <= 2 ; player ++){
|
||||||
var p=createElem("p");
|
var p=createElem("p");
|
||||||
p.innerHTML='Reponse joueurs:' + xhr.responseText;
|
p.innerHTML='Reponse joueurs:' + xhr.responseText;
|
||||||
|
@ -102,11 +107,8 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(e){
|
|
||||||
document.getElementById('logs').innerHTML = xhr.responseText;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}};
|
}};
|
||||||
xhr.open("POST", '/Battleship', true);
|
xhr.open("POST", '/Battleship', true);
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user