1

I am attempting to create a console-based library for games.

I have classes that fill a two-dimensional array with background-foreground-character values, and then my code iterates through that array to write the symbols. (This is so I can have multiple colors).

This is what I believe to be the only relevant part of the code:

for (int y = 0; y < chars.GetLength(1); y++)
        {
            for (int x = 0; x < chars.GetLength(0); x++)
            {
                Character chr = chars[x, y];
                Console.ForegroundColor = chr.ForeGround;
                Console.BackgroundColor = chr.BackGround;
                Console.Write(chr.Symbol.ToString());
            }
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Write("\n");
        }

However, the output looks like this: enter image description here

There are small lines at the bottom and at the right, as well as the large black square presumably where the scroll bar would normally be. The scrollbar itself isn't visible, as I've changed the buffer size of the console window to be the same as the screen size, like so:

        public Game(string name, Size size, Scene[] scenes)
    {
        this.name = name;
        Console.Title = name;
        this.scenes = scenes;
        this.currentScene = scenes[0];
        this.size = size;
        Console.SetWindowSize(size.Width, size.Height);
        Console.SetBufferSize(size.Width, size.Height);
        Render();
        Console.ReadKey();
    }

Is there any way of getting rid of those color anomalies? The only way I've personally found is by printing black background at the edges, but this would result in my game being awkwardly offset from the center.

Copper
  • 35
  • 7
  • 1
    You can get better control by writing directly to the console buffer. This doesn't appear to be support by the `Console` class, however, but there's some information in [this answer](https://stackoverflow.com/questions/2754518/how-can-i-write-fast-colored-output-to-console). – 500 - Internal Server Error Aug 10 '21 at 12:25

0 Answers0