Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class ConsoleMove
- {
- public static void Main()
- {
- Console.CursorVisible = false;
- Console.Write("@");
- var playingGame = true;
- var playerX = 0;
- var playerY = 0;
- while (playingGame)
- {
- if (Console.KeyAvailable)
- {
- Console.SetCursorPosition(playerX, playerY);
- Console.Write(" ");
- ConsoleKeyInfo input = Console.ReadKey(true);
- switch (input.Key)
- {
- case ConsoleKey.UpArrow:
- if (playerY > 0)
- {
- playerY--;
- }
- break;
- case ConsoleKey.DownArrow:
- playerY++;
- break;
- case ConsoleKey.LeftArrow:
- if (playerX > 0)
- {
- playerX--;
- }
- break;
- case ConsoleKey.RightArrow:
- playerX++;
- break;
- case ConsoleKey.Escape:
- playingGame = false;
- break;
- }
- Console.SetCursorPosition(playerX, playerY);
- Console.Write("@");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement