Example #1
0
 /**
  * @param Position $pos
  * Il metodo fixPosition si occupa di far
  * si che il nostro mondo sia Toroidale.
  */
 public function fixPosition(Position $pos)
 {
     if ($pos->getX() < 0) {
         $pos->setX($this->w + $pos->getX());
     } elseif ($pos->getX() >= $this->w) {
         $pos->setX($pos->getX() - $this->w);
     }
     if ($pos->getY() < 0) {
         $pos->setY($this->h + $pos->getY());
     } elseif ($pos->getY() >= $this->h) {
         $pos->setY($pos->getY() - $this->h);
     }
 }
Example #2
0
 /**
  * Restituisce una posizione libera (se disponibile) nei dintorni
  *
  * @param Position $position
  * @return null|Position Null
  *
  * @internal param FishInterface $fish
  */
 public function getNearFreePosition(Position $position)
 {
     $pos = new Position($position->getX(), $position->getY());
     $x = $pos->getX() - 1;
     $y = $pos->getY() - 1;
     for ($i = 0; $i < 3; $i++) {
         $pos->setX($x + $i);
         for ($j = 0; $j < 3; $j++) {
             $pos->setY($y + $j);
             if ($this->isFreePosition($pos) == true) {
                 return new Position($pos->getX(), $pos->getY());
             }
         }
     }
     return null;
 }