From 849a54bb68864175081f92f1f50693a3594bb29b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 6 Jul 2016 08:01:18 +0200 Subject: [PATCH] . --- countBattles.txt | 2 +- src/arenas/tron/act.php | 9 ++++++++- src/arenas/tron/functions.php | 5 ++++- src/arenas/tron/js.js | 21 +++++++++++++++++++-- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 85b0c4b..3559f24 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1462 \ No newline at end of file +1477 \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index b4db349..5cf7176 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -17,7 +17,14 @@ switch ($_POST['act']){ case "initGame": $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(); echo json_encode(array( diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index 6b1fef9..0edb411 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -84,7 +84,7 @@ class TronGame{ return $arr; } public function __construct($botsIds){ - + $this->gameId = get_unique_id(); $this->bots = array(); $positions = array(); @@ -101,7 +101,10 @@ class TronGame{ $this->bots[$botCount] = new TronPlayer($botId,$x,$y,'y+'); if ($this->bots[$botCount]->getStatus() === false){ + $err = "Something went wrong for ".$this->bots[$botCount]->getName()."
"; + }else{ + $botCount++; } } return $err; diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index f5ebecd..765f386 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -12,6 +12,22 @@ function addLog(message){ 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){ //same as createElem but with ns for svg file var elem=document.createElementNS("http://www.w3.org/2000/svg",type); @@ -68,8 +84,9 @@ function applyInitMessage(req,xd_check){ return; } addLog(ret['logs']); - if(ret['status'] == "OK"){ - play(ret['gameId'],xd_check); + if(ret['status'] == true){ + growTails(ret['botsPosition']); + //play(ret['gameId'],xd_check); } }else{