diff --git a/Core/Menu.cs b/Core/Menu.cs
index 1b395a9..0775ad0 100644
--- a/Core/Menu.cs
+++ b/Core/Menu.cs
@@ -10,9 +10,9 @@ namespace laba3.Core
///
/// TUI menu;
///
- internal class Menu
+ public class Menu
{
- private List options;
+ private List options;
private int selected;
private string title;
@@ -23,9 +23,21 @@ 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;
///
@@ -33,7 +45,7 @@ namespace laba3.Core
/// Action, runs if option selected
public void AddOption(string name, Action action)
{
- this.options.Add(new Option(name, action));
+ this.options.Add(new MenuOption(name, action));
}
///
@@ -77,7 +89,7 @@ namespace laba3.Core
Console.Clear();
Console.WriteLine(title);
int optionIndex = 0;
- foreach (Option option in options)
+ foreach (MenuOption option in options)
{
string pointer = optionIndex == selected ? " ->" : " ";
Console.WriteLine($"{pointer}{option.Name}");
@@ -85,12 +97,15 @@ namespace laba3.Core
}
}
- private struct Option
+ ///
+ /// Menu option struct;
+ ///
+ public struct MenuOption
{
public string Name { get; }
public Action Action { get; }
- public Option(string name, Action action)
+ public MenuOption(string name, Action action)
{
Name = name;
Action = action;
diff --git a/Core/Program.cs b/Core/Program.cs
index 0348517..46548bb 100644
--- a/Core/Program.cs
+++ b/Core/Program.cs
@@ -1,12 +1,20 @@
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()
{
- Menu mainMenu = new Menu("Select option");
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Menu mainForm = new Menu();
+
+ laba3.Core.Menu mainMenu = new laba3.Core.Menu("Select option");
mainMenu.AddOption("Guess answer math game", () => GuessAnswerMath.RunGame());
mainMenu.AddOption("About me", () => PrintAboutMe());
mainMenu.AddOption("Array sort", () => new ArraySortDemo().Run());
@@ -14,13 +22,13 @@ class Program
int sizex = 0;
int sizey = 0;
SnakeGame.Level difficulty = 0;
- Menu sizeMenu = new Menu("Select world size");
+ laba3.Core.Menu sizeMenu = new laba3.Core.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();
- Menu difficultyMenu = new Menu("Select difficulty");
+ laba3.Core.Menu difficultyMenu = new laba3.Core.Menu("Select difficulty");
difficultyMenu.AddOption("Easy", () => { difficulty = SnakeGame.Level.Low; });
difficultyMenu.AddOption("Medium", () => { difficulty = SnakeGame.Level.Medium; });
difficultyMenu.AddOption("Hard", () => { difficulty = SnakeGame.Level.High; });
@@ -37,13 +45,16 @@ class Program
Utils.Arrays withOneParam = new Utils.Arrays(10);
Utils.Arrays withTwoParams = new Utils.Arrays(10, 100);
- while (true)
- {
- mainMenu.RunMenu();
- Console.WriteLine("Press Enter to continue");
- while (Console.ReadKey().Key != ConsoleKey.Enter) { }
- Console.Clear();
- }
+ laba3.Core.Menu test = new laba3.Core.Menu("test");
+ test.AddOption("a", () => { });
+ mainForm.AddMenu(mainMenu);
+ mainForm.AddMenu(mainMenu);
+ mainForm.AddMenu(mainMenu);
+
+
+
+
+ Application.Run(mainForm);
}
private static void PrintAboutMe()
diff --git a/GUI/MenuForm.Designer.cs b/GUI/MenuForm.Designer.cs
new file mode 100644
index 0000000..73563b5
--- /dev/null
+++ b/GUI/MenuForm.Designer.cs
@@ -0,0 +1,39 @@
+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
new file mode 100644
index 0000000..581b4da
--- /dev/null
+++ b/GUI/MenuForm.cs
@@ -0,0 +1,63 @@
+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
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/GUI/MenuForm.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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 2150e37..217ede6 100644
--- a/ProgLab1.csproj
+++ b/ProgLab1.csproj
@@ -2,9 +2,10 @@
Exe
- net8.0
+ net8.0-windows10.0.17763.0
enable
enable
+ True