Problem z "rysowaniem" używając readkey();

0

Witam,Mam taki problem.Napisałem sobie taki oto program w którym rysuję przy pomocy Readkey

 using System;

class Program
{
    static void Main()
    {
        int a=0, b=0;
        while (true)
        {

            ConsoleKeyInfo o = Console.ReadKey();
            if (o.Key == ConsoleKey.LeftArrow)
            {
                b = b - 1;
                Console.SetCursorPosition(b, a);
                Console.Write("█");

            }
            if (o.Key == ConsoleKey.RightArrow)
            {
                b = b + 1;
                Console.SetCursorPosition(b, a);
                Console.Write("█");
            }
            if (o.Key == ConsoleKey.DownArrow)
            {
                a = a + 1;
                Console.SetCursorPosition(b, a);
                Console.Write("█");
            }
            if (o.Key == ConsoleKey.UpArrow)
            {
                a = a - 1;
                Console.SetCursorPosition(b, a);
                Console.Write("█");
            }
        }
    }
}

Problem polega na tym,iż kiedy przejadę ponownie po narysowanej linii ( w większości przypadków spróbujcie ) to ona znika.Nie wiem jak temy zaradzić
Pozdrawiam

0
using System;

class Program
{
    static void Main()
    {
        int a = 0, b = 0;
        Console.CursorVisible = false;
        while (true)
        {

            ConsoleKeyInfo o = Console.ReadKey();
            if (o.Key == ConsoleKey.LeftArrow)
            {
                b -= b > 0 ? 1 : 0;
            }
            if (o.Key == ConsoleKey.RightArrow)
            {
                b += b < 79 ? 1 : 0;
            }
            if (o.Key == ConsoleKey.DownArrow)
            {
                a = a + 1;
            }
            if (o.Key == ConsoleKey.UpArrow)
            {
                a -= a > 0 ? 1 : 0;
            }

            Console.SetCursorPosition(b, a);
            Console.Write("█");
            Console.SetCursorPosition(0, 0);
        }
    }
}

Sądzę, że to spowodowane jest ReadKeyem. Ten kod pomaga, aczkolwiek teraz na pozycji 0,0 nic nie da się narysować.

0
  1. brak kontroli zakresów, wyjechanie poza ekran wywala program
  2. ConsoleKeyInfo o = Console.ReadKey(true);
  3. najlepiej wyczyść ekran przy końcu.

1 użytkowników online, w tym zalogowanych: 0, gości: 1