Example #1
0
 public function testCheckPoint()
 {
     $ship = new Ship('Destroyer', 3);
     $point = new Point(5, 7);
     $this->assertFalse($ship->checkPoint($point));
     $ship->setPoint($point);
     $this->assertTrue($ship->checkPoint($point));
 }
Example #2
0
 /**
  * Helper function placing the ship on the board.
  * @param  Ship   $ship
  * @param  Point  $startPoint
  * @param  String $direction
  */
 private function placeShip(Ship $ship, Point $startPoint, $direction)
 {
     if ($direction == 'horizontal') {
         $end = $startPoint->getColumn() + $ship->getSize() - 1;
         $row = $startPoint->getRow();
         foreach (range($startPoint->getColumn(), $end) as $column) {
             $point = new Point($row, $column);
             $ship->setPoint($point);
             $this->busySpots[] = $point;
         }
     } else {
         $end = $startPoint->getRow() + $ship->getSize() - 1;
         $column = $startPoint->getColumn();
         foreach (range($startPoint->getRow(), $end) as $row) {
             $point = new Point($row, $column);
             $ship->setPoint($point);
             $this->busySpots[] = $point;
         }
     }
     $this->ships[] = $ship;
 }