class tail
This commit is contained in:
parent
02457de1fe
commit
d57ad1ec47
|
@ -1,15 +1,18 @@
|
||||||
<?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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
|
|
@ -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
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