class tail

This commit is contained in:
Gnieark 2016-07-12 07:48:52 +02:00
parent 02457de1fe
commit d57ad1ec47
3 changed files with 33 additions and 1 deletions

View File

@ -1,7 +1,9 @@
<?php <?php
class Coords{ class Coords{
public $x; public $x;
public $y; public $y;
public function __construct(int $x = 0, int $y = 0) { public function __construct(int $x = 0, int $y = 0) {
$this->x = $x; $this->x = $x;
$this->y = $y; $this->y = $y;
@ -10,6 +12,7 @@ class Coords{
public function __toString(){ public function __toString(){
return $this->x.",".$this->y; return $this->x.",".$this->y;
} }
public function addDirection(Direction $dir){ public function addDirection(Direction $dir){
return new Coords( return new Coords(
$this->x + $dir->deltaX, $this->x + $dir->deltaX,

View File

@ -69,11 +69,13 @@ class TronPlayer{
$this->tail[] = $targetCell; $this->tail[] = $targetCell;
return $targetCell; return $targetCell;
} }
public function loose(){ public function loose(){
$this->state = false; $this->state = false;
$this->tail = array(); $this->tail = array();
return false; return false;
} }
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,

27
src/arenas/tron/tail.php Normal file
View File

@ -0,0 +1,27 @@
<?php
class Tail{
public $tail;
public function __toString(){
$str = "";
foreach(Tail::$tail as $coord){
$str .= "[".$coord."],";
}
return $str;
}
public function __make(Coords $InitialCoords){
$this->tail = array($InitialCoords);
}
public function grow(Direction $dir){
$last = Tail::getLastTailCoord();
Tail::tail[] = $last->addDirection($dir);
}
public function getLastTailCoord(){
return end(Tail::$tail);
}
}