Implement Tile.representsVoid

master
Peter Babič 8 years ago
parent 53ea4f589e
commit f7b58eeb0e
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 21
      src/Coffee/Tile.php
  2. 6
      tests/Coffee/TileTest.php

@ -3,12 +3,7 @@
namespace Coffee;
/**
* Class Tile
*
* @package Coffee
*/
/**
* Class Tile
* Class Tile Represents the Position on the Map with more properties
*
* @package Coffee
*/
@ -25,7 +20,9 @@ class Tile extends Position {
/**
* @var bool
*/
private $containsElement = false;
private $representsElement = false;
// private $isVisited = false;
/**
* Tile constructor.
@ -36,20 +33,24 @@ class Tile extends Position {
* @throws \Exception
*/
public function __construct($row, $column, $tileRepresentation) {
if ($tileRepresentation != self::REPRESENTS_ELEMENT && $tileRepresentation != self::REPRESENTS_VOID) {
if (!$this->representsElement() && !$this->representsVoid()) {
throw new \Exception('The map contains invalid representations');
}
parent::__construct($row, $column);
$this->containsElement = $tileRepresentation;
$this->representsElement = $tileRepresentation;
}
/**
* @return boolean
*/
public function representsElement() {
return $this->containsElement == self::REPRESENTS_ELEMENT;
return $this->representsElement == self::REPRESENTS_ELEMENT;
}
public function representsVoid() {
return $this->representsElement == self::REPRESENTS_VOID;
}
/**

@ -13,6 +13,12 @@ class TileTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($tile->representsElement());
}
public function testRepresentsVoid() {
$tile = new Tile(2, 2, Tile::REPRESENTS_VOID);
$this->assertTrue($tile->representsVoid());
}
public function testGetPosition() {
$row = 2;
$column = 2;

Loading…
Cancel
Save