Advertisement
Rodunskiy

Untitled

May 5th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. class program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         Console.CursorVisible = false;
  6.         char[,] map =
  7.         {
  8.             {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
  9.             {'#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ','#'},
  10.             {'#',' ',' ',' ','#','#','#','#',' ','#',' ','#','#','#',' ','#'},
  11.             {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#',' ',' ',' ','#'},
  12.             {'#',' ',' ',' ',' ','#',' ','#','#',' ','#','#','#',' ','#','#'},
  13.             {'#',' ','#','#',' ','#',' ',' ',' ',' ','#','#',' ',' ','#','#'},
  14.             {'#',' ',' ',' ',' ','#','#','#','#',' ','#','#',' ','#','#','#'},
  15.             {'#',' ','#','#',' ',' ',' ',' ','#',' ',' ',' ',' ','#','#','#'},
  16.             {'#',' ','#','#',' ','#','#',' ','#','#','#',' ','#','#','#','#'},
  17.             {'#',' ','#','#',' ','#','#',' ','#','#','#',' ',' ',' ',' ','#'},
  18.             {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
  19.         };
  20.  
  21.         int userX = 10, userY = 1;
  22.  
  23.         while (true)
  24.         {
  25.             MapGeneration(map, userX, userY);
  26.             MapMovement(map,ref userX,ref userY);
  27.         }
  28.     }
  29.  
  30.     static void MapGeneration(char[,] array, int X, int Y)
  31.     {
  32.         for (int i = 0; i < array.GetLength(0); i++)
  33.         {
  34.             for (int j = 0; j < array.GetLength(1); j++)
  35.             {
  36.                 Console.Write(array[i, j]);
  37.             }
  38.             Console.WriteLine();
  39.         }
  40.  
  41.         Console.SetCursorPosition(X, Y);
  42.         Console.WriteLine('@');
  43.     }
  44.  
  45.     static void MapMovement(char[,] array,ref int X,ref int Y)
  46.     {
  47.         ConsoleKeyInfo charKey = Console.ReadKey();
  48.  
  49.         switch (charKey.Key)
  50.         {
  51.             case ConsoleKey.UpArrow:
  52.                 if (array[Y - 1, X] != '#')
  53.                 {
  54.                     Y--;
  55.                 }
  56.                 break;
  57.  
  58.             case ConsoleKey.DownArrow:
  59.                 if (array[Y + 1, X] != '#')
  60.                 {
  61.                     Y++;
  62.                 }
  63.                 break;
  64.  
  65.             case ConsoleKey.LeftArrow:
  66.                 if (array[Y, X - 1] != '#')
  67.                 {
  68.                     X--;
  69.                 }
  70.                 break;
  71.  
  72.             case ConsoleKey.RightArrow:
  73.                 if (array[Y, X + 1] != '#')
  74.                 {
  75.                     X++;
  76.                 }
  77.                 break;
  78.         }
  79.  
  80.         Console.Clear();
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement