diff --git a/Core/Menu.cs b/Core/Menu.cs
index 0775ad0..1b395a9 100644
--- a/Core/Menu.cs
+++ b/Core/Menu.cs
@@ -10,9 +10,9 @@ namespace laba3.Core
///
/// TUI menu;
///
- public class Menu
+ internal class Menu
{
- private List options;
+ private List options;
private int selected;
private string title;
@@ -23,21 +23,9 @@ namespace laba3.Core
public Menu(string title)
{
this.title = title;
- this.options = new List { };
+ this.options = new List { };
}
- ///
- /// Get options list
- ///
- ///
- public List GetOptions() { return this.options; }
-
- ///
- /// Get title string
- ///
- ///
- public string GetTitle() { return this.title; }
-
///
/// Add option to menu;
///
@@ -45,7 +33,7 @@ namespace laba3.Core
/// Action, runs if option selected
public void AddOption(string name, Action action)
{
- this.options.Add(new MenuOption(name, action));
+ this.options.Add(new Option(name, action));
}
///
@@ -89,7 +77,7 @@ namespace laba3.Core
Console.Clear();
Console.WriteLine(title);
int optionIndex = 0;
- foreach (MenuOption option in options)
+ foreach (Option option in options)
{
string pointer = optionIndex == selected ? " ->" : " ";
Console.WriteLine($"{pointer}{option.Name}");
@@ -97,15 +85,12 @@ namespace laba3.Core
}
}
- ///
- /// Menu option struct;
- ///
- public struct MenuOption
+ private struct Option
{
public string Name { get; }
public Action Action { get; }
- public MenuOption(string name, Action action)
+ public Option(string name, Action action)
{
Name = name;
Action = action;
diff --git a/Core/Program.cs b/Core/Program.cs
index 46548bb..0348517 100644
--- a/Core/Program.cs
+++ b/Core/Program.cs
@@ -1,20 +1,12 @@
using laba3.Core;
using laba3.Subprograms;
-using ProgLab1.GUI;
using System;
-using System.Windows.Forms;
-using static System.Windows.Forms.DataFormats;
class Program
{
- [STAThread] // Требуется для Windows Forms
static void Main()
{
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Menu mainForm = new Menu();
-
- laba3.Core.Menu mainMenu = new laba3.Core.Menu("Select option");
+ Menu mainMenu = new Menu("Select option");
mainMenu.AddOption("Guess answer math game", () => GuessAnswerMath.RunGame());
mainMenu.AddOption("About me", () => PrintAboutMe());
mainMenu.AddOption("Array sort", () => new ArraySortDemo().Run());
@@ -22,13 +14,13 @@ class Program
int sizex = 0;
int sizey = 0;
SnakeGame.Level difficulty = 0;
- laba3.Core.Menu sizeMenu = new laba3.Core.Menu("Select world size");
+ Menu sizeMenu = new Menu("Select world size");
sizeMenu.AddOption("Small size (10x10)", () => { sizex = 10; sizey = 10; });
sizeMenu.AddOption("Medium size (20x20)", () => { sizex = 20; sizey = 20; });
sizeMenu.AddOption("Big size (40x20)", () => { sizex = 40; sizey = 20; });
sizeMenu.RunMenu();
- laba3.Core.Menu difficultyMenu = new laba3.Core.Menu("Select difficulty");
+ Menu difficultyMenu = new Menu("Select difficulty");
difficultyMenu.AddOption("Easy", () => { difficulty = SnakeGame.Level.Low; });
difficultyMenu.AddOption("Medium", () => { difficulty = SnakeGame.Level.Medium; });
difficultyMenu.AddOption("Hard", () => { difficulty = SnakeGame.Level.High; });
@@ -45,16 +37,13 @@ class Program
Utils.Arrays withOneParam = new Utils.Arrays(10);
Utils.Arrays withTwoParams = new Utils.Arrays(10, 100);
- laba3.Core.Menu test = new laba3.Core.Menu("test");
- test.AddOption("a", () => { });
- mainForm.AddMenu(mainMenu);
- mainForm.AddMenu(mainMenu);
- mainForm.AddMenu(mainMenu);
-
-
-
-
- Application.Run(mainForm);
+ while (true)
+ {
+ mainMenu.RunMenu();
+ Console.WriteLine("Press Enter to continue");
+ while (Console.ReadKey().Key != ConsoleKey.Enter) { }
+ Console.Clear();
+ }
}
private static void PrintAboutMe()
diff --git a/GUI/MenuForm.Designer.cs b/GUI/MenuForm.Designer.cs
deleted file mode 100644
index 73563b5..0000000
--- a/GUI/MenuForm.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace ProgLab1.GUI
-{
- partial class Menu
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Main";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/GUI/MenuForm.cs b/GUI/MenuForm.cs
deleted file mode 100644
index 581b4da..0000000
--- a/GUI/MenuForm.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using laba3.Core;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace ProgLab1.GUI
-{
- public partial class MenuForm : Form
- {
- public MenuForm()
- {
- InitializeComponent();
- }
-
- ///
- /// Adds menu to GUI
- ///
- /// TUI menu
- public void AddMenu(Menu consoleMenu)
- {
-
- FlowLayoutPanel buttonPanel = new FlowLayoutPanel
- {
- Dock = DockStyle.Fill, // Растягиваем на всю форму
- FlowDirection = FlowDirection.TopDown, // Кнопки располагаются сверху вниз
- WrapContents = false // Запрет переноса
- };
-
- Label menuLabel = new Label
- {
- Text = consoleMenu.GetTitle(), // Текст заголовка
- Font = new System.Drawing.Font("Arial", 16, System.Drawing.FontStyle.Bold), // Стиль шрифта
- TextAlign = System.Drawing.ContentAlignment.MiddleCenter, // Выравнивание текста по центру
- Dock = DockStyle.Top, // Заголовок сверху
- Height = 40 // Высота заголовка
- };
-
- buttonPanel.Controls.Add(menuLabel);
-
- foreach (MenuOption option in consoleMenu.GetOptions())
- {
- Button button = new Button
- {
- Text = option.Name,
- Width = buttonPanel.Width-10,
- Height = 40,
- Margin = new Padding(5),
- };
-
- // Связываем обработчик с OnSelect из консольного меню
- button.Click += (sender, e) => option.Action();
-
- buttonPanel.Controls.Add(button);
- }
- }
- }
-}
diff --git a/GUI/MenuForm.resx b/GUI/MenuForm.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/GUI/MenuForm.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/ProgLab1.csproj b/ProgLab1.csproj
index 217ede6..2150e37 100644
--- a/ProgLab1.csproj
+++ b/ProgLab1.csproj
@@ -2,10 +2,9 @@
Exe
- net8.0-windows10.0.17763.0
+ net8.0
enable
enable
- True