/
Landilf
/
2413_Ryumin_CourseWork
Обзор
Документация
Войти
/
Landilf
/
2413_Ryumin_CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CourseWork/ConsoleUI/Flow/ConsoleGameMenus.cs
141 строка
3 KB
Landilf
add project
27 янв 2026, 13:57
27 янв 2026, 13:57
753b3e7
Код
Авторство
О чём код?
using ConsoleUI.Enums; using ConsoleUI.Views; using GameCore.Resources; namespace ConsoleUI.Flow; /// <summary> /// Часть класса, отвечающая за меню (Главное, Помощь, Рекорды). /// </summary> public static partial class ConsoleGame { #region Методы /// <summary> /// Запускает цикл главного меню. /// </summary> private static void RunMainMenu() { var options = new List<string>(); lock (_controller!.SyncRoot) { if (_controller.State == GameCore.Enums.GameState.Paused) { options.Add(Strings.MainMenuResume); } } options.AddRange([Strings.MainMenuNewGame, Strings.MainMenuHighScores, Strings.MainMenuHelp, Strings.MainMenuExit]); var selected = 0; while (_currentState == AppState.MainMenu) { bool canResume = options.Contains(Strings.MainMenuResume); MainMenuView.Draw(options.ToArray(), selected, canResume); var cmd = ConsoleInput.WaitForCommand(); if (cmd == InputCommand.Up) { selected = (selected - 1 + options.Count) % options.Count; } else if (cmd == InputCommand.Down) { selected = (selected + 1) % options.Count; } else if (cmd == InputCommand.Confirm) { var choice = options[selected]; if (choice == Strings.MainMenuResume) { lock (_controller.SyncRoot) { _controller.Resume(); } _currentState = AppState.Game; } else if (choice == Strings.MainMenuNewGame) { StartGame(); } else if (choice == Strings.MainMenuHighScores) { _currentState = AppState.HighScores; } else if (choice == Strings.MainMenuHelp) { _currentState = AppState.Help; } else if (choice == Strings.MainMenuExit) { if (Confirm(Strings.PromptExitGame)) { _running = false; return; } } } } } /// <summary> /// Запускает экран таблицы рекордов. /// </summary> private static void RunHighScores() { var scores = _controller!.GetHighScores(); HighScoresView.Draw(scores); while (ConsoleInput.WaitForCommand() != InputCommand.Confirm) { } _currentState = AppState.MainMenu; } /// <summary> /// Запускает экран справки. /// </summary> private static void RunHelp() { HelpView.Draw(); while (ConsoleInput.WaitForCommand() != InputCommand.Confirm) { } _currentState = AppState.MainMenu; } /// <summary> /// Показывает диалог подтверждения (Да/Нет). /// </summary> /// <param name="parMessage">Сообщение вопроса.</param> /// <returns>True, если выбрано "Да".</returns> private static bool Confirm(string parMessage) { var selected = 1; string[] options = [Strings.PromptYes, Strings.PromptNo]; while (true) { ConfirmationView.Draw(parMessage, options, selected); var cmd = ConsoleInput.WaitForCommand(); switch (cmd) { case InputCommand.Left: selected = (selected - 1 + options.Length) % options.Length; break; case InputCommand.Right: selected = (selected + 1) % options.Length; break; case InputCommand.Confirm: return selected == 0; } } } #endregion }