Merge pull request #22 from gnieark/dev

franglais dedicated to @moul
This commit is contained in:
Gnieark 2015-12-15 14:16:29 +01:00
commit 1b7c24f760
2 changed files with 23 additions and 6 deletions

View File

@ -25,8 +25,8 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
var bot2IdName = bot2.split("-");
document.getElementById('fightResult').innerHTML = '';
//dessiner les deux grilles
var tableAdv=createElem("table",{"id":"tblAdv","class":"battleshipGrid"});
var tableMe=createElem("table",{"id":"tblAdv","class":"battleshipGrid"});
var tableAdv=createElem("table",{"id":"tbl1","class":"battleshipGrid"});
var tableMe=createElem("table",{"id":"tbl2","class":"battleshipGrid"});
//ligne de titre
var trTitre1=createElem("tr");
var trTitre2=createElem("tr");
@ -43,8 +43,8 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
var trAdv=createElem("tr");
var trMe=createElem("tr");
for (var j=0; j < gridWidth ; j++){
var tdAdv=createElem("td",{"id":"adv" + i +"-" + j,"class": "empty"});
var tdMe=createElem("td",{"id":"me" + i +"-" + j,"class": "empty"});
var tdAdv=createElem("td",{"id":"bot1-" + i +"-" + j,"class": "empty"});
var tdMe=createElem("td",{"id":"bot2-" + i +"-" + j,"class": "empty"});
trAdv.appendChild(tdAdv);
trMe.appendChild(tdMe);
}
@ -63,7 +63,23 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
if(xhr.status == 200) {
//debug
//alert(xhr.responseText);
document.getElementById('logs').innerHTML = xhr.responseText;
try{
var grids = JSON.parse(xhr.responseText);
for( var player=1; player <= 2 ; player ++){
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;
}
}
}};
xhr.open("POST", '/Battleship', true);

View File

@ -5,4 +5,5 @@ td{min-width: 15px; height: 15px;}
.battleshipGrid{float: left; border-collapse:collapse; margin: 20px 20px 20px 20px;}
.battleshipGrid tr{}
.battleshipGrid tr td{border: 1px dashed green;}
.battleshipGrid tr th{text-align: center;}
.battleshipGrid tr th{text-align: center;}
.shipOn{background-color: black;}