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,15 +1,18 @@
<?php
class Coords{
public $x;
public $y;
public function __construct(int $x = 0, int $y = 0) {
$this->x = $x;
$this->y = $y;
}
public function __toString(){
return $this->x.",".$this->y;
}
public function addDirection(Direction $dir){
return new Coords(
$this->x + $dir->deltaX,

View File

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