From 1d5624462f07c40f032adb6898ae6b7b177179e8 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 26 Jul 2016 19:55:40 +0200 Subject: [PATCH] it draws the tail --- countBattles.txt | 2 +- src/arenas/tron/act.php | 1 + src/arenas/tron/js.js | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 30ab544..f84ccb2 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1593 \ No newline at end of file +1617 \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index c7df199..5cc1d81 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -77,6 +77,7 @@ switch ($_POST['act']){ 'continue' => $continue, 'lap' => $lap )); + $_SESSION['game'] = serialize($game); die; break; diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index c189820..1223cbf 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -43,9 +43,9 @@ function changeSelect(number,botId){ return; }else{ show_bot_panel(next); - } + } if(number > 0){ - document.getElementById('fightButton').disabled = false; + document.getElementById('fightButton').disabled = false; } } } @@ -96,6 +96,22 @@ function applyInitMessage(req,xd_check){ } } } + + +function drawMap(map){ + console.log(map); + var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; + + for (var botId in map){ + for(var coordsI in map[botId]){ + coords = map[botId][coordsI]; + //draw the point + var rect=createElemNS('rect',{'x':coords[0],'y':coords[1],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); + document.getElementById('map').appendChild(rect); + } + } +} + function play(gameId,xd_check){ var req = new XMLHttpRequest(); @@ -105,8 +121,12 @@ function play(gameId,xd_check){ addLog(req.responseText); var reponse = JSON.parse(req.responseText); - growTails(reponse['lap']); - play(gameId,xd_check); + + + drawMap(reponse['lap']); + if(reponse['continue'] == '1'){ + play(gameId,xd_check); + } }else{ @@ -116,7 +136,6 @@ function play(gameId,xd_check){ req.open("POST", '/tron', true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send('act=play&xd_check=' + xd_check + '&gameId=' + gameId + '&fullLogs=' + document.getElementById("fullLogs").checked); - } function tron(xd_check){ //empty