Exemple #1
0
        public bool WriteCharacterArray(int x, int y, DecoratedCharacter[,] decoratedCharacters)
        {
            x = -x;
            y = -y;
            for (int yCount = 0; yCount < decoratedCharacters.GetLength(1); yCount++)
            {
                for (int xCount = 0; xCount < decoratedCharacters.GetLength(0); xCount++)
                {
                    if (xCount + _x < _x || xCount + _x > _x2 + 1 || yCount + _y < _y || yCount + _y > _y2 + 1 ||
                        xCount + x + _x < _x || yCount + y + _y + 1 < _y)
                    {
                        continue;
                    }

                    try
                    {
                        if (decoratedCharacters[xCount + x, yCount + y] == null)
                        {
                            decoratedCharacters[xCount + x, yCount + y] = new DecoratedCharacter(' ', ConsoleColor.White, ConsoleColor.Black);
                        }
                        ScreenBuffer.UpdateCharacter(xCount + _x, yCount + _y,
                                                     decoratedCharacters[xCount + x, yCount + y].Character,
                                                     decoratedCharacters[xCount + x, yCount + y].ForegroundColor, decoratedCharacters[xCount + x, yCount + y].BackgroundColor);
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        continue;
                    }
                }
            }

            return(true);
        }
Exemple #2
0
        public bool WriteCharacter(int x, int y, DecoratedCharacter character)
        {
            if (x > _width || y > _height)
            {
                return(false);
            }

            ScreenBuffer.UpdateCharacter(_x + x, _y + y, character.Character, character.ForegroundColor, character.BackgroundColor);

            return(true);
        }
        private static DecoratedCharacter[,] GenerateMap(int width, int height, float scale)
        {
            PerlinMapGenerator mapGenerator = new PerlinMapGenerator(width, height, scale);

            var map = mapGenerator.Map;

            var mapDecorated = new DecoratedCharacter[width, height];

            for (int mapY = 0; mapY < height; mapY++)
            {
                for (int mapX = 0; mapX < width; mapX++)
                {
                    if (map[mapX, mapY] < 0.2)
                    {
                        mapDecorated[mapX, mapY] = new DecoratedCharacter(' ', ConsoleColor.Black, ConsoleColor.DarkCyan);
                    }
                    else if (map[mapX, mapY] < 0.3)
                    {
                        mapDecorated[mapX, mapY] = new DecoratedCharacter(' ', ConsoleColor.Black, ConsoleColor.Cyan);
                    }
                    else if (map[mapX, mapY] < 0.35)
                    {
                        mapDecorated[mapX, mapY] = new DecoratedCharacter(' ', ConsoleColor.Black, ConsoleColor.DarkYellow);
                    }
                    else if (map[mapX, mapY] < 0.8)
                    {
                        mapDecorated[mapX, mapY] = new DecoratedCharacter(' ', ConsoleColor.Black, ConsoleColor.Green);
                    }
                    else if (map[mapX, mapY] < 0.8)
                    {
                        mapDecorated[mapX, mapY] = new DecoratedCharacter(' ', ConsoleColor.Black, ConsoleColor.DarkGreen);
                    }
                    else
                    {
                        mapDecorated[mapX, mapY] = new DecoratedCharacter(' ', ConsoleColor.Black, ConsoleColor.Grey);
                    }
                }
            }

            return(mapDecorated);
        }