Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IMJunior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {                            
  9.             Map map = new Map();
  10.             int lines = UserInput("строк", "строк");
  11.             int columns = UserInput("столбцов", "столбцов");
  12.             Console.Clear();
  13.  
  14.             map.DrawMap(lines, columns, '#');
  15.             Console.CursorVisible = false;          
  16.  
  17.             Position position = new Position(columns / 2, lines / 2);
  18.  
  19.             Render render = new Render();
  20.             render.DrawPlayer(position.PositionX, position.PositionY);
  21.  
  22.             Console.ForegroundColor = ConsoleColor.White;
  23.             Console.ReadLine();
  24.         }
  25.         static int UserInput(string message1, string message2)
  26.         {
  27.             int lines;
  28.  
  29.             while (true)
  30.             {
  31.                 Console.Write($"введите кол-во {message1}: ");
  32.                 lines = Convert.ToInt32(Console.ReadLine());
  33.  
  34.                 if (lines < 3)
  35.                     Console.WriteLine($"Слишком мало {message2}!");
  36.                 else
  37.                     break;
  38.             }
  39.             return lines;
  40.         }
  41.     }
  42.    
  43.     class Position
  44.     {
  45.         private int _posX;
  46.         private int _posY;
  47.        
  48.         public int PositionX
  49.         {
  50.             get
  51.             {
  52.                 return _posX;
  53.             }
  54.             private set
  55.             {
  56.                 _posX = value;
  57.             }
  58.         }
  59.  
  60.         public int PositionY
  61.         {
  62.             get
  63.             {
  64.                 return _posY;
  65.             }
  66.             private set
  67.             {
  68.                 _posY = value;
  69.             }
  70.         }
  71.  
  72.         public Position(int posX, int posY)
  73.         {
  74.             _posX = posX;
  75.             _posY = posY;
  76.         }
  77.     }
  78.  
  79.     class Map
  80.     {
  81.         private int _strokNumber;
  82.         private int _stolbNumber;
  83.  
  84.         public void DrawMap(int lines, int columns, char symbol)
  85.         {
  86.             _strokNumber = lines;
  87.             _stolbNumber = columns;
  88.             char[,] map = new char[_strokNumber, _stolbNumber];
  89.  
  90.             for(int i = 0; i < map.GetLength(0); i++)
  91.             {
  92.                 for(int j = 0; j < map.GetLength(1); j++)
  93.                 {
  94.                     if (i == 0 || i == map.GetLength(0) - 1)
  95.                     {
  96.                         map[i, j] = symbol;
  97.                         Console.Write(map[i, j]);
  98.                     }
  99.                     else
  100.                     {
  101.                         if(j == 0 || j == map.GetLength(1) - 1)
  102.                             map[i, j] = symbol;
  103.                         else
  104.                             map[i, j] = ' ';
  105.                         Console.Write(map[i, j]);
  106.                     }
  107.                 }
  108.                 Console.WriteLine();
  109.             }
  110.         }
  111.     }
  112.  
  113.     class Render
  114.     {
  115.         public void DrawPlayer(int x, int y)
  116.         {
  117.             Console.SetCursorPosition(x, y);
  118.             Console.ForegroundColor = ConsoleColor.Green;
  119.             Console.Write('@');
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement