Example #1
0
 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';
         }
     }
 }