/
Landilf
/
2413_Ryumin_CourseWork
Обзор
Документация
Войти
/
Landilf
/
2413_Ryumin_CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
project
CourseWork/ConsoleUI/Flow/ConsoleGamePopups.cs
165 строк
4 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 RunPauseMenu() { string[] options = [Strings.PauseMenuResume, Strings.PauseMenuRestart, Strings.PauseMenuToMenu]; int selected = 0; while (_currentState == AppState.Pause) { PauseMenuView.Draw(options, selected); var cmd = ConsoleInput.WaitForCommand(); if (cmd == InputCommand.Up) { selected = (selected - 1 + options.Length) % options.Length; } else if (cmd == InputCommand.Down) { selected = (selected + 1) % options.Length; } else if (cmd == InputCommand.Confirm) { switch (selected) { case 0: lock (_controller!.SyncRoot) { _controller?.Resume(); } _currentState = AppState.Game; break; case 1: { if (Confirm(Strings.PromptRestartGame)) { StartGame(); } break; } case 2: { if (Confirm(Strings.PromptExitToMenu)) { _currentState = AppState.MainMenu; } break; } } } } } /// <summary> /// Запускает экран поражения. /// </summary> private static void RunGameOver() { string[] options = [Strings.MainMenuNewGame, Strings.VictoryToMenu]; var selected = 0; while (_currentState == AppState.GameOver) { GameOverView.Draw(options, selected); var cmd = ConsoleInput.WaitForCommand(); switch (cmd) { case InputCommand.Up: selected = (selected - 1 + options.Length) % options.Length; break; case InputCommand.Down: selected = (selected + 1) % options.Length; break; case InputCommand.Confirm when selected == 0: StartGame(); break; case InputCommand.Confirm: { if (selected == 1) { _currentState = AppState.MainMenu; } break; } } } } private static void RunVictory() { var duration = _controller?.Session.GetDuration() ?? TimeSpan.Zero; bool isInTop = _controller!.IsTopScore((int)duration.TotalSeconds); var options = new List<string> { Strings.VictoryToMenu }; if (isInTop) { options.Add(Strings.VictorySave); } options.Add(Strings.MainMenuNewGame); var selected = isInTop ? 1 : 0; while (_currentState == AppState.Victory) { VictoryView.Draw(duration, isInTop, options.ToArray(), selected); 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.VictorySave) { string? input = VictoryView.DrawNameInput(); string name = string.IsNullOrWhiteSpace(input) ? "Player" : input; if (_controller.HasScore(name)) { if (Confirm(Strings.PromptOverwriteScore)) { _controller.OverwriteScore(name, (int)duration.TotalSeconds); _currentState = AppState.HighScores; } } else { _controller.SubmitScore(name); _currentState = AppState.HighScores; } } else if (choice == Strings.MainMenuNewGame) { StartGame(); } else if (choice == Strings.VictoryToMenu) { _currentState = AppState.MainMenu; } } } } #endregion }