From 098c33470f661d1ac44519bdd0d6568927a4d1df Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sun, 3 Jul 2016 12:50:29 +0200 Subject: [PATCH] . --- src/arenas/tron/js.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index cc5682d..5ca3a7e 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -55,7 +55,7 @@ function show_bot_panel(number){ document.getElementById('configurePlayers').appendChild(fieldset); } -function applyInitMessage(req){ +function applyInitMessage(req,xd_check){ document.getElementById('fightButton').disabled=true; //callback function when init game request if(req.readyState == 4){ @@ -68,6 +68,9 @@ function applyInitMessage(req){ return; } addLog(ret['logs']); + if(ret['status'] == "OK"){ + play(ret['gameId'],xd_check); + } }else{ alert ('error ' + req.status); @@ -76,6 +79,24 @@ function applyInitMessage(req){ } } } +function play(gameId,xd_check){ + + var request = new XMLHttpRequest(); + request.onreadystatechange = function(){ + if(req.readyState == 4){ + if(req.status == 200) { + addLog(req.responseText); + + }else{ + + } + } + }; + request.open("POST", '/tron', true); + request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + request.send('act=play&xd_check=' + xd_check + '&gameId=' + gameId + '&fullLogs=' + document.getElementById("fullLogs").checked); + +} function tron(xd_check){ //empty while (document.getElementById('fightResult').firstChild) { @@ -99,7 +120,7 @@ function tron(xd_check){ //ask arena to send bots init messages var request = new XMLHttpRequest(); - request.onreadystatechange = function(){applyInitMessage(request)}; + request.onreadystatechange = function(){applyInitMessage(request,xd_check)}; request.open("POST", '/tron', true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send('act=initGame&xd_check=' + xd_check + '&bots=' + JSON.stringify(botsList) + '&fullLogs=' + document.getElementById("fullLogs").checked);