コード例 #1
0
ファイル: Point.php プロジェクト: angelk/tmp-bships
 /**
  * @inheritdoc
  */
 public function isSameAs(PointInterface $point)
 {
     if ($point->getX() === $this->getX() && $point->getY() === $this->getY()) {
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: Placer.php プロジェクト: angelk/tmp-bships
 /**
  * @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');
     }
 }
コード例 #3
0
ファイル: Battlefield.php プロジェクト: angelk/tmp-bships
 /**
  * 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;
 }