class tail

This commit is contained in:
Gnieark 2016-07-12 18:58:28 +02:00
parent d57ad1ec47
commit 294ab30e48
3 changed files with 38 additions and 68 deletions

View File

@ -1,5 +1,16 @@
<?php <?php
class TronGame class TronGame
{
private $bots; //array of bots
private $gameId;
private $status; //false => Game ended or not initialised
}
/*
class TronGame
{ {
private $bots; private $bots;
private $gameId; private $gameId;
@ -30,9 +41,9 @@ class TronGame
} }
private function save_draw_bots($arr){ private function save_draw_bots($arr){
/* *
* Recursive function who save all combionaisons of draw matches * Recursive function who save all combionaisons of draw matches
*/ *
if(count($arr) < 2){ if(count($arr) < 2){
return; return;
@ -293,4 +304,4 @@ class TronGame
return $err; return $err;
} }
} }
?> */

View File

@ -1,69 +1,13 @@
<?php <?php
class TronPlayer{ class TronPlayer{
private $url; private $url;
private $id; public $id;
private $name; public $name;
private $tail = array(); public $tail;
private $direction; private $direction;
private $state;
public function getTail(){
return $this->tail;
}
public function getStatus(){
return $this->state;
}
public function getURL(){
return $this->url;
}
public function getName(){
return $this->name;
}
public function getId(){
return $this->id;
}
private function set_direction($newDir){
//can't be the opposite of the previous direction
if(
(($newDir == "x+") && ($this->direction == "x-"))
|| (($newDir == "x-") && ($this->direction == "x+"))
|| (($newDir == "y+") && ($this->direction == "y-"))
|| (($newDir == "y-") && ($this->direction == "y+"))
){
return false;
}
$this->direction = $newDir;
return true;
}
private function getTargetCell($dir){
if($dir == ""){ public $isAlive = true;
$dir = $this->direction;
}
if(!$this->set_direction($dir)){
return false;
}
$headCoords = end($this->tail);
switch ($dir){
case "y+":
return array($headCoords[0],$headCoords[1]++);
break;
case "y-":
return array($headCoords[0],$headCoords[1]--);
break;
case "x+":
return array($headCoords[0]++,$headCoords[1]);
break;
case "x-":
return array($headCoords[0]--,$headCoords[1]);
break;
default:
return false;
}
}
public function grow($dir=""){ public function grow($dir=""){
$targetCell = $this->getTargetCell($dir); $targetCell = $this->getTargetCell($dir);
$this->tail[] = $targetCell; $this->tail[] = $targetCell;
@ -71,11 +15,21 @@ class TronPlayer{
} }
public function loose(){ public function loose(){
$this->state = false;
$this->tail = array(); $this->isAlive = false;
// $this->tail = array();
return false; return false;
} }
public function __make($botId, Coords $initialsCoords,$name,$url){
$this->id = $botId;
$this->tail = Tail::make($initialsCoords);
$this->name = $name;
$this->url = $url;
}
public function __construct(){
$this->state = true;
}
/*
public function __construct($id,$initialX,$initialY,$initialDirection){ public function __construct($id,$initialX,$initialY,$initialDirection){
$lnBdd = conn_bdd(); $lnBdd = conn_bdd();
$rs = mysqli_query($lnBdd, $rs = mysqli_query($lnBdd,
@ -92,5 +46,6 @@ class TronPlayer{
$this->state = false; $this->state = false;
} }
} }
*/
} }
?> ?>

View File

@ -16,9 +16,13 @@ class Tail{
$this->tail = array($InitialCoords); $this->tail = array($InitialCoords);
} }
public function empty_tail(){
}
public function grow(Direction $dir){ public function grow(Direction $dir){
$last = Tail::getLastTailCoord(); $last = $this->getLastTailCoord();
Tail::tail[] = $last->addDirection($dir); $this->tail[] = $last->addDirection($dir);
} }
public function getLastTailCoord(){ public function getLastTailCoord(){