Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp5
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Выберите размеры карты");
- Console.Write("Ширина");
- int width = Convert.ToInt32(Console.ReadLine());
- Console.Write("Длина");
- int length = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- string[,] map = new string[length, width];
- Borders(map, width, length);
- DrawingMap(map);
- }
- static void Borders(string[,] map, int width, int length)
- {
- for (int i = 0; i < length; i++)
- {
- for (int j = 0; j < width; j++)
- {
- map[i, j]= " ";
- }
- }
- for (int i = 0; i < length; i++)
- {
- map[i, 0] = "#";
- map[i, width -1 ] = "#";
- }
- for (int j = 0; j < width; j++)
- {
- map[0, j] = "#";
- map[length-1, j] = "#";
- }
- for (int i = 0; i < length; i++)
- {
- for (int j = 0; j < width; j++)
- {
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void DrawingMap(string[,] map)
- {
- int cursorX = 1 , cursorY = 1;
- Console.SetCursorPosition(cursorY, cursorX);
- while (true)
- {
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- if (map[cursorX, cursorY-1] != "#")
- {
- Console.SetCursorPosition(cursorX, --cursorY);
- }
- break;
- case ConsoleKey.DownArrow:
- if (map[cursorX, cursorY+1] != "#")
- {
- Console.SetCursorPosition(cursorX, ++cursorY);
- }
- break;
- case ConsoleKey.LeftArrow:
- Console.SetCursorPosition(--cursorX, cursorY);
- break;
- case ConsoleKey.RightArrow:
- Console.SetCursorPosition(++cursorX, cursorY);
- break;
- default:
- Console.WriteLine("Вы нажали не ту клавишу!");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement