Compare commits
7 Commits
6256105b42
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 20c29a2a12 | |||
| 0fc0fdb125 | |||
| f7342093af | |||
| d1ebd91521 | |||
| 7be59a5cf0 | |||
| 5ea7f1bed4 | |||
| f440212793 |
@@ -8,6 +8,10 @@ class Program
|
||||
static MenuForm mainMenuForm;
|
||||
static MenuForm snakeDiffMenuForm;
|
||||
static MenuForm snakeSizeMenuForm;
|
||||
static AboutMeForm aboutMeForm;
|
||||
static MathGameForm mathGameForm;
|
||||
static SnakeForm snakeForm;
|
||||
static ArraySortGUI arrayGUI;
|
||||
|
||||
[STAThread] // Требуется для Windows Forms
|
||||
static void Main()
|
||||
@@ -17,7 +21,7 @@ class Program
|
||||
|
||||
int sizex = 20;
|
||||
int sizey = 20;
|
||||
SnakeGame.Level difficulty = 0;
|
||||
SnakeForm.Level difficulty = 0;
|
||||
|
||||
Menu sizeMenu = new Menu("Select world size");
|
||||
sizeMenu.AddOption("Small size (10x10)", () => { sizex = 10; sizey = 10; });
|
||||
@@ -25,17 +29,17 @@ class Program
|
||||
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; });
|
||||
difficultyMenu.AddOption("Easy", () => { difficulty = SnakeForm.Level.Low; });
|
||||
difficultyMenu.AddOption("Medium", () => { difficulty = SnakeForm.Level.Medium; });
|
||||
difficultyMenu.AddOption("Hard", () => { difficulty = SnakeForm.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("Guess answer math game", () => mainMenuForm.SwitchToForm(mathGameForm));
|
||||
mainMenu.AddOption("About me", () => mainMenuForm.SwitchToForm(aboutMeForm));
|
||||
mainMenu.AddOption("Array sort", () => { arrayGUI = new ArraySortGUI(mainMenuForm); mainMenuForm.SwitchToForm(arrayGUI); });
|
||||
mainMenu.AddOption("Snake game", () => {
|
||||
SnakeGame game = new SnakeGame(difficulty, sizex, sizey);
|
||||
game.start();
|
||||
mainMenuForm.Hide();
|
||||
snakeDiffMenuForm.Show();
|
||||
});
|
||||
mainMenu.AddOption("Exit", () => Exit());
|
||||
|
||||
@@ -44,8 +48,16 @@ class Program
|
||||
Utils.Arrays withTwoParams = new Utils.Arrays(10, 100);
|
||||
|
||||
mainMenuForm = new MenuForm(mainMenu);
|
||||
snakeDiffMenuForm = new MenuForm(difficultyMenu);
|
||||
snakeSizeMenuForm = new MenuForm(sizeMenu);
|
||||
snakeDiffMenuForm = new MenuForm(difficultyMenu, () => { snakeDiffMenuForm.SwitchToForm(snakeSizeMenuForm); });
|
||||
snakeSizeMenuForm = new MenuForm(sizeMenu, () =>
|
||||
{
|
||||
snakeSizeMenuForm.Hide();
|
||||
snakeForm = new SnakeForm(difficulty, sizex, sizey, mainMenuForm);
|
||||
snakeForm.Show();
|
||||
});
|
||||
|
||||
aboutMeForm = new AboutMeForm(mainMenuForm);
|
||||
mathGameForm = new MathGameForm(mainMenuForm);
|
||||
|
||||
Application.Run(mainMenuForm);
|
||||
|
||||
@@ -60,8 +72,7 @@ Website: divan2000.su";
|
||||
}
|
||||
private static void Exit()
|
||||
{
|
||||
if(ExitMenu())
|
||||
Environment.Exit(0);
|
||||
Dialogs.Exit();
|
||||
}
|
||||
private static bool ExitMenu()
|
||||
{
|
||||
|
||||
@@ -139,6 +139,15 @@ namespace laba3.Core
|
||||
Console.WriteLine("\b\b]");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string str = "[";
|
||||
foreach (int x in this.array) { str+=$"{x}, "; }
|
||||
str = str.TrimEnd(' ').TrimEnd(',');
|
||||
str += "]";
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort this array with Gnome Sort;
|
||||
/// Avg time O(n^2);
|
||||
@@ -216,5 +225,21 @@ namespace laba3.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenInWeb(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = url, // Замените на свой сайт
|
||||
UseShellExecute = true // Это указывает, что нужно использовать ассоциации с оболочкой (браузер)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Ошибка при открытии браузера: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
GUI/AboutMeForm.Designer.cs
generated
Normal file
39
GUI/AboutMeForm.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class AboutMeForm
|
||||
{
|
||||
/// <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 = "AboutMeForm";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
41
GUI/AboutMeForm.cs
Normal file
41
GUI/AboutMeForm.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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 AboutMeForm : Form
|
||||
{
|
||||
private Label nameLabel;
|
||||
private LinkLabel websiteLinkLabel;
|
||||
public AboutMeForm(Form onCloseForm)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Text = "Обо мне";
|
||||
|
||||
nameLabel = new Label();
|
||||
nameLabel.Text = "Морозов Иван Сергеевич 6106 aka DIvan2000";
|
||||
nameLabel.AutoSize = true;
|
||||
nameLabel.Top = 50;
|
||||
nameLabel.Left = 50;
|
||||
|
||||
websiteLinkLabel = new LinkLabel();
|
||||
websiteLinkLabel.Text = "Мой сайт: divan2000.su";
|
||||
websiteLinkLabel.AutoSize = true;
|
||||
websiteLinkLabel.Top = 100;
|
||||
websiteLinkLabel.Left = 50;
|
||||
websiteLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler( (object sender, LinkLabelLinkClickedEventArgs e) => { Utils.OpenInWeb("https://divan2000.su"); });
|
||||
|
||||
this.Controls.Add(nameLabel);
|
||||
this.Controls.Add(websiteLinkLabel);
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => { e.Cancel = true; this.Hide(); onCloseForm.Show(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
120
GUI/AboutMeForm.resx
Normal file
120
GUI/AboutMeForm.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
39
GUI/ArraySortGUI.Designer.cs
generated
Normal file
39
GUI/ArraySortGUI.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class ArraySortGUI
|
||||
{
|
||||
/// <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 = "ArraySortGUI";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
116
GUI/ArraySortGUI.cs
Normal file
116
GUI/ArraySortGUI.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
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 ArraySortGUI : Form
|
||||
{
|
||||
private long time1;
|
||||
private long time2;
|
||||
private Label lblArraySize;
|
||||
private TextBox txtArraySize;
|
||||
private Button btnRun;
|
||||
private TextBox txtOutput;
|
||||
|
||||
public ArraySortGUI(Form onCloseForm)
|
||||
{
|
||||
// Initialize components
|
||||
lblArraySize = new Label
|
||||
{
|
||||
Location = new System.Drawing.Point(12, 12),
|
||||
Name = "lblArraySize",
|
||||
Size = new System.Drawing.Size(100, 22),
|
||||
Text = "Размер массива:"
|
||||
};
|
||||
|
||||
txtArraySize = new TextBox
|
||||
{
|
||||
Location = new System.Drawing.Point(150, 12),
|
||||
Name = "txtArraySize",
|
||||
Size = new System.Drawing.Size(150, 22),
|
||||
PlaceholderText = "Размер массива"
|
||||
};
|
||||
|
||||
btnRun = new Button
|
||||
{
|
||||
Location = new System.Drawing.Point(310, 10),
|
||||
Name = "btnRun",
|
||||
Size = new System.Drawing.Size(100, 25),
|
||||
Text = "Запустить",
|
||||
UseVisualStyleBackColor = true
|
||||
};
|
||||
btnRun.Click += new EventHandler(this.btnRun_Click);
|
||||
|
||||
txtOutput = new TextBox
|
||||
{
|
||||
Location = new System.Drawing.Point(12, 50),
|
||||
Multiline = true,
|
||||
Name = "txtOutput",
|
||||
ReadOnly = true,
|
||||
ScrollBars = ScrollBars.Vertical,
|
||||
Size = new System.Drawing.Size(400, 300),
|
||||
WordWrap = true
|
||||
};
|
||||
|
||||
// Set up form
|
||||
this.ClientSize = new System.Drawing.Size(424, 361);
|
||||
this.Controls.Add(lblArraySize);
|
||||
this.Controls.Add(txtArraySize);
|
||||
this.Controls.Add(btnRun);
|
||||
this.Controls.Add(txtOutput);
|
||||
this.Name = "ArraySortGUI";
|
||||
this.Text = "Array Sort Demo";
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => {onCloseForm.Show(); });
|
||||
}
|
||||
|
||||
private void btnRun_Click(object sender, EventArgs e)
|
||||
{
|
||||
int size;
|
||||
if (!int.TryParse(txtArraySize.Text, out size) || size < 1)
|
||||
{
|
||||
MessageBox.Show("Размер массива должен быть числом больше 0!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
txtOutput.Clear();
|
||||
Utils.Arrays array1 = new Utils.Arrays(size, 100);
|
||||
Utils.Arrays array2 = new Utils.Arrays(array1);
|
||||
|
||||
txtOutput.AppendText("Для Массива 1 будет использована \"гномья сортировка\"" + Environment.NewLine);
|
||||
txtOutput.AppendText("Для Массива 2 будет использована \"сортировка шелла\"" + Environment.NewLine);
|
||||
|
||||
if (size <= 10)
|
||||
{
|
||||
txtOutput.AppendText("Массив 1 (с начальными значениями): " + Environment.NewLine + array1.ToString() + Environment.NewLine);
|
||||
txtOutput.AppendText("Массив 2 (с начальными значениями): " + Environment.NewLine + array2.ToString() + Environment.NewLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
txtOutput.AppendText("Массивы не могут быть выведены на экран так как их размер больше 10" + Environment.NewLine);
|
||||
}
|
||||
|
||||
txtOutput.AppendText("Сортируем..." + Environment.NewLine);
|
||||
|
||||
time1 = array1.gnomeSort();
|
||||
time2 = array2.shellSort();
|
||||
|
||||
txtOutput.AppendText("Готово!" + Environment.NewLine);
|
||||
|
||||
if (size <= 10)
|
||||
{
|
||||
txtOutput.AppendText("Массив 1 (после гномьей сортировки): " + Environment.NewLine + array1.ToString() + Environment.NewLine);
|
||||
txtOutput.AppendText("Массив 2 (после сортировки шелла): " + Environment.NewLine + array2.ToString() + Environment.NewLine);
|
||||
}
|
||||
|
||||
txtOutput.AppendText($"Для сортировки 1 потребовалось {time1}мс" + Environment.NewLine);
|
||||
txtOutput.AppendText($"Для сортировки 2 потребовалось {time2}мс" + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
120
GUI/ArraySortGUI.resx
Normal file
120
GUI/ArraySortGUI.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
28
GUI/Dialogs.cs
Normal file
28
GUI/Dialogs.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
public static class Dialogs
|
||||
{
|
||||
public static bool Exit()
|
||||
{
|
||||
DialogResult result = MessageBox.Show("Вы уверены, что хотите закрыть программу?", "Подтверждение", MessageBoxButtons.YesNo);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool GameOver(string message)
|
||||
{
|
||||
DialogResult result = MessageBox.Show(message, "Игра окончена", MessageBoxButtons.OK);
|
||||
return result == DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
GUI/GuessForm.Designer.cs
generated
Normal file
39
GUI/GuessForm.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class GuessForm
|
||||
{
|
||||
/// <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 = "GuessForm";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
101
GUI/GuessForm.cs
Normal file
101
GUI/GuessForm.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using laba3.Subprograms;
|
||||
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 GuessForm : Form
|
||||
{
|
||||
private double answer;
|
||||
private int tryes;
|
||||
private Label tryCount;
|
||||
private TextBox input;
|
||||
|
||||
public void SetAnswer(double answer) { this.answer = answer; tryes = 3; tryCount.Text = $"Количество попыток: {tryes}"; }
|
||||
public GuessForm(Form onCloseForm)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => { e.Cancel = true; this.Hide(); onCloseForm.Show(); });
|
||||
|
||||
input = new TextBox();
|
||||
input.Top = 100;
|
||||
input.Left = 50;
|
||||
input.Width = 300;
|
||||
|
||||
Label inputLabel = new Label();
|
||||
inputLabel.Top = 70;
|
||||
inputLabel.Left = 50;
|
||||
inputLabel.Text = "Введите число:";
|
||||
|
||||
Button confirmButton = new Button
|
||||
{
|
||||
Text = "Подтвердить",
|
||||
Width = 100,
|
||||
Height = 30,
|
||||
Top = 100,
|
||||
Left = 400
|
||||
};
|
||||
|
||||
tryCount = new Label();
|
||||
tryCount.Top = 40;
|
||||
tryCount.Left = 50;
|
||||
tryCount.Width = 400;
|
||||
tryCount.Text = $"Количество попыток: {tryes}";
|
||||
|
||||
confirmButton.Click += ConfirmButton_Click;
|
||||
|
||||
this.Controls.Add(inputLabel);
|
||||
this.Controls.Add(input);
|
||||
this.Controls.Add(confirmButton);
|
||||
this.Controls.Add(tryCount);
|
||||
}
|
||||
|
||||
private bool ValidateInput(TextBox textBox)
|
||||
{
|
||||
if (double.TryParse(textBox.Text, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfirmButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
bool isValid = ValidateInput(input);
|
||||
if (!isValid)
|
||||
{
|
||||
input.BackColor = Color.Red;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.BackColor = SystemColors.Window;
|
||||
double inputNum = double.Parse(input.Text);
|
||||
if (Math.Abs(answer - inputNum) < 0.01)
|
||||
{
|
||||
Dialogs.GameOver("Победа!\nВы угадали значение функции!");
|
||||
this.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
tryes--;
|
||||
tryCount.Text = $"Количество попыток: {tryes}";
|
||||
if (tryes <= 0)
|
||||
{
|
||||
Dialogs.GameOver($"Попытки кончились :(\nВерный ответ был {answer:F2}");
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
GUI/GuessForm.resx
Normal file
120
GUI/GuessForm.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
39
GUI/MathGameForm.Designer.cs
generated
Normal file
39
GUI/MathGameForm.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class MathGameForm
|
||||
{
|
||||
/// <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 = "MathGameForm";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
157
GUI/MathGameForm.cs
Normal file
157
GUI/MathGameForm.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using laba3.Subprograms;
|
||||
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 System.Xml;
|
||||
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
public partial class MathGameForm : Form
|
||||
{
|
||||
private Label error;
|
||||
private Label formula;
|
||||
private Label rules;
|
||||
private TextBox textBoxA;
|
||||
private TextBox textBoxB;
|
||||
private Label labelA;
|
||||
private Label labelB;
|
||||
|
||||
private double a=0;
|
||||
private double b=0;
|
||||
private GuessAnswerMath game;
|
||||
private GuessForm guessForm;
|
||||
public MathGameForm(Form onCloseForm)
|
||||
{
|
||||
guessForm = new GuessForm(onCloseForm);
|
||||
game = new GuessAnswerMath();
|
||||
InitializeComponent();
|
||||
this.Text = "Угадайка";
|
||||
|
||||
formula = new Label();
|
||||
formula.Text = "Math.Sin((Math.Pow(a, 3) + Math.Pow(b, 5)) / (2 * PI)) + Math.Pow(Math.Cos(a + b), (1.0 / 3.0))";
|
||||
formula.AutoSize = true;
|
||||
formula.Top = 50;
|
||||
formula.Left = 50;
|
||||
|
||||
rules = new Label();
|
||||
rules.Text = "Нужно ввести аргументы для функции, а затем попытаться отгадать её значение";
|
||||
rules.AutoSize = true;
|
||||
rules.Top = 100;
|
||||
rules.Left = 50;
|
||||
|
||||
// Создание Label для "a"
|
||||
labelA = new Label();
|
||||
labelA.Text = "a:";
|
||||
labelA.Top = 150;
|
||||
labelA.Left = 20;
|
||||
labelA.AutoSize = true;
|
||||
|
||||
// Создание TextBox для "a"
|
||||
textBoxA = new TextBox();
|
||||
textBoxA.Top = 150;
|
||||
textBoxA.Left = 50;
|
||||
textBoxA.Width = 300;
|
||||
|
||||
// Создание Label для "b"
|
||||
labelB = new Label();
|
||||
labelB.Text = "b:";
|
||||
labelB.Top = 190;
|
||||
labelB.Left = 20;
|
||||
labelB.AutoSize = true;
|
||||
|
||||
// Создание TextBox для "b"
|
||||
textBoxB = new TextBox();
|
||||
textBoxB.Top = 190;
|
||||
textBoxB.Left = 50;
|
||||
textBoxB.Width = 300;
|
||||
|
||||
error = new Label();
|
||||
error.Text = "";
|
||||
error.AutoSize = true;
|
||||
error.Top = 220;
|
||||
error.Left = 50;
|
||||
error.ForeColor = Color.Red;
|
||||
|
||||
this.Controls.Add(formula);
|
||||
this.Controls.Add(rules);
|
||||
this.Controls.Add(labelA);
|
||||
this.Controls.Add(textBoxA);
|
||||
this.Controls.Add(labelB);
|
||||
this.Controls.Add(textBoxB);
|
||||
this.Controls.Add(error);
|
||||
|
||||
Button confirmButton = new Button
|
||||
{
|
||||
Text = "Подтвердить",
|
||||
Width = 100,
|
||||
Height = 30,
|
||||
Top = 165,
|
||||
Left = 400
|
||||
};
|
||||
|
||||
confirmButton.Click += ConfirmButton_Click;
|
||||
|
||||
this.Controls.Add(confirmButton);
|
||||
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => { e.Cancel = true; this.Hide(); onCloseForm.Show(); });
|
||||
}
|
||||
|
||||
private bool ValidateInput(TextBox textBox)
|
||||
{
|
||||
if (double.TryParse(textBox.Text, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfirmButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Проверяем значения в полях
|
||||
bool isAValid = ValidateInput(textBoxA);
|
||||
bool isBValid = ValidateInput(textBoxB);
|
||||
|
||||
if (isAValid && isBValid)
|
||||
{
|
||||
// Если оба значения корректные, выводим сумму в
|
||||
textBoxA.BackColor = SystemColors.Window;
|
||||
textBoxB.BackColor = SystemColors.Window;
|
||||
a = double.Parse(textBoxA.Text);
|
||||
b = double.Parse(textBoxB.Text);
|
||||
|
||||
game.setArgs(a, b);
|
||||
|
||||
bool funcValid = game.CheckArgs();
|
||||
|
||||
if (!funcValid)
|
||||
{
|
||||
error.Text = "Функция не определена при этих аргументах";
|
||||
}
|
||||
else
|
||||
{
|
||||
error.Text = "";
|
||||
game.ComputeResult();
|
||||
guessForm.SetAnswer(game.GetResult());
|
||||
this.Hide();
|
||||
guessForm.Show();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Если есть ошибка, подсвечиваем поля
|
||||
if (!isAValid) textBoxA.BackColor = Color.Red;
|
||||
if (!isBValid) textBoxB.BackColor = Color.Red;
|
||||
error.Text = "Аргументы должны быть double";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
GUI/MathGameForm.resx
Normal file
120
GUI/MathGameForm.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
@@ -18,9 +18,27 @@ namespace ProgLab1.GUI
|
||||
public MenuForm(Menu consoleMenu)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Text = "Меню";
|
||||
this.Width = 800;
|
||||
this.Height = 600;
|
||||
AddMenu(consoleMenu);
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => { e.Cancel = !Dialogs.Exit(); });
|
||||
}
|
||||
|
||||
public MenuForm(Menu consoleMenu, Action onAny)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Text = "Меню";
|
||||
this.Width = 800;
|
||||
this.Height = 600;
|
||||
AddMenu(consoleMenu, onAny);
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => { e.Cancel = !Dialogs.Exit(); });
|
||||
}
|
||||
|
||||
public void SwitchToForm(Form form)
|
||||
{
|
||||
form.Show();
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,5 +84,61 @@ namespace ProgLab1.GUI
|
||||
|
||||
this.Controls.Add(buttonPanel);
|
||||
}
|
||||
|
||||
private void AddMenu(Menu consoleMenu, Action onAny)
|
||||
{
|
||||
|
||||
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();
|
||||
button.Click += (sender, e) => onAny();
|
||||
|
||||
buttonPanel.Controls.Add(button);
|
||||
}
|
||||
|
||||
this.Controls.Add(buttonPanel);
|
||||
}
|
||||
|
||||
private void FormClosingHandler(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
// Предотвращаем закрытие окна
|
||||
DialogResult result = MessageBox.Show("Вы уверены, что хотите закрыть окно?", "Подтверждение", MessageBoxButtons.YesNo);
|
||||
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
e.Cancel = true; // Отменяем закрытие окна
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = false; // Разрешаем закрытие окна
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
GUI/SnakeForm.Designer.cs
generated
Normal file
39
GUI/SnakeForm.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class SnakeForm
|
||||
{
|
||||
/// <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 = "SnakeGUI";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
194
GUI/SnakeForm.cs
Normal file
194
GUI/SnakeForm.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
using laba3.Subprograms;
|
||||
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 System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
public partial class SnakeForm : Form
|
||||
{
|
||||
private System.Windows.Forms.Timer gameTimer = new System.Windows.Forms.Timer();
|
||||
private List<Point> snake = new List<Point>();
|
||||
private Point food = Point.Empty;
|
||||
private int tileSize = 20;
|
||||
private string direction = "Right";
|
||||
private string nextDirection = "Right";
|
||||
private bool isGameOver = false;
|
||||
private int score = 0;
|
||||
|
||||
private Level level;
|
||||
private int sizex;
|
||||
private int sizey;
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
public SnakeForm(Level level, int sizex, int sizey, Form onCloseForm)
|
||||
{
|
||||
this.level = level;
|
||||
this.sizex = sizex;
|
||||
this.sizey = sizey;
|
||||
InitializeComponent();
|
||||
InitializeGame();
|
||||
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => {onCloseForm.Show();});
|
||||
}
|
||||
|
||||
private void InitializeGame()
|
||||
{
|
||||
this.Text = "Snake Game";
|
||||
this.ClientSize = new Size(sizex*tileSize, sizey*tileSize);
|
||||
this.DoubleBuffered = true;
|
||||
this.KeyDown += OnKeyDown;
|
||||
this.Paint += OnPaint;
|
||||
|
||||
gameTimer.Interval = level switch
|
||||
{
|
||||
Level.Low => 250,
|
||||
Level.Medium => 125,
|
||||
Level.High => 50,
|
||||
_ => 500,
|
||||
}; ;
|
||||
gameTimer.Tick += OnGameTick;
|
||||
gameTimer.Start();
|
||||
|
||||
ResetGame();
|
||||
}
|
||||
|
||||
private void ResetGame()
|
||||
{
|
||||
snake.Clear();
|
||||
snake.Add(new Point(2, sizey/2)); // Initial snake head
|
||||
snake.Add(new Point(1, sizey/2)); // Initial snake body
|
||||
snake.Add(new Point(0, sizey/2)); // Initial snake tail
|
||||
direction = "Right";
|
||||
nextDirection = "Right";
|
||||
isGameOver = false;
|
||||
SpawnFood();
|
||||
}
|
||||
|
||||
private void SpawnFood()
|
||||
{
|
||||
int maxX = sizex;
|
||||
int maxY = sizey;
|
||||
do
|
||||
{
|
||||
food = new Point(rand.Next(0, maxX), rand.Next(0, maxY));
|
||||
} while (snake.Contains(food));
|
||||
}
|
||||
|
||||
private void OnGameTick(object sender, EventArgs e)
|
||||
{
|
||||
if (isGameOver) return;
|
||||
|
||||
// Update direction
|
||||
direction = nextDirection;
|
||||
|
||||
// Calculate new head position
|
||||
Point newHead = snake[0];
|
||||
switch (direction)
|
||||
{
|
||||
case "Up": newHead.Y--; break;
|
||||
case "Down": newHead.Y++; break;
|
||||
case "Left": newHead.X--; break;
|
||||
case "Right": newHead.X++; break;
|
||||
}
|
||||
|
||||
// Check collisions
|
||||
if (newHead.X < 0 || newHead.Y < 0 ||
|
||||
newHead.X >= sizex ||
|
||||
newHead.Y >= sizey ||
|
||||
snake.Contains(newHead))
|
||||
{
|
||||
isGameOver = true;
|
||||
gameTimer.Stop();
|
||||
Dialogs.GameOver($"Счёт: {score}");
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Move snake
|
||||
snake.Insert(0, newHead);
|
||||
if (newHead == food)
|
||||
{
|
||||
SpawnFood();
|
||||
addScore();
|
||||
}
|
||||
else
|
||||
{
|
||||
snake.RemoveAt(snake.Count - 1); // Remove tail
|
||||
}
|
||||
|
||||
this.Invalidate(); // Redraw
|
||||
}
|
||||
|
||||
private void OnPaint(object sender, PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
// Draw snake
|
||||
foreach (Point p in snake)
|
||||
{
|
||||
DrawTile(g, p.X, p.Y, Brushes.Green);
|
||||
}
|
||||
|
||||
// Draw food
|
||||
DrawTile(g, food.X, food.Y, Brushes.Red);
|
||||
|
||||
// Draw grid (optional)
|
||||
for (int x = 0; x < this.ClientSize.Width; x += tileSize)
|
||||
{
|
||||
for (int y = 0; y < this.ClientSize.Height; y += tileSize)
|
||||
{
|
||||
g.DrawRectangle(Pens.Gray, x, y, tileSize, tileSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTile(Graphics g, int x, int y, Brush brush)
|
||||
{
|
||||
g.FillRectangle(brush, x * tileSize, y * tileSize, tileSize, tileSize);
|
||||
}
|
||||
|
||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (isGameOver && e.KeyCode == Keys.R)
|
||||
{
|
||||
ResetGame();
|
||||
gameTimer.Start();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Up: if (direction != "Down") nextDirection = "Up"; break;
|
||||
case Keys.Down: if (direction != "Up") nextDirection = "Down"; break;
|
||||
case Keys.Left: if (direction != "Right") nextDirection = "Left"; break;
|
||||
case Keys.Right: if (direction != "Left") nextDirection = "Right"; break;
|
||||
}
|
||||
}
|
||||
|
||||
private void addScore()
|
||||
{
|
||||
score += level switch
|
||||
{
|
||||
Level.Low => 50,
|
||||
Level.Medium => 100,
|
||||
Level.High => 250,
|
||||
_ => 1,
|
||||
};
|
||||
}
|
||||
public enum Level
|
||||
{
|
||||
Low,
|
||||
Medium,
|
||||
High
|
||||
}
|
||||
}
|
||||
}
|
||||
120
GUI/SnakeForm.resx
Normal file
120
GUI/SnakeForm.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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 |
@@ -1,17 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>True</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="GUI\background.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
using laba3.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace laba3.Subprograms
|
||||
{
|
||||
/// <summary>
|
||||
/// Compare computing time of 2 sorting methods;
|
||||
/// Gnome sort and Shell sort;
|
||||
/// </summary>
|
||||
internal class ArraySortDemo
|
||||
{
|
||||
private long time1;
|
||||
private long time2;
|
||||
|
||||
/// <summary>
|
||||
/// Get values from keyboard, init arrays, start computing, print time;
|
||||
/// Console will be clean!;
|
||||
/// </summary>
|
||||
public void Run()
|
||||
{
|
||||
Utils.Arrays array1;
|
||||
Utils.Arrays array2;
|
||||
int size;
|
||||
size = ReadArrayLen();
|
||||
array1 = new Utils.Arrays(size, 100);
|
||||
array2 = new Utils.Arrays(array1);
|
||||
|
||||
Console.WriteLine("Для Массива 1 будет использована \"гномья сортировка\"");
|
||||
Console.WriteLine("Для Массива 2 будет использована \"сортировка шелла\"");
|
||||
|
||||
if (size <= 10)
|
||||
array1.print("с начальными значениями");
|
||||
else
|
||||
Console.WriteLine("Массивы не могут быть выведены на экран так как их размер больше 10");
|
||||
Console.WriteLine("Сортируем...");
|
||||
|
||||
time1 = array1.gnomeSort();
|
||||
time2 = array2.shellSort();
|
||||
|
||||
Console.WriteLine("Готово!");
|
||||
if (size <= 10)
|
||||
{
|
||||
array1.print("после гномьей сортировки");
|
||||
array2.print("после сортировки шелла ");
|
||||
}
|
||||
|
||||
Console.WriteLine($"Для сортировки 1 потребовалось {time1}мс");
|
||||
Console.WriteLine($"Для сортировки 2 потребовалось {time2}мс");
|
||||
}
|
||||
|
||||
private int ReadArrayLen()
|
||||
{
|
||||
int size;
|
||||
do
|
||||
{
|
||||
size = Utils.ReadInt("Размер массива для сортировки");
|
||||
Console.Clear();
|
||||
if (size < 1)
|
||||
Console.WriteLine("Размер не может быть меньше 1!");
|
||||
} while (size < 1);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,81 +11,33 @@ namespace laba3.Subprograms
|
||||
/// CLI math game "Gusess the answer";
|
||||
/// Player need to guess result of math function;
|
||||
/// </summary>
|
||||
internal static class GuessAnswerMath
|
||||
public class GuessAnswerMath
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs game;
|
||||
/// Console will be clean!;
|
||||
/// </summary>
|
||||
public static void RunGame()
|
||||
{
|
||||
const int attempts = 3;
|
||||
Console.WriteLine("Введите аргументы функции, а затем попытайтесь угадать её значение. Количество попыток ограничено!");
|
||||
bool isValid;
|
||||
do
|
||||
{
|
||||
MathFunc.setArgs(Utils.ReadDouble("аргумент a"), Utils.ReadDouble("аргумент b"));
|
||||
isValid = MathFunc.CheckArgs();
|
||||
if (!isValid)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("Функция не определена при данных аргументах!");
|
||||
}
|
||||
} while (!isValid);
|
||||
MathFunc.ComputeResult();
|
||||
if (GameLogic(MathFunc.GetResult(), attempts))
|
||||
{
|
||||
Console.WriteLine("Ответ верный! Победа!");
|
||||
} else
|
||||
{
|
||||
Console.WriteLine(String.Format("Попытки кончились! Правильный ответ: {0:0.00}", MathFunc.GetResult()));
|
||||
}
|
||||
}
|
||||
|
||||
private static bool GameLogic(double correctAnswer, int attempts)
|
||||
{
|
||||
bool win = false;
|
||||
for (int i = attempts; i > 0; i--)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Количество попыток: {i}");
|
||||
double answer = Utils.ReadDouble("ваш ответ");
|
||||
win = Math.Abs(correctAnswer - answer) < 0.01;
|
||||
if (win)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
return win;
|
||||
}
|
||||
private static class MathFunc
|
||||
{
|
||||
private const double PI = Math.PI;
|
||||
private const double E = Math.E;
|
||||
private static double a;
|
||||
private static double b;
|
||||
private static double result;
|
||||
private double a;
|
||||
private double b;
|
||||
private double result;
|
||||
|
||||
public static void setArgs(double a, double b)
|
||||
public void setArgs(double a, double b)
|
||||
{
|
||||
MathFunc.a = a;
|
||||
MathFunc.b = b;
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static void ComputeResult()
|
||||
public void ComputeResult()
|
||||
{
|
||||
MathFunc.result = Math.Sin((Math.Pow(a, 3) + Math.Pow(b, 5)) / (2 * PI)) + Math.Pow(Math.Cos(a + b), (1.0 / 3.0));
|
||||
this.result = Math.Sin((Math.Pow(a, 3) + Math.Pow(b, 5)) / (2 * PI)) + Math.Pow(Math.Cos(a + b), (1.0 / 3.0));
|
||||
}
|
||||
|
||||
public static bool CheckArgs()
|
||||
public bool CheckArgs()
|
||||
{
|
||||
return Math.Cos(a + b) >= 0;
|
||||
}
|
||||
|
||||
public static double GetResult()
|
||||
public double GetResult()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,380 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace laba3.Subprograms
|
||||
{
|
||||
/// <summary>
|
||||
/// TUI classic game "Snake";
|
||||
/// The player controls the snake.
|
||||
/// The player has to eat apples to increase the length of the snake
|
||||
/// and try not to crash into the wall or themselves;
|
||||
/// </summary>
|
||||
internal class SnakeGame
|
||||
{
|
||||
int size_x;
|
||||
int size_y;
|
||||
int score;
|
||||
int size_xy;
|
||||
Level difficulty;
|
||||
Tiles[,] world;
|
||||
Snake snake;
|
||||
Random rnd;
|
||||
|
||||
private bool gameover;
|
||||
/// <summary>
|
||||
/// Game world constructor;
|
||||
/// </summary>
|
||||
/// <param name="difficulty">Game speed</param>
|
||||
/// <param name="size_x">Game world size dim x</param>
|
||||
/// <param name="size_y">Game world size dim y</param>
|
||||
public SnakeGame(Level difficulty, int size_x, int size_y)
|
||||
{
|
||||
this.size_x = size_x;
|
||||
this.size_y = size_y;
|
||||
this.difficulty = difficulty;
|
||||
world = new Tiles[size_x, size_y];
|
||||
rnd = new Random();
|
||||
score = 0;
|
||||
size_xy = size_x * size_y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Start game;
|
||||
/// Console will be clean!;
|
||||
/// </summary>
|
||||
public void start()
|
||||
{
|
||||
int msPerTick = difficulty switch
|
||||
{
|
||||
Level.Low => 500,
|
||||
Level.Medium => 250,
|
||||
Level.High => 100,
|
||||
_ => 500,
|
||||
};
|
||||
gameover = false;
|
||||
|
||||
Console.Clear();
|
||||
Console.CursorVisible = false;
|
||||
snake = new Snake(new Point(size_x / 2, size_y / 2, this), 1, Direction.Right, this);
|
||||
|
||||
GenerateFood();
|
||||
|
||||
DrawBackground();
|
||||
DrawWorld();
|
||||
|
||||
Stopwatch tickTimer = new Stopwatch();
|
||||
while (!gameover)
|
||||
{
|
||||
tickTimer.Restart();
|
||||
if (Console.KeyAvailable)
|
||||
{
|
||||
ConsoleKeyInfo key = Console.ReadKey(false);
|
||||
snake.HandleKey(key.Key);
|
||||
while (Console.KeyAvailable)
|
||||
Console.ReadKey(false);
|
||||
}
|
||||
snake.Move();
|
||||
long delta = tickTimer.ElapsedMilliseconds;
|
||||
|
||||
Console.SetCursorPosition(1, 0);
|
||||
if (delta > msPerTick)
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Write(delta);
|
||||
|
||||
Thread.Sleep((int)Math.Max(0, msPerTick - delta));
|
||||
}
|
||||
onStop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop game;
|
||||
/// </summary>
|
||||
public void stop()
|
||||
{
|
||||
gameover = true;
|
||||
}
|
||||
|
||||
private void onStop()
|
||||
{
|
||||
string gameOverTitle =
|
||||
@"
|
||||
### ##
|
||||
# ## #### # # # # # # ##
|
||||
# ## # # # # # ### # # # # ### #
|
||||
# # # # # # # # # # # # #
|
||||
### ## # # # ## ## # ## #
|
||||
";
|
||||
Console.Clear();
|
||||
printArt(gameOverTitle, (Console.WindowWidth - 36) / 2, 4, ConsoleColor.DarkYellow, ConsoleColor.DarkGray);
|
||||
|
||||
Console.ResetColor();
|
||||
|
||||
string scoreString = $"Score: {score}";
|
||||
Console.SetCursorPosition((Console.WindowWidth - scoreString.Length) / 2, 11);
|
||||
Console.Write(scoreString);
|
||||
Console.SetCursorPosition((Console.WindowWidth - "Press Enter to continue".Length) / 2, 14);
|
||||
Console.CursorVisible = true;
|
||||
}
|
||||
|
||||
private void printArt(string art, int x, int y, ConsoleColor primaryColor, ConsoleColor shadowColor)
|
||||
{
|
||||
int row = 0;
|
||||
Console.SetCursorPosition(x, y);
|
||||
char shadow = ' ';
|
||||
foreach (char ch in art)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
if (shadow == '#')
|
||||
{
|
||||
Console.BackgroundColor = shadowColor;
|
||||
Console.Write(' ');
|
||||
}
|
||||
Console.SetCursorPosition(x, y++ + row);
|
||||
Thread.Sleep(25);
|
||||
shadow = ch;
|
||||
}
|
||||
else if (ch == ' ')
|
||||
{
|
||||
if (shadow == '#')
|
||||
{
|
||||
Console.BackgroundColor = shadowColor;
|
||||
Console.Write(' ');
|
||||
}
|
||||
else
|
||||
Console.CursorLeft++;
|
||||
shadow = ch;
|
||||
}
|
||||
else if (ch == '#')
|
||||
{
|
||||
Console.BackgroundColor = primaryColor;
|
||||
Console.Write(' ');
|
||||
shadow = ch;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void addScore()
|
||||
{
|
||||
score += difficulty switch
|
||||
{
|
||||
Level.Low => 10,
|
||||
Level.Medium => 50,
|
||||
Level.High => 100,
|
||||
_ => 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generate food in random place;
|
||||
/// </summary>
|
||||
public void GenerateFood()
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
do
|
||||
{
|
||||
x = rnd.Next(size_x);
|
||||
y = rnd.Next(size_y);
|
||||
} while (world[x, y] != Tiles.Void);
|
||||
world[x, y] = Tiles.Food;
|
||||
DrawTile(x, y);
|
||||
}
|
||||
|
||||
private void DrawBackground()
|
||||
{
|
||||
for (int x = 1; x < (size_x + 1) * 2 + 1; x++)
|
||||
{
|
||||
Console.SetCursorPosition(x, 1);
|
||||
Console.Write('#');
|
||||
Console.SetCursorPosition(x, size_y + 2);
|
||||
Console.Write('#');
|
||||
}
|
||||
for (int y = 1; y < size_y + 2; y++)
|
||||
{
|
||||
Console.SetCursorPosition(1, y);
|
||||
Console.Write('#');
|
||||
|
||||
Console.SetCursorPosition(size_x * 2 + 1, y);
|
||||
Console.Write('#');
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTile(int x, int y)
|
||||
{
|
||||
char symbol;
|
||||
switch (world[x, y])
|
||||
{
|
||||
case Tiles.Void:
|
||||
symbol = ' ';
|
||||
break;
|
||||
case Tiles.Snake:
|
||||
symbol = '*';
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
break;
|
||||
case Tiles.Food:
|
||||
symbol = '@';
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
break;
|
||||
default:
|
||||
symbol = '?';
|
||||
break;
|
||||
};
|
||||
//Console.BackgroundColor = ConsoleColor.DarkGreen;
|
||||
Console.SetCursorPosition((x + 1) * 2, y + 2);
|
||||
Console.Write(symbol);
|
||||
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
}
|
||||
private void DrawWorld()
|
||||
{
|
||||
for (int x = 0; x < size_x; x++)
|
||||
{
|
||||
for (int y = 0; y < size_y; y++)
|
||||
{
|
||||
DrawTile(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
private enum Tiles
|
||||
{
|
||||
Void,
|
||||
Snake,
|
||||
Food
|
||||
}
|
||||
public enum Level
|
||||
{
|
||||
Low,
|
||||
Medium,
|
||||
High
|
||||
}
|
||||
private class Snake
|
||||
{
|
||||
private SnakeGame game;
|
||||
private List<Point> body;
|
||||
private Direction direction;
|
||||
|
||||
public Snake(Point tail, int length, Direction initialDirection, SnakeGame game)
|
||||
{
|
||||
this.game = game;
|
||||
body = new List<Point>();
|
||||
direction = initialDirection;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
Point p = new Point(tail.X, tail.Y, game);
|
||||
body.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
Point head = GetNextPoint();
|
||||
Point tail = body.First();
|
||||
|
||||
if (head.X < 0 || head.Y < 0 || head.X >= game.size_x || head.Y >= game.size_y)
|
||||
{
|
||||
game.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.world[head.X, head.Y] == Tiles.Snake)
|
||||
{
|
||||
game.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
body.Add(head);
|
||||
if (game.world[head.X, head.Y] != Tiles.Food)
|
||||
{
|
||||
body.Remove(tail);
|
||||
tail.UpdateWorld(Tiles.Void);
|
||||
}
|
||||
else
|
||||
{
|
||||
game.addScore();
|
||||
game.GenerateFood();
|
||||
if (body.Count >= game.size_xy) game.stop();
|
||||
}
|
||||
head.UpdateWorld(Tiles.Snake);
|
||||
}
|
||||
|
||||
public Point GetNextPoint()
|
||||
{
|
||||
Point head = body.Last();
|
||||
Point nextPoint = new Point(head.X, head.Y, game);
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Right:
|
||||
nextPoint.X++;
|
||||
break;
|
||||
case Direction.Left:
|
||||
nextPoint.X--;
|
||||
break;
|
||||
case Direction.Up:
|
||||
nextPoint.Y--;
|
||||
break;
|
||||
case Direction.Down:
|
||||
nextPoint.Y++;
|
||||
break;
|
||||
}
|
||||
|
||||
return nextPoint;
|
||||
}
|
||||
|
||||
public void HandleKey(ConsoleKey key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case ConsoleKey.LeftArrow:
|
||||
if (direction != Direction.Right)
|
||||
direction = Direction.Left;
|
||||
break;
|
||||
case ConsoleKey.RightArrow:
|
||||
if (direction != Direction.Left)
|
||||
direction = Direction.Right;
|
||||
break;
|
||||
case ConsoleKey.UpArrow:
|
||||
if (direction != Direction.Down)
|
||||
direction = Direction.Up;
|
||||
break;
|
||||
case ConsoleKey.DownArrow:
|
||||
if (direction != Direction.Up)
|
||||
direction = Direction.Down;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Direction
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
|
||||
private class Point
|
||||
{
|
||||
private SnakeGame game { get; set; }
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
public Point(int x, int y, SnakeGame game)
|
||||
{
|
||||
this.game = game;
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public void UpdateWorld(Tiles tile)
|
||||
{
|
||||
game.world[X, Y] = tile;
|
||||
game.DrawTile(X, Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user