Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#','#','#','#',' ','#',' ','#','#','#',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ','#',' ','#','#',' ','#','#','#',' ','#','#'},
- {'#',' ','#','#',' ','#',' ',' ',' ',' ','#','#',' ',' ','#','#'},
- {'#',' ',' ',' ',' ','#','#','#','#',' ','#','#',' ','#','#','#'},
- {'#',' ','#','#',' ',' ',' ',' ','#',' ',' ',' ',' ','#','#','#'},
- {'#',' ','#','#',' ','#','#',' ','#','#','#',' ','#','#','#','#'},
- {'#',' ','#','#',' ','#','#',' ','#','#','#',' ',' ',' ',' ','#'},
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- };
- int userX = 10, userY = 1;
- while (true)
- {
- MapGeneration(map, userX, userY);
- MapMovement(map,ref userX,ref userY);
- }
- }
- static void MapGeneration(char[,] array, int X, int Y)
- {
- for (int i = 0; i < array.GetLength(0); i++)
- {
- for (int j = 0; j < array.GetLength(1); j++)
- {
- Console.Write(array[i, j]);
- }
- Console.WriteLine();
- }
- Console.SetCursorPosition(X, Y);
- Console.WriteLine('@');
- }
- static void MapMovement(char[,] array,ref int X,ref int Y)
- {
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (array[Y - 1, X] != '#')
- {
- Y--;
- }
- break;
- case ConsoleKey.DownArrow:
- if (array[Y + 1, X] != '#')
- {
- Y++;
- }
- break;
- case ConsoleKey.LeftArrow:
- if (array[Y, X - 1] != '#')
- {
- X--;
- }
- break;
- case ConsoleKey.RightArrow:
- if (array[Y, X + 1] != '#')
- {
- X++;
- }
- break;
- }
- Console.Clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement