public function getLastShotStatus() { $lastShot = $this->battlefield->getShots()->getLastPoint(); if (!$lastShot) { return null; } if ($this->battlefield->isPointFree($lastShot)) { return 'miss'; } else { $sink = false; foreach ($this->battlefield->getPlacers() as $placer) { $placerPoints = $placer->getPoints(); if ($placerPoints->hasPoint($lastShot)) { $sinking = true; foreach ($placerPoints as $battleshipPoint) { if (Battlefield::POINT_STATUS_SHIP_HIT !== $this->battlefield->getPointStatus($battleshipPoint)) { $sinking = false; break; } } if ($sinking) { $sink = true; } break; } } if ($sink) { return 'sunk'; } else { return 'hit'; } } }
public function testAddCheatPoint() { $battlefield = new Battlefield(5, 5); $battlefield->shoot(new CheatPoint()); $this->assertSame(0, $battlefield->getShots()->count()); }