Less data on each query

pull/96/head
Gnieark 8 years ago
parent 49ed343300
commit f873d6233d

@ -1 +1 @@
1617
1622

Before

Width:  |  Height:  |  Size: 550 KiB

After

Width:  |  Height:  |  Size: 550 KiB

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 114 KiB

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

@ -36,6 +36,7 @@ class Trail {
public function __toString(){
return json_encode($this->getTrailAsArray());
}
public function getTrailAsArray(){
$arr = array();
foreach($this->trail as $coord) {

@ -77,6 +77,14 @@ class TronGame
}
return $trailsArr;
}
public function get_lasts_trails(){
//return only the lasts coords for each tail
$trailsArr = array();
foreach($this->bots as $bot){
$trailsArr[] = $bot->trail->last();
}
return $trailsArr;
}
public function new_lap(){
// for all alive bots
$logs = "";
@ -133,7 +141,7 @@ class TronGame
}
}
return $this->get_trails();
return $this->get_lasts_trails();
}

@ -44,7 +44,7 @@ switch ($_POST['act']){
'status' => $game->get_continue(),
'logs' => $logs,
'gameId' => $game->gameId,
'botsPosition' => $game->get_trails()
'botsPosition' => $game->get_lasts_trails()
));
$_SESSION['game'] = serialize($game);

@ -12,6 +12,7 @@ function addLog(message){
divLogs.scrollTop = divLogs.scrollHeight;
}
/*
function growTails(newPointsByPlayer){
var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue'];
@ -28,6 +29,7 @@ function growTails(newPointsByPlayer){
}
}
}
*/
function createElemNS(type,attributes){
//same as createElem but with ns for svg file
var elem=document.createElementNS("http://www.w3.org/2000/svg",type);
@ -85,7 +87,7 @@ function applyInitMessage(req,xd_check){
}
addLog(ret['logs']);
if(ret['status'] == true){
growTails(ret['botsPosition']);
drawMap(ret['botsPosition']);
play(ret['gameId'],xd_check);
}
@ -103,12 +105,18 @@ function drawMap(map){
var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue'];
for (var botId in map){
//draw the point
var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'});
document.getElementById('map').appendChild(rect);
/*
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);
}
*/
}
}
@ -126,9 +134,12 @@ function play(gameId,xd_check){
drawMap(reponse['lap']);
if(reponse['continue'] == '1'){
play(gameId,xd_check);
}else{
alert ('game ended');
}
}else{
alert('erreur' + req.status);
}
}

Loading…
Cancel
Save