Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace lesson2_4potok
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- int X = 0, Y = 0;
- //у пользователя есть координаты X Y, необходимо сделать так, чтобы при нажатии клавиш WASD
- //происходило изменение координат пользователя и каждую итерацию необходимо выводить эти координаты
- //в консоль
- //усовершенствовать этот код, чтобы не выбрасывало исключение при выходе за границы консоли
- ConsoleKey playerKey = Console.ReadKey(true).Key;
- while(playerKey != ConsoleKey.Escape)
- {
- switch(playerKey)
- {
- case ConsoleKey.A:
- X--;
- break;
- case ConsoleKey.W:
- Y--;
- break;
- case ConsoleKey.D:
- X++;
- break;
- case ConsoleKey.S:
- Y++;
- break;
- }
- Console.Clear();
- Console.SetCursorPosition(X, Y);
- Console.WriteLine("{0} {1}", X, Y);
- playerKey = Console.ReadKey(true).Key;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment