js debug output
This commit is contained in:
parent
f45994ebda
commit
145ab319f5
|
@ -21,81 +21,85 @@ function createElem(type,attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){
|
function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){
|
||||||
var bot1IdName = bot1.split("-");
|
var bot1IdName = bot1.split("-");
|
||||||
var bot2IdName = bot2.split("-");
|
var bot2IdName = bot2.split("-");
|
||||||
document.getElementById('fightResult').innerHTML = '';
|
document.getElementById('fightResult').innerHTML = '';
|
||||||
//dessiner les deux grilles
|
//dessiner les deux grilles
|
||||||
var tableAdv=createElem("table",{"id":"tbl1","class":"battleshipGrid"});
|
var tableAdv=createElem("table",{"id":"tbl1","class":"battleshipGrid"});
|
||||||
var tableMe=createElem("table",{"id":"tbl2","class":"battleshipGrid"});
|
var tableMe=createElem("table",{"id":"tbl2","class":"battleshipGrid"});
|
||||||
//ligne de titre
|
//ligne de titre
|
||||||
var trTitre1=createElem("tr");
|
var trTitre1=createElem("tr");
|
||||||
var trTitre2=createElem("tr");
|
var trTitre2=createElem("tr");
|
||||||
var tdTitre1=createElem("th",{"colspan":gridWidth});
|
var tdTitre1=createElem("th",{"colspan":gridWidth});
|
||||||
var tdTitre2=createElem("th",{"colspan":gridWidth});
|
var tdTitre2=createElem("th",{"colspan":gridWidth});
|
||||||
tdTitre1.innerHTML = bot1IdName[1];
|
tdTitre1.innerHTML = bot1IdName[1];
|
||||||
tdTitre2.innerHTML = bot2IdName[1];
|
tdTitre2.innerHTML = bot2IdName[1];
|
||||||
trTitre1.appendChild(tdTitre1);
|
trTitre1.appendChild(tdTitre1);
|
||||||
tableAdv.appendChild(trTitre1);
|
tableAdv.appendChild(trTitre1);
|
||||||
trTitre2.appendChild(tdTitre2);
|
trTitre2.appendChild(tdTitre2);
|
||||||
tableMe.appendChild(trTitre2);
|
tableMe.appendChild(trTitre2);
|
||||||
|
|
||||||
for (var i=0; i < gridHeight ; i++){
|
for (var i=0; i < gridHeight ; i++){
|
||||||
var trAdv=createElem("tr");
|
var trAdv=createElem("tr");
|
||||||
var trMe=createElem("tr");
|
var trMe=createElem("tr");
|
||||||
for (var j=0; j < gridWidth ; j++){
|
for (var j=0; j < gridWidth ; j++){
|
||||||
var tdAdv=createElem("td",{"id":"bot1-" + i +"-" + j,"class": "empty"});
|
var tdAdv=createElem("td",{"id":"bot1-" + i +"-" + j,"class": "empty"});
|
||||||
var tdMe=createElem("td",{"id":"bot2-" + i +"-" + j,"class": "empty"});
|
var tdMe=createElem("td",{"id":"bot2-" + i +"-" + j,"class": "empty"});
|
||||||
trAdv.appendChild(tdAdv);
|
trAdv.appendChild(tdAdv);
|
||||||
trMe.appendChild(tdMe);
|
trMe.appendChild(tdMe);
|
||||||
}
|
}
|
||||||
tableAdv.appendChild(trAdv);
|
tableAdv.appendChild(trAdv);
|
||||||
tableMe.appendChild(trMe);
|
tableMe.appendChild(trMe);
|
||||||
}
|
|
||||||
document.getElementById('fightResult').appendChild(tableAdv);
|
|
||||||
document.getElementById('fightResult').appendChild(tableMe);
|
|
||||||
var divLogs=createElem("div",{"id":"logs"});
|
|
||||||
document.getElementById('fightResult').appendChild(divLogs);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 ++){
|
|
||||||
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('fightResult').appendChild(tableAdv);
|
||||||
document.getElementById('logs').innerHTML = xhr.responseText;
|
document.getElementById('fightResult').appendChild(tableMe);
|
||||||
|
var divLogs=createElem("div",{"id":"logs"});
|
||||||
}
|
document.getElementById('fightResult').appendChild(divLogs);
|
||||||
}
|
|
||||||
}};
|
|
||||||
xhr.open("POST", '/Battleship', true);
|
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
var xhr = Ajx();
|
||||||
xhr.send(
|
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
||||||
'act=initGame&bot1=' + bot1IdName[0]
|
if(xhr.status == 200) {
|
||||||
+ '&bot2=' + bot2IdName[0]
|
//debug
|
||||||
+ '&gridWidth=' + gridWidth
|
//alert(xhr.responseText);
|
||||||
+ '&gridHeight=' + gridHeight
|
try{
|
||||||
+ '&nbShip1=' + nbShip1
|
var grids = JSON.parse(xhr.responseText);
|
||||||
+ '&nbShip2=' + nbShip2
|
for( var player=1; player <= 2 ; player ++){
|
||||||
+ '&nbShip3=' + nbShip3
|
var p=createElem("p");
|
||||||
+ '&nbShip4=' + nbShip4
|
p.innerHTML='Reponse joueurs:'xhr.responseText;
|
||||||
+ '&nbShip5=' + nbShip5
|
document.getElementById('logs').appendChild(p);
|
||||||
+ '&nbShip6=' + nbShip6
|
|
||||||
+ '&xd_check=' + xd_check
|
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);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.send(
|
||||||
|
'act=initGame&bot1=' + bot1IdName[0]
|
||||||
|
+ '&bot2=' + bot2IdName[0]
|
||||||
|
+ '&gridWidth=' + gridWidth
|
||||||
|
+ '&gridHeight=' + gridHeight
|
||||||
|
+ '&nbShip1=' + nbShip1
|
||||||
|
+ '&nbShip2=' + nbShip2
|
||||||
|
+ '&nbShip3=' + nbShip3
|
||||||
|
+ '&nbShip4=' + nbShip4
|
||||||
|
+ '&nbShip5=' + nbShip5
|
||||||
|
+ '&nbShip6=' + nbShip6
|
||||||
|
+ '&xd_check=' + xd_check
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user