From d57ad1ec47d13f8a95269d0daca0100a8b9ac7c5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 12 Jul 2016 07:48:52 +0200 Subject: [PATCH] class tail --- src/arenas/tron/Coords.php | 5 ++++- src/arenas/tron/TronPlayer.php | 2 ++ src/arenas/tron/tail.php | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/arenas/tron/tail.php diff --git a/src/arenas/tron/Coords.php b/src/arenas/tron/Coords.php index 34a16a7..31a42b3 100644 --- a/src/arenas/tron/Coords.php +++ b/src/arenas/tron/Coords.php @@ -1,15 +1,18 @@ 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, diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php index c90462c..6305da5 100644 --- a/src/arenas/tron/TronPlayer.php +++ b/src/arenas/tron/TronPlayer.php @@ -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, diff --git a/src/arenas/tron/tail.php b/src/arenas/tron/tail.php new file mode 100644 index 0000000..4d2d3e9 --- /dev/null +++ b/src/arenas/tron/tail.php @@ -0,0 +1,27 @@ +tail = array($InitialCoords); + } + + public function grow(Direction $dir){ + $last = Tail::getLastTailCoord(); + Tail::tail[] = $last->addDirection($dir); + } + + public function getLastTailCoord(){ + return end(Tail::$tail); + } +} \ No newline at end of file