Advertisement
RedFlys

Editor

Nov 19th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. class PlayerController
  2.     {
  3.         public int Controller()
  4.         {
  5.             Map map = new Map();
  6.             Player player = new Player();
  7.  
  8.             ConsoleKeyInfo consoleKey = Console.ReadKey();
  9.  
  10.             {
  11.                 switch (consoleKey.Key)
  12.                 {
  13.                     case ConsoleKey.LeftArrow:
  14.                         if (map.Level[player.PlayerPositionX, player.PlayerPositionY - 1] != '#')
  15.                         {
  16.                             return player.PlayerPositionY--;
  17.                         }
  18.                         break;
  19.                     case ConsoleKey.RightArrow:
  20.                         if (map.Level[player.PlayerPositionX, player.PlayerPositionY + 1] != '#')
  21.                         {
  22.                             return player.PlayerPositionY++;
  23.                         }
  24.                         break;
  25.                     case ConsoleKey.UpArrow:
  26.                         if (map.Level[player.PlayerPositionX - 1, player.PlayerPositionY] != '#')
  27.                         {
  28.                             return player.PlayerPositionX--;
  29.                         }
  30.                         break;
  31.                     case ConsoleKey.DownArrow:
  32.                         if (map.Level[player.PlayerPositionX + 1, player.PlayerPositionY] != '#')
  33.                         {
  34.                             return player.PlayerPositionX++;
  35.                         }
  36.                         break;
  37.                 }
  38.             }
  39.         }
  40.  
  41.         static bool TryKey(ConsoleKeyInfo consoleKey)
  42.         {
  43.             if (consoleKey.Key = ConsoleKey.LeftArrow || consoleKey.Key = ConsoleKey.RightArrow || consoleKey.Key = ConsoleKey.UpArrow || consoleKey.Key = ConsoleKey.DownArrow)
  44.                 return true;
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement