IGRODELOFF

SimpleGameMap_v2

Feb 26th, 2026
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.63 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace SimpleGameMap
  5. {
  6.     internal struct Record
  7.     {
  8.         public int Width;
  9.         public int Height;
  10.         public int TreasureCount;
  11.         public TimeSpan Time;
  12.     }
  13.  
  14.     internal class Game
  15.     {
  16.         private const char Wall = '#';
  17.         private const char Floor = '.';
  18.         private const char Treasure = 'T';
  19.         private const char Player = '@';
  20.  
  21.         private const char BorderTopLeft = '+';
  22.         private const char BorderTopRight = '+';
  23.         private const char BorderBottomLeft = '+';
  24.         private const char BorderBottomRight = '+';
  25.         private const char BorderHorizontal = '-';
  26.         private const char BorderVertical = '|';
  27.  
  28.         private char[,] map;
  29.         private int playerRow;
  30.         private int playerColumn;
  31.         private int currentScore;
  32.         private int totalTreasures;
  33.         private readonly int mapHeight;
  34.         private readonly int mapWidth;
  35.         private readonly int treasureCount;
  36.  
  37.         private DateTime startTime;
  38.         public TimeSpan PlayTime { get; private set; }
  39.  
  40.         private int Rows => map.GetLength(0);
  41.         private int Columns => map.GetLength(1);
  42.  
  43.         private const int InfoLines = 3;
  44.         private int TotalDrawLines => Rows + 2 + InfoLines;
  45.  
  46.         private readonly Random random = new Random();
  47.  
  48.         public Game(int height, int width, int treasureCount)
  49.         {
  50.             mapHeight = height;
  51.             mapWidth = width;
  52.             this.treasureCount = treasureCount;
  53.             InitializeMap();
  54.             SpawnPlayer();
  55.             PlaceTreasures();
  56.             currentScore = 0;
  57.         }
  58.  
  59.         public bool Run()
  60.         {
  61.             Console.CursorVisible = false;
  62.             Console.Clear();
  63.             startTime = DateTime.Now;
  64.             bool isRunning = true;
  65.             bool victory = false;
  66.  
  67.             while (isRunning == true)
  68.             {
  69.                 DrawMap();
  70.                 ConsoleKeyInfo keyInfo = Console.ReadKey(true);
  71.  
  72.                 if (keyInfo.Key == ConsoleKey.Escape)
  73.                 {
  74.                     var menuResult = ShowPauseMenu();
  75.                     if (menuResult == PauseMenuResult.ExitToMainMenu)
  76.                     {
  77.                         isRunning = false;
  78.                     }
  79.                 }
  80.                 else
  81.                 {
  82.                     ProcessPlayerInput(keyInfo);
  83.                     if (currentScore == totalTreasures)
  84.                     {
  85.                         victory = true;
  86.                         isRunning = false;
  87.                     }
  88.                 }
  89.             }
  90.  
  91.             PlayTime = DateTime.Now - startTime;
  92.  
  93.             if (victory == true)
  94.             {
  95.                 ShowVictory();
  96.                 return true;
  97.             }
  98.             else
  99.             {
  100.                 ShowGameInterrupted();
  101.                 Console.CursorVisible = true;
  102.                 return false;
  103.             }
  104.         }
  105.  
  106.         private void InitializeMap()
  107.         {
  108.             map = new char[mapHeight, mapWidth];
  109.             for (int row = 0; row < mapHeight; row++)
  110.             {
  111.                 for (int column = 0; column < mapWidth; column++)
  112.                 {
  113.                     map[row, column] = Wall;
  114.                 }
  115.             }
  116.  
  117.             GenerateMaze();
  118.         }
  119.  
  120.         private void GenerateMaze()
  121.         {
  122.             int startRow = random.Next(1, mapHeight - 1);
  123.             int startColumn = random.Next(1, mapWidth - 1);
  124.             map[startRow, startColumn] = Floor;
  125.  
  126.             var frontierCells = new List<(int row, int column)>();
  127.             AddFrontierCells(startRow, startColumn, frontierCells);
  128.  
  129.             while (frontierCells.Count > 0)
  130.             {
  131.                 int randomIndex = random.Next(frontierCells.Count);
  132.                 var (currentRow, currentColumn) = frontierCells[randomIndex];
  133.                 frontierCells.RemoveAt(randomIndex);
  134.  
  135.                 int passageNeighbourCount = 0;
  136.                 int[] rowOffsets = { -1, 1, 0, 0 };
  137.                 int[] columnOffsets = { 0, 0, -1, 1 };
  138.  
  139.                 foreach (var directionIndex in new[] { 0, 1, 2, 3 })
  140.                 {
  141.                     int neighbourRow = currentRow + rowOffsets[directionIndex];
  142.                     int neighbourColumn = currentColumn + columnOffsets[directionIndex];
  143.                     if (neighbourRow >= 0 && neighbourRow < mapHeight &&
  144.                         neighbourColumn >= 0 && neighbourColumn < mapWidth &&
  145.                         map[neighbourRow, neighbourColumn] == Floor)
  146.                     {
  147.                         passageNeighbourCount++;
  148.                     }
  149.                 }
  150.  
  151.                 if (passageNeighbourCount == 1)
  152.                 {
  153.                     map[currentRow, currentColumn] = Floor;
  154.                     AddFrontierCells(currentRow, currentColumn, frontierCells);
  155.                 }
  156.             }
  157.         }
  158.  
  159.         private void AddFrontierCells(int row, int column, List<(int, int)> frontierCells)
  160.         {
  161.             int[] rowOffsets = { -1, 1, 0, 0 };
  162.             int[] columnOffsets = { 0, 0, -1, 1 };
  163.  
  164.             for (int direction = 0; direction < 4; direction++)
  165.             {
  166.                 int neighbourRow = row + rowOffsets[direction];
  167.                 int neighbourColumn = column + columnOffsets[direction];
  168.                 if (neighbourRow >= 0 && neighbourRow < mapHeight &&
  169.                     neighbourColumn >= 0 && neighbourColumn < mapWidth &&
  170.                     map[neighbourRow, neighbourColumn] == Wall)
  171.                 {
  172.                     if (frontierCells.Contains((neighbourRow, neighbourColumn)) == false)
  173.                     {
  174.                         frontierCells.Add((neighbourRow, neighbourColumn));
  175.                     }
  176.                 }
  177.             }
  178.         }
  179.  
  180.         private List<(int row, int column)> GetFreeCells(int excludeRow = -1, int excludeColumn = -1)
  181.         {
  182.             var freeCells = new List<(int, int)>();
  183.             for (int row = 0; row < mapHeight; row++)
  184.             {
  185.                 for (int column = 0; column < mapWidth; column++)
  186.                 {
  187.                     if (map[row, column] != Wall && (row == excludeRow && column == excludeColumn) == false)
  188.                     {
  189.                         freeCells.Add((row, column));
  190.                     }
  191.                 }
  192.             }
  193.             return freeCells;
  194.         }
  195.  
  196.         private void SpawnPlayer()
  197.         {
  198.             var freeCells = GetFreeCells();
  199.             if (freeCells.Count == 0)
  200.             {
  201.                 playerRow = 1;
  202.                 playerColumn = 1;
  203.                 return;
  204.             }
  205.             int randomIndex = random.Next(freeCells.Count);
  206.             (playerRow, playerColumn) = freeCells[randomIndex];
  207.         }
  208.  
  209.         private void PlaceTreasures()
  210.         {
  211.             var freeCells = GetFreeCells(playerRow, playerColumn);
  212.             int treasuresToPlace = treasureCount;
  213.             if (treasuresToPlace > freeCells.Count)
  214.             {
  215.                 treasuresToPlace = freeCells.Count;
  216.             }
  217.  
  218.             for (int firstIndex = 0; firstIndex < freeCells.Count; firstIndex++)
  219.             {
  220.                 int secondIndex = random.Next(firstIndex, freeCells.Count);
  221.                 var temp = freeCells[firstIndex];
  222.                 freeCells[firstIndex] = freeCells[secondIndex];
  223.                 freeCells[secondIndex] = temp;
  224.             }
  225.  
  226.             for (int treasureIndex = 0; treasureIndex < treasuresToPlace; treasureIndex++)
  227.             {
  228.                 var (treasureRow, treasureColumn) = freeCells[treasureIndex];
  229.                 map[treasureRow, treasureColumn] = Treasure;
  230.             }
  231.  
  232.             totalTreasures = treasuresToPlace;
  233.         }
  234.  
  235.         private void ClearLines(int lineCount, int startLine = 0)
  236.         {
  237.             int windowWidth = Console.WindowWidth;
  238.             for (int lineIndex = 0; lineIndex < lineCount; lineIndex++)
  239.             {
  240.                 Console.SetCursorPosition(0, startLine + lineIndex);
  241.                 Console.Write(new string(' ', windowWidth));
  242.             }
  243.         }
  244.  
  245.         private void DrawMap()
  246.         {
  247.             int mapWidthWithBorders = Columns + 2;
  248.             int startColumn = (Console.WindowWidth - mapWidthWithBorders) / 2;
  249.             if (startColumn < 0)
  250.             {
  251.                 startColumn = 0;
  252.             }
  253.  
  254.             ClearLines(TotalDrawLines);
  255.  
  256.             Console.SetCursorPosition(startColumn, 0);
  257.             Console.Write(BorderTopLeft);
  258.             Console.Write(new string(BorderHorizontal, Columns));
  259.             Console.Write(BorderTopRight);
  260.  
  261.             for (int row = 0; row < Rows; row++)
  262.             {
  263.                 Console.SetCursorPosition(startColumn, row + 1);
  264.                 Console.Write(BorderVertical);
  265.                 for (int column = 0; column < Columns; column++)
  266.                 {
  267.                     if (row == playerRow && column == playerColumn)
  268.                     {
  269.                         Console.Write(Player);
  270.                     }
  271.                     else
  272.                     {
  273.                         Console.Write(map[row, column]);
  274.                     }
  275.                 }
  276.                 Console.Write(BorderVertical);
  277.             }
  278.  
  279.             int bottomLine = Rows + 1;
  280.             Console.SetCursorPosition(startColumn, bottomLine);
  281.             Console.Write(BorderBottomLeft);
  282.             Console.Write(new string(BorderHorizontal, Columns));
  283.             Console.Write(BorderBottomRight);
  284.  
  285.             int infoLine = bottomLine + 1;
  286.             string scoreText = $"Счёт: {currentScore}  Осталось сокровищ: {totalTreasures - currentScore}";
  287.             string helpText = "Стрелки - движение, Esc - меню";
  288.  
  289.             Console.SetCursorPosition(startColumn, infoLine);
  290.             Console.Write(scoreText.PadRight(mapWidthWithBorders));
  291.  
  292.             Console.SetCursorPosition(startColumn, infoLine + 1);
  293.             Console.Write(helpText.PadRight(mapWidthWithBorders));
  294.         }
  295.  
  296.         private void ProcessPlayerInput(ConsoleKeyInfo keyInfo)
  297.         {
  298.             int newPlayerRow = playerRow;
  299.             int newPlayerColumn = playerColumn;
  300.  
  301.             switch (keyInfo.Key)
  302.             {
  303.                 case ConsoleKey.UpArrow:
  304.                     newPlayerRow--;
  305.                     break;
  306.                 case ConsoleKey.DownArrow:
  307.                     newPlayerRow++;
  308.                     break;
  309.                 case ConsoleKey.LeftArrow:
  310.                     newPlayerColumn--;
  311.                     break;
  312.                 case ConsoleKey.RightArrow:
  313.                     newPlayerColumn++;
  314.                     break;
  315.                 default:
  316.                     return;
  317.             }
  318.  
  319.             if (newPlayerRow >= 0 && newPlayerRow < Rows &&
  320.                 newPlayerColumn >= 0 && newPlayerColumn < Columns &&
  321.                 map[newPlayerRow, newPlayerColumn] != Wall)
  322.             {
  323.                 if (map[newPlayerRow, newPlayerColumn] == Treasure)
  324.                 {
  325.                     currentScore++;
  326.                     map[newPlayerRow, newPlayerColumn] = Floor;
  327.                 }
  328.  
  329.                 playerRow = newPlayerRow;
  330.                 playerColumn = newPlayerColumn;
  331.             }
  332.         }
  333.  
  334.         private PauseMenuResult ShowPauseMenu()
  335.         {
  336.             int menuWidth = 30;
  337.             int menuHeight = 8;
  338.             int startColumn = (Console.WindowWidth - menuWidth) / 2;
  339.             int startRow = (Console.WindowHeight - menuHeight) / 2;
  340.  
  341.             Console.Clear();
  342.             DrawFrame(startColumn, startRow, menuWidth, menuHeight);
  343.  
  344.             string title = "МЕНЮ";
  345.             Console.SetCursorPosition(startColumn + (menuWidth - title.Length) / 2, startRow + 1);
  346.             Console.Write(title);
  347.  
  348.             string continueText = "1. Продолжить";
  349.             string exitToMainText = "2. Выйти в главное меню";
  350.             string escHint = "Esc - вернуться в игру";
  351.  
  352.             Console.SetCursorPosition(startColumn + (menuWidth - continueText.Length) / 2, startRow + 3);
  353.             Console.Write(continueText);
  354.             Console.SetCursorPosition(startColumn + (menuWidth - exitToMainText.Length) / 2, startRow + 4);
  355.             Console.Write(exitToMainText);
  356.             Console.SetCursorPosition(startColumn + (menuWidth - escHint.Length) / 2, startRow + 6);
  357.             Console.Write(escHint);
  358.  
  359.             bool waiting = true;
  360.             PauseMenuResult result = PauseMenuResult.Continue;
  361.  
  362.             while (waiting == true)
  363.             {
  364.                 ConsoleKeyInfo key = Console.ReadKey(true);
  365.                 if (key.Key == ConsoleKey.D1 || key.Key == ConsoleKey.NumPad1 || key.Key == ConsoleKey.Escape)
  366.                 {
  367.                     result = PauseMenuResult.Continue;
  368.                     waiting = false;
  369.                 }
  370.                 else if (key.Key == ConsoleKey.D2 || key.Key == ConsoleKey.NumPad2)
  371.                 {
  372.                     result = PauseMenuResult.ExitToMainMenu;
  373.                     waiting = false;
  374.                 }
  375.             }
  376.  
  377.             Console.Clear();
  378.             return result;
  379.         }
  380.  
  381.         private void ShowVictory()
  382.         {
  383.             Console.Clear();
  384.  
  385.             int menuWidth = 40;
  386.             int menuHeight = 10;
  387.             int startColumn = (Console.WindowWidth - menuWidth) / 2;
  388.             int startRow = (Console.WindowHeight - menuHeight) / 2;
  389.  
  390.             DrawFrame(startColumn, startRow, menuWidth, menuHeight);
  391.  
  392.             string title = "ПОБЕДА!";
  393.             Console.SetCursorPosition(startColumn + (menuWidth - title.Length) / 2, startRow + 1);
  394.             Console.Write(title);
  395.  
  396.             string info1 = $"Размер карты: {mapWidth} x {mapHeight}";
  397.             string info2 = $"Сокровищ собрано: {currentScore} из {totalTreasures}";
  398.             string info3 = $"Время: {PlayTime:mm\\:ss}";
  399.  
  400.             Console.SetCursorPosition(startColumn + (menuWidth - info1.Length) / 2, startRow + 3);
  401.             Console.Write(info1);
  402.             Console.SetCursorPosition(startColumn + (menuWidth - info2.Length) / 2, startRow + 4);
  403.             Console.Write(info2);
  404.             Console.SetCursorPosition(startColumn + (menuWidth - info3.Length) / 2, startRow + 5);
  405.             Console.Write(info3);
  406.  
  407.             string continueText = "Нажмите любую клавишу для продолжения...";
  408.             Console.SetCursorPosition(startColumn + (menuWidth - continueText.Length) / 2, startRow + 7);
  409.             Console.Write(continueText);
  410.  
  411.             Console.ReadKey(true);
  412.             Console.Clear();
  413.         }
  414.  
  415.         private void ShowGameInterrupted()
  416.         {
  417.             Console.Clear();
  418.  
  419.             int menuWidth = 40;
  420.             int menuHeight = 8;
  421.             int startColumn = (Console.WindowWidth - menuWidth) / 2;
  422.             int startRow = (Console.WindowHeight - menuHeight) / 2;
  423.  
  424.             DrawFrame(startColumn, startRow, menuWidth, menuHeight);
  425.  
  426.             string title = "ИГРА ПРЕРВАНА";
  427.             Console.SetCursorPosition(startColumn + (menuWidth - title.Length) / 2, startRow + 1);
  428.             Console.Write(title);
  429.  
  430.             string scoreText = $"Ваш счёт: {currentScore}";
  431.             Console.SetCursorPosition(startColumn + (menuWidth - scoreText.Length) / 2, startRow + 3);
  432.             Console.Write(scoreText);
  433.  
  434.             string continueText = "Нажмите любую клавишу для возврата...";
  435.             Console.SetCursorPosition(startColumn + (menuWidth - continueText.Length) / 2, startRow + 5);
  436.             Console.Write(continueText);
  437.  
  438.             Console.ReadKey(true);
  439.         }
  440.  
  441.         private void DrawFrame(int left, int top, int width, int height)
  442.         {
  443.             Console.SetCursorPosition(left, top);
  444.             Console.Write('┌' + new string('─', width - 2) + '┐');
  445.  
  446.             for (int lineIndex = 1; lineIndex < height - 1; lineIndex++)
  447.             {
  448.                 Console.SetCursorPosition(left, top + lineIndex);
  449.                 Console.Write('│' + new string(' ', width - 2) + '│');
  450.             }
  451.  
  452.             Console.SetCursorPosition(left, top + height - 1);
  453.             Console.Write('└' + new string('─', width - 2) + '┘');
  454.         }
  455.  
  456.         private enum PauseMenuResult
  457.         {
  458.             Continue,
  459.             ExitToMainMenu
  460.         }
  461.     }
  462.  
  463.     internal static class Program
  464.     {
  465.         private static List<Record> records = new List<Record>();
  466.  
  467.         private static void Main()
  468.         {
  469.             Console.OutputEncoding = System.Text.Encoding.UTF8;
  470.             bool exitProgram = false;
  471.  
  472.             while (exitProgram == false)
  473.             {
  474.                 Console.Clear();
  475.                 int menuWidth = 30;
  476.                 int menuHeight = 7;
  477.                 int startColumn = (Console.WindowWidth - menuWidth) / 2;
  478.                 int startRow = (Console.WindowHeight - menuHeight) / 2;
  479.  
  480.                 DrawFrame(startColumn, startRow, menuWidth, menuHeight);
  481.  
  482.                 string title = "ГЛАВНОЕ МЕНЮ";
  483.                 Console.SetCursorPosition(startColumn + (menuWidth - title.Length) / 2, startRow + 1);
  484.                 Console.Write(title);
  485.  
  486.                 string newGameText = "1. Новая игра";
  487.                 string recordsText = "2. История побед";
  488.                 string exitText = "3. Выход";
  489.  
  490.                 Console.SetCursorPosition(startColumn + (menuWidth - newGameText.Length) / 2, startRow + 3);
  491.                 Console.Write(newGameText);
  492.                 Console.SetCursorPosition(startColumn + (menuWidth - recordsText.Length) / 2, startRow + 4);
  493.                 Console.Write(recordsText);
  494.                 Console.SetCursorPosition(startColumn + (menuWidth - exitText.Length) / 2, startRow + 5);
  495.                 Console.Write(exitText);
  496.  
  497.                 ConsoleKeyInfo key = Console.ReadKey(true);
  498.                 switch (key.KeyChar)
  499.                 {
  500.                     case '1':
  501.                         StartNewGame();
  502.                         break;
  503.                     case '2':
  504.                         ShowRecords();
  505.                         break;
  506.                     case '3':
  507.                         exitProgram = true;
  508.                         break;
  509.                 }
  510.                 Console.Clear();
  511.             }
  512.         }
  513.  
  514.         private static int GetIntFromUser(string prompt, int min, int max)
  515.         {
  516.             int result = 0;
  517.             bool valid = false;
  518.  
  519.             while (valid == false)
  520.             {
  521.                 Console.Clear();
  522.  
  523.                 int menuWidth = 50;
  524.                 int menuHeight = 7;
  525.                 int startColumn = (Console.WindowWidth - menuWidth) / 2;
  526.                 int startRow = (Console.WindowHeight - menuHeight) / 2;
  527.  
  528.                 DrawFrame(startColumn, startRow, menuWidth, menuHeight);
  529.  
  530.                 string title = "ВВОД ПАРАМЕТРА";
  531.                 Console.SetCursorPosition(startColumn + (menuWidth - title.Length) / 2, startRow + 1);
  532.                 Console.Write(title);
  533.  
  534.                 string fullPrompt = $"{prompt} (от {min} до {max}):";
  535.                 Console.SetCursorPosition(startColumn + (menuWidth - fullPrompt.Length) / 2, startRow + 3);
  536.                 Console.Write(fullPrompt);
  537.  
  538.                 Console.SetCursorPosition(startColumn + 2, startRow + 5);
  539.                 Console.Write(new string(' ', menuWidth - 4));
  540.                 Console.SetCursorPosition(startColumn + 2, startRow + 5);
  541.                 Console.CursorVisible = true;
  542.                 string input = Console.ReadLine();
  543.                 Console.CursorVisible = false;
  544.  
  545.                 if (int.TryParse(input, out result) == true && result >= min && result <= max)
  546.                 {
  547.                     valid = true;
  548.                 }
  549.                 else
  550.                 {
  551.                     Console.SetCursorPosition(startColumn + 2, startRow + 6);
  552.                     Console.Write("Ошибка! Нажмите любую клавишу...".PadRight(menuWidth - 4));
  553.                     Console.ReadKey(true);
  554.                 }
  555.             }
  556.  
  557.             return result;
  558.         }
  559.  
  560.         private static void StartNewGame()
  561.         {
  562.             int width = GetIntFromUser("Введите ширину карты", 5, Console.WindowWidth - 2);
  563.             int height = GetIntFromUser("Введите высоту карты", 5, Console.WindowHeight - 5);
  564.             int maxTreasures = (height - 2) * (width - 2) / 2;
  565.             int treasureCount = GetIntFromUser("Введите количество сокровищ", 1, maxTreasures);
  566.  
  567.             Game game = new Game(height, width, treasureCount);
  568.             bool victory = game.Run();
  569.             if (victory == true)
  570.             {
  571.                 Record rec = new Record
  572.                 {
  573.                     Width = width,
  574.                     Height = height,
  575.                     TreasureCount = treasureCount,
  576.                     Time = game.PlayTime
  577.                 };
  578.                 records.Add(rec);
  579.                 ShowRecords();
  580.             }
  581.         }
  582.  
  583.         private static void ShowRecords()
  584.         {
  585.             Console.Clear();
  586.             int menuWidth = 50;
  587.             int menuHeight = Math.Max(10, records.Count + 5);
  588.             int startColumn = (Console.WindowWidth - menuWidth) / 2;
  589.             int startRow = (Console.WindowHeight - menuHeight) / 2;
  590.  
  591.             DrawFrame(startColumn, startRow, menuWidth, menuHeight);
  592.  
  593.             string title = "ИСТОРИЯ ПОБЕД";
  594.             Console.SetCursorPosition(startColumn + (menuWidth - title.Length) / 2, startRow + 1);
  595.             Console.Write(title);
  596.  
  597.             if (records.Count == 0)
  598.             {
  599.                 string noRecords = "Пока нет записей";
  600.                 Console.SetCursorPosition(startColumn + (menuWidth - noRecords.Length) / 2, startRow + 3);
  601.                 Console.Write(noRecords);
  602.             }
  603.             else
  604.             {
  605.                 string header = "Ширина Высота Сокровища Время";
  606.                 Console.SetCursorPosition(startColumn + (menuWidth - header.Length) / 2, startRow + 3);
  607.                 Console.Write(header);
  608.  
  609.                 var sortedRecords = records.OrderBy(record => record.Time).ToList();
  610.                 for (int recordIndex = 0; recordIndex < sortedRecords.Count; recordIndex++)
  611.                 {
  612.                     var currentRecord = sortedRecords[recordIndex];
  613.                     string line = $"{currentRecord.Width,7} {currentRecord.Height,6} {currentRecord.TreasureCount,9} {currentRecord.Time:mm\\:ss}";
  614.                     Console.SetCursorPosition(startColumn + (menuWidth - line.Length) / 2, startRow + 4 + recordIndex);
  615.                     Console.Write(line);
  616.                 }
  617.             }
  618.  
  619.             string backText = "Нажмите любую клавишу для возврата...";
  620.             Console.SetCursorPosition(startColumn + (menuWidth - backText.Length) / 2, startRow + menuHeight - 2);
  621.             Console.Write(backText);
  622.  
  623.             Console.ReadKey(true);
  624.         }
  625.  
  626.         private static void DrawFrame(int left, int top, int width, int height)
  627.         {
  628.             Console.SetCursorPosition(left, top);
  629.             Console.Write('┌' + new string('─', width - 2) + '┐');
  630.  
  631.             for (int lineIndex = 1; lineIndex < height - 1; lineIndex++)
  632.             {
  633.                 Console.SetCursorPosition(left, top + lineIndex);
  634.                 Console.Write('│' + new string(' ', width - 2) + '│');
  635.             }
  636.  
  637.             Console.SetCursorPosition(left, top + height - 1);
  638.             Console.Write('└' + new string('─', width - 2) + '┘');
  639.         }
  640.     }
  641. }
Advertisement
Add Comment
Please, Sign In to add comment