Compare commits
No commits in common. "6256105b42c5f71cdbe73b7bf61323c784ea4bd1" and "3062bab5842f32a0c87465794595bfbb63bd922f" have entirely different histories.
6256105b42
...
3062bab584
17
Core/Menu.cs
17
Core/Menu.cs
@ -10,14 +10,11 @@ namespace laba3.Core
|
||||
/// <summary>
|
||||
/// TUI menu;
|
||||
/// </summary>
|
||||
public class Menu
|
||||
internal class Menu
|
||||
{
|
||||
private List<MenuOption> options;
|
||||
private List<Option> options;
|
||||
private int selected;
|
||||
private string title;
|
||||
|
||||
public List<MenuOption> GetOptions() { return options; }
|
||||
public string GetTitle() { return title; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor of menu;
|
||||
@ -26,7 +23,7 @@ namespace laba3.Core
|
||||
public Menu(string title)
|
||||
{
|
||||
this.title = title;
|
||||
this.options = new List<MenuOption> { };
|
||||
this.options = new List<Option> { };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -36,7 +33,7 @@ namespace laba3.Core
|
||||
/// <param name="action">Action, runs if option selected</param>
|
||||
public void AddOption(string name, Action action)
|
||||
{
|
||||
this.options.Add(new MenuOption(name, action));
|
||||
this.options.Add(new Option(name, action));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -80,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}");
|
||||
@ -88,12 +85,12 @@ namespace laba3.Core
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -1,41 +1,35 @@
|
||||
using laba3.Core;
|
||||
using laba3.Subprograms;
|
||||
using ProgLab1.GUI;
|
||||
using System;
|
||||
|
||||
class Program
|
||||
{
|
||||
static MenuForm mainMenuForm;
|
||||
static MenuForm snakeDiffMenuForm;
|
||||
static MenuForm snakeSizeMenuForm;
|
||||
|
||||
[STAThread] // Требуется для Windows Forms
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
int sizex = 20;
|
||||
int sizey = 20;
|
||||
SnakeGame.Level difficulty = 0;
|
||||
|
||||
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; });
|
||||
|
||||
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; });
|
||||
|
||||
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());
|
||||
mainMenu.AddOption("Snake game", () => {
|
||||
int sizex = 0;
|
||||
int sizey = 0;
|
||||
SnakeGame.Level difficulty = 0;
|
||||
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();
|
||||
|
||||
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; });
|
||||
difficultyMenu.RunMenu();
|
||||
|
||||
SnakeGame game = new SnakeGame(difficulty, sizex, sizey);
|
||||
game.start();
|
||||
|
||||
|
||||
});
|
||||
mainMenu.AddOption("Exit", () => Exit());
|
||||
|
||||
@ -43,13 +37,13 @@ class Program
|
||||
Utils.Arrays withOneParam = new Utils.Arrays(10);
|
||||
Utils.Arrays withTwoParams = new Utils.Arrays(10, 100);
|
||||
|
||||
mainMenuForm = new MenuForm(mainMenu);
|
||||
snakeDiffMenuForm = new MenuForm(difficultyMenu);
|
||||
snakeSizeMenuForm = new MenuForm(sizeMenu);
|
||||
|
||||
Application.Run(mainMenuForm);
|
||||
|
||||
|
||||
while (true)
|
||||
{
|
||||
mainMenu.RunMenu();
|
||||
Console.WriteLine("Press Enter to continue");
|
||||
while (Console.ReadKey().Key != ConsoleKey.Enter) { }
|
||||
Console.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintAboutMe()
|
||||
|
39
GUI/MenuForm.Designer.cs
generated
39
GUI/MenuForm.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class MenuForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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 = "MenuForm";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,70 +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;
|
||||
|
||||
using static laba3.Core.Menu;
|
||||
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
public partial class MenuForm : Form
|
||||
{
|
||||
public MenuForm(Menu consoleMenu)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Width = 800;
|
||||
this.Height = 600;
|
||||
AddMenu(consoleMenu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds menu to GUI
|
||||
/// </summary>
|
||||
/// <param name="consoleMenu">TUI menu</param>
|
||||
private 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);
|
||||
}
|
||||
|
||||
this.Controls.Add(buttonPanel);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Binary file not shown.
Before Width: | Height: | Size: 506 KiB |
@ -2,16 +2,9 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>True</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="GUI\background.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user