class tail
This commit is contained in:
parent
02457de1fe
commit
d57ad1ec47
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
class Coords{
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
|
||||
public function __construct(int $x = 0, int $y = 0) {
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
|
@ -10,6 +12,7 @@ class Coords{
|
|||
public function __toString(){
|
||||
return $this->x.",".$this->y;
|
||||
}
|
||||
|
||||
public function addDirection(Direction $dir){
|
||||
return new Coords(
|
||||
$this->x + $dir->deltaX,
|
||||
|
|
|
@ -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
27
src/arenas/tron/tail.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user