function addAnimalToMap(World $world, $animal) { for ($i = 0; $i < 10; $i++) { $tempX = rand(1, $world->getWidth()); $tempY = rand(1, $world->getHeight()); if (!$world->getCellContents($tempX, $tempY)) { $world->addAnimal(new $animal($tempX, $tempY)); return; } } }