This commit is contained in:
Gnieark 2016-07-03 12:50:29 +02:00
parent 0be20dea4d
commit 098c33470f

View File

@ -55,7 +55,7 @@ function show_bot_panel(number){
document.getElementById('configurePlayers').appendChild(fieldset); document.getElementById('configurePlayers').appendChild(fieldset);
} }
function applyInitMessage(req){ function applyInitMessage(req,xd_check){
document.getElementById('fightButton').disabled=true; document.getElementById('fightButton').disabled=true;
//callback function when init game request //callback function when init game request
if(req.readyState == 4){ if(req.readyState == 4){
@ -68,6 +68,9 @@ function applyInitMessage(req){
return; return;
} }
addLog(ret['logs']); addLog(ret['logs']);
if(ret['status'] == "OK"){
play(ret['gameId'],xd_check);
}
}else{ }else{
alert ('error ' + req.status); 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){ function tron(xd_check){
//empty //empty
while (document.getElementById('fightResult').firstChild) { while (document.getElementById('fightResult').firstChild) {
@ -99,7 +120,7 @@ function tron(xd_check){
//ask arena to send bots init messages //ask arena to send bots init messages
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onreadystatechange = function(){applyInitMessage(request)}; request.onreadystatechange = function(){applyInitMessage(request,xd_check)};
request.open("POST", '/tron', true); request.open("POST", '/tron', true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 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); request.send('act=initGame&xd_check=' + xd_check + '&bots=' + JSON.stringify(botsList) + '&fullLogs=' + document.getElementById("fullLogs").checked);