it draws the tail

This commit is contained in:
Gnieark 2016-07-26 19:55:40 +02:00
parent 5935b750d0
commit 1d5624462f
3 changed files with 26 additions and 6 deletions

View File

@ -1 +1 @@
1593 1617

View File

@ -77,6 +77,7 @@ switch ($_POST['act']){
'continue' => $continue, 'continue' => $continue,
'lap' => $lap 'lap' => $lap
)); ));
$_SESSION['game'] = serialize($game);
die; die;
break; break;

View File

@ -45,7 +45,7 @@ function changeSelect(number,botId){
show_bot_panel(next); show_bot_panel(next);
} }
if(number > 0){ 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){ function play(gameId,xd_check){
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
@ -105,8 +121,12 @@ function play(gameId,xd_check){
addLog(req.responseText); addLog(req.responseText);
var reponse = JSON.parse(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{ }else{
@ -116,7 +136,6 @@ function play(gameId,xd_check){
req.open("POST", '/tron', true); req.open("POST", '/tron', true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send('act=play&xd_check=' + xd_check + '&gameId=' + gameId + '&fullLogs=' + document.getElementById("fullLogs").checked); req.send('act=play&xd_check=' + xd_check + '&gameId=' + gameId + '&fullLogs=' + document.getElementById("fullLogs").checked);
} }
function tron(xd_check){ function tron(xd_check){
//empty //empty