.
This commit is contained in:
parent
0d79e871de
commit
849a54bb68
|
@ -1 +1 @@
|
||||||
1462
|
1477
|
|
@ -17,7 +17,14 @@ switch ($_POST['act']){
|
||||||
case "initGame":
|
case "initGame":
|
||||||
|
|
||||||
$botsArrayTemp = json_decode($_POST['bots']);
|
$botsArrayTemp = json_decode($_POST['bots']);
|
||||||
$game = new TronGame($botsArrayTemp);
|
$botsIds = array();
|
||||||
|
//dont take non selected bots (value=0)
|
||||||
|
foreach($botsArrayTemp as $bot){
|
||||||
|
if($bot > 0){
|
||||||
|
$botsIds[] = $bot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$game = new TronGame($botsIds);
|
||||||
$logs = $game->init_game();
|
$logs = $game->init_game();
|
||||||
|
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
|
|
|
@ -101,7 +101,10 @@ class TronGame{
|
||||||
$this->bots[$botCount] = new TronPlayer($botId,$x,$y,'y+');
|
$this->bots[$botCount] = new TronPlayer($botId,$x,$y,'y+');
|
||||||
|
|
||||||
if ($this->bots[$botCount]->getStatus() === false){
|
if ($this->bots[$botCount]->getStatus() === false){
|
||||||
|
|
||||||
$err = "Something went wrong for ".$this->bots[$botCount]->getName()."<br/>";
|
$err = "Something went wrong for ".$this->bots[$botCount]->getName()."<br/>";
|
||||||
|
}else{
|
||||||
|
$botCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $err;
|
return $err;
|
||||||
|
|
|
@ -12,6 +12,22 @@ function addLog(message){
|
||||||
divLogs.scrollTop = divLogs.scrollHeight;
|
divLogs.scrollTop = divLogs.scrollHeight;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
function growTails(newPointsByPlayer){
|
||||||
|
|
||||||
|
var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue'];
|
||||||
|
//document.getElementById('map');
|
||||||
|
for (var botId in newPointsByPlayer){
|
||||||
|
|
||||||
|
var tail = newPointsByPlayer[botId]['tail'];
|
||||||
|
for(var coordsIx in tail){
|
||||||
|
|
||||||
|
coords = tail[coordsIx];
|
||||||
|
//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 createElemNS(type,attributes){
|
function createElemNS(type,attributes){
|
||||||
//same as createElem but with ns for svg file
|
//same as createElem but with ns for svg file
|
||||||
var elem=document.createElementNS("http://www.w3.org/2000/svg",type);
|
var elem=document.createElementNS("http://www.w3.org/2000/svg",type);
|
||||||
|
@ -68,8 +84,9 @@ function applyInitMessage(req,xd_check){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addLog(ret['logs']);
|
addLog(ret['logs']);
|
||||||
if(ret['status'] == "OK"){
|
if(ret['status'] == true){
|
||||||
play(ret['gameId'],xd_check);
|
growTails(ret['botsPosition']);
|
||||||
|
//play(ret['gameId'],xd_check);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user