/** * @inheritdoc */ public function isSameAs(PointInterface $point) { if ($point->getX() === $this->getX() && $point->getY() === $this->getY()) { return true; } return false; }
/** * @param BattleshipInterface $battleship * @param PointInterface $start * @param PointInterface $end */ public function __construct(BattleshipInterface $battleship, PointInterface $start, PointInterface $end) { /* * placer should allow ony * ----> * OR * | * | * \/ * * But not <----- * Instead of throw error, $start and $end could be exchanged. */ if ($start->getX() > $end->getX() || $start->getY() > $end->getY()) { throw new Exception\Exception("Points missmatch"); } $this->battleship = $battleship; $this->startPoint = $start; $this->endPoint = $end; if ($this->getPoints()->count() !== $battleship->getSize()) { throw new Exception\Exception('Can\'t fit battleship in placer'); } }
/** * Check if point is valid for battlefield * @param PointInterface $point * @return boolean */ public function isPointValid(PointInterface $point) { $pointX = $point->getX(); if ($this->getFieldMaximumWidthIndex() < $pointX) { return false; } $pointY = $point->getY(); if ($this->getFieldMaximumHeightIndex() < $pointY) { return false; } return true; }