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