Пример #1
0
 /**
  * @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
 /**
  *
  * @param Position $pos
  *
  * @return boolean  True se la posizione indicata è libera
  */
 protected function isFreePosition(Position $pos)
 {
     return $this->matrix->get($pos) === self::OCEAN;
 }