public function testGetLastShotStatusSink() { $battlefield = new Battlefield(10, 10); $visualizer = new Visualizer($battlefield); $placer = new Placer(new \Model\Battleship\Destroyer(), new Point(0, 0), new Point(3, 0)); $battlefield->addBattleship($placer); $battlefield->shoot(new Point(1, 1)); $this->assertSame('miss', $visualizer->getLastShotStatus()); $battlefield->shoot(new Point(0, 0)); $this->assertSame('hit', $visualizer->getLastShotStatus()); $battlefield->shoot(new Point(1, 0)); $battlefield->shoot(new Point(2, 0)); $battlefield->shoot(new Point(3, 0)); $this->assertSame('sunk', $visualizer->getLastShotStatus()); }
public function testBattleshipAddingAfterShoot() { $this->setExpectedException(\Model\Battlefield\Exception\Exception::class); $battlefield = new Battlefield(5, 5); $battlefield->shoot(new Point(0, 0)); $battlefield->addBattleship(new Placer(new Destroyer(), new Point(0, 0), new Point(0, 3))); }
/** * Force user to enter valid point * @param Battlefield $battlefield * @return \Model\Battlefield\Point\PointInterface */ protected function shoot(Battlefield $battlefield) { $pointFactory = new \Model\Battlefield\Point\PointFactory(); $shot = null; while ($shot === null) { echo "Enter point coordinates: "; $coordinates = trim(fgets(STDIN)); try { $shot = $pointFactory->createPoint($coordinates); $battlefield->shoot($shot); } catch (\Model\Battlefield\Exception\HumanReadableException $e) { echo "Error. " . $e->getMessage() . PHP_EOL; $shot = null; } } return $shot; }