public function growAroundTile($index) { $this->freeIndexSearchIsRandom = true; $roundToBuild = 2; $map = $this->getMap(); $position = new Tile($map->getAllTiles()[$index][self::COORDINATES][self::X], $map->getAllTiles()[$index][self::COORDINATES][self::Y]); $map->setTileDistance($index, self::COORDINATES); for ($round = self::DISTANCE; $round <= $roundToBuild; $round++) { $position->move(Directions::RIGHT_UP); foreach (Directions::getDirections() as $direction) { for ($step = 0; $step < $round; $step++) { $tile = $position->move($direction); if ($map->hasTile($tile)) { if ($round == self::FIRST_ROUND) { if ($map->isTileOnTheEdge($tile)) { $newTileIndex = $map->getTileIndex($tile); $map->setTileDistance($newTileIndex, self::DISTANCE); } } } else { $map->addTile($tile, $round); } } } } }
public function __construct(Tile $position, $rounds) { $this->addTile($position); for ($round = 1; $round < $rounds; $round++) { $position->move(Directions::RIGHT_UP); foreach (Directions::getDirections() as $direction) { for ($step = 0; $step < $round; $step++) { $this->addTile($position->move($direction), $round); } } } }