static void PlaceRandomObstacles()
        {
            int targetCount  = (int)(room.tileCount * settings.obstaclePercent);
            int currentCount = 0;

            bool[,] obstacleMap = new bool[room.size.x, room.size.y];

            for (int i = 0; i < targetCount; i++)
            {
                Coord randomCoord = openCoords.Next();
                obstacleMap[randomCoord.x, randomCoord.y] = true;
                currentCount++;

                if (randomCoord != room.center && (room.tileCount - currentCount)
                    == GetAccessibleCount(room.center, obstacleMap))
                {
                    InstantiateObstacle(randomCoord);
                    openCoords.Remove(randomCoord);
                }
                else
                {
                    obstacleMap[randomCoord.x, randomCoord.y] = false;
                    currentCount--;
                }
            }
        }
示例#2
0
 public void SetTile(int x, int y, ITile tile)
 {
     // change openTiles list if necessary
     if (tiles[x, y] == null || tiles[x, y].type != tile.type)
     {
         Coord c = new Coord(x, y);
         if (tile.type == TileType.Empty)
         {
             openTiles.Add(c);
         }
         else
         {
             openTiles.Remove(c);
         }
     }
     tiles[x, y] = tile;
 }