/** * il pesce ritorna la direzione che vuole intraprendere . * @return Movement */ public function getMovement() { $move = new Movement(); $dirs = $move->getDirections(); $dir = rand(0, count($dirs) - 1); $move->setDirection($dirs[$dir]); return $move; }
/** * Restituisco una posizione libera nei dintorni * * @param Position $position * * @return null|Position null se non vi sono posti liberi * * */ public function getFreePosition(Position $position) { $map = $this->worldMap; if ($map->get($position) === null) { return $position; } $move = new Movement(); foreach ($move->getDirections() as $direction) { $move->setDirection($direction); $destination = $position->calculateNewPoint($move); if ($map->get($destination) === null) { return $destination; } } return null; }