0

I got problem this is my code for moving my Cursor and i need help to make it moving automatic/alone , i mean e.g. when i press LeftArrow it should go left until i press e.g. RightArrow to change the navigation.

switch (Console.ReadKey(true).Key)
{
    case ConsoleKey.UpArrow:
        {
            if (y > 0)
            {
                y--; // y = y - 1
            }
            break;
        }
    case ConsoleKey.DownArrow:
        {
            if (y < höhe - 1)
            {
                y++; // y = y + 1
            }
            break;
        }
    case ConsoleKey.LeftArrow:
        {
            if (x > 0)
            {
                x--; // x = x - 1
            }
            break;
        }
    case ConsoleKey.RightArrow:
        {
            if (x < breite - 1)
            {
                x++; // x = x + 1
            }
            break;
}
Mr.Nimelo
  • 316
  • 4
  • 17
Kevin Garnick
  • 94
  • 1
  • 9
  • if you are entirely controlling the curse then you will find that there is a set position for the cursor you can do – BugFinder Oct 04 '17 at 14:44
  • You need a timer. Or a gameloop with a "direction" variable. A console app is not exactly the best way, you can't get a reliable keyup notification so you can't press multiple keys at the same time. Technically you can pinvoke ReadConsoleInput() to make it perfect. – Hans Passant Oct 04 '17 at 14:45
  • `ReadKey()` blocks, but you could poll the `KeyAvailable` property while moving your cursor. – C.Evenhuis Oct 04 '17 at 14:46

0 Answers0