This commit is contained in:
Gnieark 2016-06-30 14:53:38 +02:00
parent f77b172b85
commit 6616624069
2 changed files with 29 additions and 21 deletions

View File

@ -17,26 +17,30 @@ switch ($_POST['act']){
case "initGame": case "initGame":
//check if bots exists //check if bots exists
$bots=get_Bots_Array('tron'); $botsArrayTemp = json_decode($_POST['bots']);
$botsArray = json_decode($_POST['bots']);
$_SESSION['bots'] = array();
$bot1Exists = false; $positions = array();
$bot2Exists = false; $botCount = 0;
foreach($bots as $bot){ foreach($botsArrayTemp as $botId){
if($bot['id'] == $_POST['bot1']){ do{
$_SESSION['bots'][]=new TronPlayer($bot['id'],500,10,'y+'); $x = rand(1,999);
$bot1Exists =true; $y = rand(1,999);
} }while(in_array($x.",".$y,$positions));
if($bot['id'] == $_POST['bot2']){
$_SESSION['bots'][]=new TronPlayer($bot['id'],500,989,'y-'); $positions[] = $x.",".$y;
$bot2Exists =true; $_SESSION['bots'][$botCount] = new TronPlayer($bot['id'],500,10,'y+');
}
if ($bot1Exists && $bot2Exists){ if ($_SESSION['bots'][$botCount]->getStatus() === false){
break; unset($_SESSION['bots'][$botCount]);
} }else{
$botCount++;
}
} }
if ((!$bot1Exists) OR (!$bot2Exists)){
error (500,"missing parameter 2"); if ($botCount < 2){
error (500,"missing bots");
} }

View File

@ -6,7 +6,11 @@ class TronPlayer{
private $tail = array(); private $tail = array();
private $direction; private $direction;
private $state; private $state;
public function getStatus(){
return $this->state;
}
private function set_direction($newDir){ private function set_direction($newDir){
//can't be the opposite of the previous direction //can't be the opposite of the previous direction
if( if(
@ -20,7 +24,7 @@ class TronPlayer{
$this->direction = $newdir; $this->direction = $newdir;
return true; return true;
} }
public function grow($dir=""){ public function grow($dir=""){
if($dir == ""){ if($dir == ""){
$dir = $this->direction; $dir = $this->direction;