示例#1
0
        public void Create(int fillRate)
        {
            Map = new Tile[Width, Height];

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (Randomizer.Percentage(fillRate))
                    {
                        Map[x, y] = new Wall(0, '#', ConsoleColor.Gray);
                    }
                    else
                    {
                        Map[x, y] = new Floor('.', ConsoleColor.DarkGray);
                    }
                }
            }

            // Create edge walls
            for (int row = 0; row < Height; row++)
            {
                Map[0, row] = new Wall(0, '#', ConsoleColor.Gray);
                Map[Width - 1, row] = new Wall(0, '#', ConsoleColor.Gray);
            }
            for (int col = 0; col < Width; col++)
            {
                Map[col, 0] = new Wall(0, '#', ConsoleColor.Gray);
                Map[col, Height - 1] = new Wall(0, '#', ConsoleColor.Gray);
            }
        }
示例#2
0
        private void Iterate(int neighbors)
        {
            Tile[,] nextMapGeneration = new Tile[Width, Height];

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (CountWalls(x, y) >= neighbors)
                    {
                        nextMapGeneration[x, y] = new Wall(0, '#', ConsoleColor.Gray);
                    }
                    else
                    {
                        nextMapGeneration[x, y] = new Floor('.', ConsoleColor.DarkGray);
                    }
                }
            }

            Map = nextMapGeneration;
        }