Advertisement
Goldobin

Untitled

Aug 16th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace train
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int X = 0, Y = 0;
  14.  
  15.             //у пользователя есть координаты X Y, необходимо сделать так, чтобы при нажатии клавиш WASD
  16.             //происходило изменение координат пользователя и каждую итерацию необходимо выводить эти координаты
  17.             //в консоль
  18.             ConsoleKey playerKey = Console.ReadKey(true).Key;
  19.  
  20.  
  21.             while (playerKey != ConsoleKey.Escape)
  22.             {
  23.                 playerKey = Console.ReadKey(true).Key;
  24.                 if (playerKey == ConsoleKey.D)
  25.                 {
  26.                     X++;
  27.                 }
  28.  
  29.                 playerKey = Console.ReadKey(true).Key;
  30.                 if (playerKey == ConsoleKey.A)
  31.                 {
  32.                     X--;
  33.                 }
  34.  
  35.                 playerKey = Console.ReadKey(true).Key;
  36.                 if (playerKey == ConsoleKey.W)
  37.                 {
  38.                     Y++;
  39.                 }
  40.  
  41.                 playerKey = Console.ReadKey(true).Key;
  42.                 if (playerKey == ConsoleKey.S)
  43.                 {
  44.                     Y--;
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement