From ac590f6314aee32f17f6b62bf8ea363eae73c096 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 15 Dec 2015 12:36:26 +0100 Subject: [PATCH 01/10] change tables id --- src/arenas/Battleship/js.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index fac22df..8d893ed 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -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,18 @@ 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 boats = JSON.parse(this.responseText); + //for + + + + + } + catch(e){ + document.getElementById('logs').innerHTML = xhr.responseText; + + } } }}; xhr.open("POST", '/Battleship', true); From 9029fa6840f647ee3c0114567a11476bb7c39fd6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 15 Dec 2015 12:41:49 +0100 Subject: [PATCH 02/10] change tables id --- src/arenas/Battleship/js.js | 6 ++++-- src/arenas/Battleship/style.css | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 8d893ed..7108711 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -65,10 +65,12 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi //alert(xhr.responseText); try{ var boats = JSON.parse(this.responseText); - //for - + for( var player=1; player <= 2 ; player ++){ + + + } } catch(e){ diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css index 4c97286..3f7b941 100644 --- a/src/arenas/Battleship/style.css +++ b/src/arenas/Battleship/style.css @@ -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;} \ No newline at end of file +.battleshipGrid tr th{text-align: center;} +.shipOn{background-color: black;} \ No newline at end of file From 1fb31d8ddfe70616cb1404b88c5fd26ca04f59d3 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:28:57 +0100 Subject: [PATCH 03/10] affiche boats --- src/arenas/Battleship/js.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 7108711..f67282d 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -64,12 +64,15 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi //debug //alert(xhr.responseText); try{ - var boats = JSON.parse(this.responseText); + var grids = JSON.parse(this.responseText); for( var player=1; player <= 2 ; player ++){ - - - - + for (var y=0; y < grids[player].count ; y++){ + for (var x=0; x < grids[player][y].count ; x++){ + if (grids[player][y][x] == "1"){ + document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; + } + } + } } } From 3fcf4f0ce5061c06cf43ccd04796071b089d4f14 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:30:56 +0100 Subject: [PATCH 04/10] affiche boats --- src/arenas/Battleship/js.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index f67282d..e20c5ee 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -69,6 +69,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi for (var y=0; y < grids[player].count ; y++){ for (var x=0; x < grids[player][y].count ; x++){ if (grids[player][y][x] == "1"){ + alert('bot' + player + '-' + y + '-' + x); document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; } } From 5c554be7aee21bd619bf666c6aed6977771fdd72 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:32:13 +0100 Subject: [PATCH 05/10] affiche boats --- src/arenas/Battleship/js.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index e20c5ee..3eeee76 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -64,12 +64,11 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi //debug //alert(xhr.responseText); try{ - var grids = JSON.parse(this.responseText); + var grids = JSON.parse(xhr.responseText); for( var player=1; player <= 2 ; player ++){ for (var y=0; y < grids[player].count ; y++){ for (var x=0; x < grids[player][y].count ; x++){ if (grids[player][y][x] == "1"){ - alert('bot' + player + '-' + y + '-' + x); document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; } } From 2d9e84acf7d1448d26262504909f2ac0547b1212 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:36:31 +0100 Subject: [PATCH 06/10] for debog --- src/arenas/Battleship/js.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 3eeee76..7f7f14f 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -63,7 +63,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi if(xhr.status == 200) { //debug //alert(xhr.responseText); - try{ + //try{ var grids = JSON.parse(xhr.responseText); for( var player=1; player <= 2 ; player ++){ for (var y=0; y < grids[player].count ; y++){ @@ -75,11 +75,11 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi } } - } - catch(e){ - document.getElementById('logs').innerHTML = xhr.responseText; + //} + //catch(e){ + // document.getElementById('logs').innerHTML = xhr.responseText; - } + //} } }}; xhr.open("POST", '/Battleship', true); From 47f86243a4c36c6caf77d93063507232c88e6f22 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:38:06 +0100 Subject: [PATCH 07/10] for debog --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 7f7f14f..48497a0 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -68,7 +68,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi for( var player=1; player <= 2 ; player ++){ for (var y=0; y < grids[player].count ; y++){ for (var x=0; x < grids[player][y].count ; x++){ - if (grids[player][y][x] == "1"){ + if (grids[player][y][x] == 1){ document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; } } From 94a33d36c1f41d40cf3b22963e479eae7f2a3091 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:39:21 +0100 Subject: [PATCH 08/10] for debog --- src/arenas/Battleship/js.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 48497a0..ba998ec 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -68,6 +68,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi for( var player=1; player <= 2 ; player ++){ for (var y=0; y < grids[player].count ; y++){ for (var x=0; x < grids[player][y].count ; x++){ + alert (grids[player][y][x] + y + x); if (grids[player][y][x] == 1){ document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; } From 2cffd1cf1f6b08b2b7854b2efed4f59da925b619 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:47:34 +0100 Subject: [PATCH 09/10] fix js --- src/arenas/Battleship/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index ba998ec..030c08a 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -66,8 +66,8 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi //try{ var grids = JSON.parse(xhr.responseText); for( var player=1; player <= 2 ; player ++){ - for (var y=0; y < grids[player].count ; y++){ - for (var x=0; x < grids[player][y].count ; x++){ + for (var y=0; y < grids[player].length ; y++){ + for (var x=0; x < grids[player][y].length ; x++){ alert (grids[player][y][x] + y + x); if (grids[player][y][x] == 1){ document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; From 374683d060d73861187bf718dfff829f1b9044bb Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 13:49:25 +0100 Subject: [PATCH 10/10] js: debog off --- src/arenas/Battleship/js.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 030c08a..3986ac8 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -63,12 +63,11 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi if(xhr.status == 200) { //debug //alert(xhr.responseText); - //try{ + 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++){ - alert (grids[player][y][x] + y + x); if (grids[player][y][x] == 1){ document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; } @@ -76,11 +75,11 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi } } - //} - //catch(e){ - // document.getElementById('logs').innerHTML = xhr.responseText; + } + catch(e){ + document.getElementById('logs').innerHTML = xhr.responseText; - //} + } } }}; xhr.open("POST", '/Battleship', true);