コード例 #1
0
ファイル: Visualizer.php プロジェクト: angelk/tmp-bships
 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';
         }
     }
 }
コード例 #2
0
ファイル: BattleFieldTest.php プロジェクト: angelk/tmp-bships
 public function testAddCheatPoint()
 {
     $battlefield = new Battlefield(5, 5);
     $battlefield->shoot(new CheatPoint());
     $this->assertSame(0, $battlefield->getShots()->count());
 }