コード例 #1
0
ファイル: LifeHS.php プロジェクト: ebasirico/school-project
 /**
  * @param MovableInterface $fish
  * @param Position         $current
  *
  * @return Position
  */
 protected function moveFish(MovableInterface $fish, Position $current)
 {
     $mov = $fish->getMovement();
     $next = $current->calculateNewPoint($mov);
     $destination = $this->worldMap->get($next);
     if ($destination === null) {
         // Destinazione vuota: mi sposto
         $this->worldMap->put($fish, $next);
         $this->worldMap->put(null, $current);
         $current = $next;
     } else {
         // Destinazione occupata: se posso mangio
         if ($fish instanceof PredatorInterface and $destination instanceof FoodInterface) {
             $fish->eat($destination);
             $this->worldMap->put($fish, $next);
             $this->worldMap->put(null, $current);
             $current = $next;
             unset($destination);
         }
     }
     return $current;
 }
コード例 #2
0
ファイル: WorldMap.php プロジェクト: ebasirico/school-project
 /**
  *
  * @param Position $pos
  *
  * @return boolean  True se la posizione indicata è libera
  */
 protected function isFreePosition(Position $pos)
 {
     return $this->matrix->get($pos) === self::OCEAN;
 }