Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- Map map = new Map();
- int lines = UserInput("строк", "строк");
- int columns = UserInput("столбцов", "столбцов");
- Console.Clear();
- map.DrawMap(lines, columns, '#');
- Console.CursorVisible = false;
- Position position = new Position(columns / 2, lines / 2);
- Render render = new Render();
- render.DrawPlayer(position.PositionX, position.PositionY);
- Console.ForegroundColor = ConsoleColor.White;
- Console.ReadLine();
- }
- static int UserInput(string message1, string message2)
- {
- int lines;
- while (true)
- {
- Console.Write($"введите кол-во {message1}: ");
- lines = Convert.ToInt32(Console.ReadLine());
- if (lines < 3)
- Console.WriteLine($"Слишком мало {message2}!");
- else
- break;
- }
- return lines;
- }
- }
- class Position
- {
- private int _posX;
- private int _posY;
- public int PositionX
- {
- get
- {
- return _posX;
- }
- private set
- {
- _posX = value;
- }
- }
- public int PositionY
- {
- get
- {
- return _posY;
- }
- private set
- {
- _posY = value;
- }
- }
- public Position(int posX, int posY)
- {
- _posX = posX;
- _posY = posY;
- }
- }
- class Map
- {
- private int _strokNumber;
- private int _stolbNumber;
- public void DrawMap(int lines, int columns, char symbol)
- {
- _strokNumber = lines;
- _stolbNumber = columns;
- char[,] map = new char[_strokNumber, _stolbNumber];
- for(int i = 0; i < map.GetLength(0); i++)
- {
- for(int j = 0; j < map.GetLength(1); j++)
- {
- if (i == 0 || i == map.GetLength(0) - 1)
- {
- map[i, j] = symbol;
- Console.Write(map[i, j]);
- }
- else
- {
- if(j == 0 || j == map.GetLength(1) - 1)
- map[i, j] = symbol;
- else
- map[i, j] = ' ';
- Console.Write(map[i, j]);
- }
- }
- Console.WriteLine();
- }
- }
- }
- class Render
- {
- public void DrawPlayer(int x, int y)
- {
- Console.SetCursorPosition(x, y);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write('@');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement