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;
|
||||||
|
|
|
@ -82,30 +82,32 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
|
||||||
|
|
||||||
var xhr = Ajx();
|
var xhr = Ajx();
|
||||||
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
||||||
if(xhr.status == 200) {
|
if(xhr.status == 200) {
|
||||||
//debug
|
//debug
|
||||||
//alert(xhr.responseText);
|
//alert(xhr.responseText);
|
||||||
try{
|
try{
|
||||||
var grids = JSON.parse(xhr.responseText);
|
var grids = JSON.parse(xhr.responseText);
|
||||||
for( var player=1; player <= 2 ; player ++){
|
catch(e){
|
||||||
var p=createElem("p");
|
document.getElementById('logs').innerHTML = xhr.responseText;
|
||||||
p.innerHTML='Reponse joueurs:' + xhr.responseText;
|
return;
|
||||||
document.getElementById('logs').appendChild(p);
|
}
|
||||||
|
|
||||||
|
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 y=0; y < grids[player].length ; y++){
|
||||||
for (var x=0; x < grids[player][y].length ; x++){
|
for (var x=0; x < grids[player][y].length ; x++){
|
||||||
if (grids[player][y][x] == 1){
|
if (grids[player][y][x] == 1){
|
||||||
document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn";
|
document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(e){
|
|
||||||
document.getElementById('logs').innerHTML = xhr.responseText;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
xhr.open("POST", '/Battleship', true);
|
xhr.open("POST", '/Battleship', true);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user