Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace easyMap_v02
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- bool isPlaying = true;
- char theseus = '♂';
- int theseusX;
- int theseusY;
- int alongX;
- int alongY;
- char[,] maze = ReadMaze();
- DrawMaze(maze, theseus, out theseusX, out theseusY);
- while (isPlaying)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo pressedKey = Console.ReadKey(true);
- ChangeDirection(pressedKey, out alongX, out alongY);
- if (maze[theseusX + alongX, theseusY + alongY] != '#')
- {
- Move(theseus, ref theseusX, ref theseusY, alongX, alongY);
- }
- }
- }
- }
- static char[,] ReadMaze()
- {
- char[,] map = new char[20, 20]
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#',' ',' ',' ',' ',' ','#',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ','#','#','#','#','#',' ','#','#','#','#',' ','#','#','#',' ','#','#','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#',' ','#',' ','#'},
- {'#',' ','#',' ','#','#','#',' ','#','#','#','#','#','#',' ','#',' ','#',' ','#'},
- {'#',' ','#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#',' ','#'},
- {'#',' ','#','#','#',' ','#','#','#','#','#','#',' ','#','#','#','#','#',' ','#'},
- {'#',' ','#','#','#',' ',' ',' ',' ','#',' ','#',' ','#',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ','#','#','#',' ',' ',' ',' ',' ',' ',' ','#','#','#','#','#'},
- {'#','#','#','#','#',' ',' ',' ','#','#','#','#','#','#',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#','#','#',' ','#',' ','#',' ',' ',' ',' ','#',' ','#',' ','#'},
- {'#','#','#',' ','#','#','#',' ','#',' ','#',' ','#','#','#','#',' ','#',' ','#'},
- {'#',' ',' ',' ',' ',' ','#',' ','#',' ',' ',' ','#','#',' ','#',' ','#',' ','#'},
- {'#','#','#','#','#',' ',' ',' ',' ',' ','#','#','#','#',' ','#',' ','#','#','#'},
- {'#',' ',' ',' ',' ',' ','#',' ','#','#','#',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ','#','#','#','#','#',' ','#',' ','#','#','#','#',' ','#','#','#',' ','#'},
- {'#',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ','#',' ',' ',' ',' ',' ','#'},
- {'#',' ','#',' ','#','#','#','#','#','#',' ','#',' ','#','#','#','#','#',' ','#'},
- {'#',' ','#','♂',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}
- };
- return map;
- }
- static void DrawMaze(char[,] map, char theseus, out int theseusX, out int theseusY)
- {
- theseusX = 1;
- theseusY = 1;
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- Console.Write($"{map[i, j]}");
- if (map[i, j] == theseus)
- {
- theseusX = i;
- theseusY = j;
- }
- }
- Console.WriteLine();
- }
- }
- static void ChangeDirection(ConsoleKeyInfo key, out int alongX, out int alongY)
- {
- alongX = 0;
- alongY = 0;
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- alongX = -1; alongY = 0;
- break;
- case ConsoleKey.DownArrow:
- alongX = 1; alongY = 0;
- break;
- case ConsoleKey.LeftArrow:
- alongX = 0; alongY = -1;
- break;
- case ConsoleKey.RightArrow:
- alongX = 0; alongY = 1;
- break;
- }
- }
- static void Move(char theseus, ref int theseusX, ref int theseusY, int alongX, int alongY)
- {
- Console.SetCursorPosition(theseusY, theseusX);
- Console.Write(' ');
- theseusX += alongX;
- theseusY += alongY;
- Console.SetCursorPosition(theseusY, theseusX);
- Console.Write(theseus);
- }
- }
- }
Add Comment
Please, Sign In to add comment