From 417ac8ed4920880066a90efad15ab13532d4023b Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 20 May 2023 13:04:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D1=83=D0=B4=D0=B0=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NewFindACouple/NewFindACouple.sln | 25 +++++ .../NewFindACouple/Form1.Designer.cs | 47 ++++++++++ NewFindACouple/NewFindACouple/Form1.cs | 93 +++++++++++++++++++ NewFindACouple/NewFindACouple/Form1.resx | 60 ++++++++++++ .../NewFindACouple/IncorectNumberException.cs | 2 + .../NewFindACouple/NewFindACouple.csproj | 11 +++ .../NewFindACouple/NewFindACouple.csproj.user | 8 ++ NewFindACouple/NewFindACouple/Program.cs | 21 +++++ 8 files changed, 267 insertions(+) create mode 100644 NewFindACouple/NewFindACouple.sln create mode 100644 NewFindACouple/NewFindACouple/Form1.Designer.cs create mode 100644 NewFindACouple/NewFindACouple/Form1.cs create mode 100644 NewFindACouple/NewFindACouple/Form1.resx create mode 100644 NewFindACouple/NewFindACouple/IncorectNumberException.cs create mode 100644 NewFindACouple/NewFindACouple/NewFindACouple.csproj create mode 100644 NewFindACouple/NewFindACouple/NewFindACouple.csproj.user create mode 100644 NewFindACouple/NewFindACouple/Program.cs diff --git a/NewFindACouple/NewFindACouple.sln b/NewFindACouple/NewFindACouple.sln new file mode 100644 index 0000000..c94d3f5 --- /dev/null +++ b/NewFindACouple/NewFindACouple.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33403.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewFindACouple", "NewFindACouple\NewFindACouple.csproj", "{5457E0B8-11B5-4D65-A76F-7302B1685CA1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5457E0B8-11B5-4D65-A76F-7302B1685CA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5457E0B8-11B5-4D65-A76F-7302B1685CA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5457E0B8-11B5-4D65-A76F-7302B1685CA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5457E0B8-11B5-4D65-A76F-7302B1685CA1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6AA191F3-0691-4C77-BC4D-D010165093BC} + EndGlobalSection +EndGlobal diff --git a/NewFindACouple/NewFindACouple/Form1.Designer.cs b/NewFindACouple/NewFindACouple/Form1.Designer.cs new file mode 100644 index 0000000..7a15d84 --- /dev/null +++ b/NewFindACouple/NewFindACouple/Form1.Designer.cs @@ -0,0 +1,47 @@ +namespace NewFindACouple +{ + partial class Form1 + { + /// + /// 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.SuspendLayout(); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/NewFindACouple/NewFindACouple/Form1.cs b/NewFindACouple/NewFindACouple/Form1.cs new file mode 100644 index 0000000..36edf67 --- /dev/null +++ b/NewFindACouple/NewFindACouple/Form1.cs @@ -0,0 +1,93 @@ +using System; + +namespace NewFindACouple +{ + public partial class Form1 : Form + { + private string previousButtonTag = string.Empty; + private Button previousButton; + + private void Button_Click(object sender, EventArgs eventArgs) + { + var button = (Button)sender; + if (previousButtonTag != string.Empty && previousButtonTag != "-") + { + if (button.Tag == null || previousButton.Tag == null) + { + throw new NullReferenceException(); + } + + if (previousButtonTag == button.Tag.ToString()) + { + previousButton.Text = previousButton.Tag.ToString(); + button.Text = button.Tag.ToString(); + previousButton.Tag = "-"; + button.Tag = "-"; + } + } + previousButtonTag = string.Copy(button.Tag.ToString()); + } + + public void AddGrid(int size) + { + + int[] arrayForNumbers = new int[size * size]; + + for (int i = 0; i < size * size; i++) + { + arrayForNumbers[i] = i; + } + + for (int i = 0; i < size; i++) + { + var random = new Random(); + var firstIndex = random.Next(0, size * size); + var secondIndex = random.Next(0, size * size); + if (firstIndex != secondIndex) + { + var copy = arrayForNumbers[firstIndex]; + arrayForNumbers[firstIndex] = arrayForNumbers[secondIndex]; + arrayForNumbers[secondIndex] = copy; + } + } + + int k = 0; + int top = 10; + int left = 10; + + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; ++j) + { + Button button = new Button(); + button.Left = left; + button.Top = top; + button.Location = new Point(left, top); + + this.Controls.Add(button); + top += button.Height + 2; + button.Name = "btn" + i + '.' + j; + button.Tag = arrayForNumbers[k].ToString(); + left += 100; + ++k; + button.Click += Button_Click; + + } + + top += 40; + left = 10; + } + } + + public Form1(int size) + { + InitializeComponent(); + AddGrid(size); + } + + private void Form1_Load(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/NewFindACouple/NewFindACouple/Form1.resx b/NewFindACouple/NewFindACouple/Form1.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/NewFindACouple/NewFindACouple/Form1.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/NewFindACouple/NewFindACouple/IncorectNumberException.cs b/NewFindACouple/NewFindACouple/IncorectNumberException.cs new file mode 100644 index 0000000..8a6fe77 --- /dev/null +++ b/NewFindACouple/NewFindACouple/IncorectNumberException.cs @@ -0,0 +1,2 @@ +namespace NewFindACouple; +internal class IncorectNumberException : Exception{} \ No newline at end of file diff --git a/NewFindACouple/NewFindACouple/NewFindACouple.csproj b/NewFindACouple/NewFindACouple/NewFindACouple.csproj new file mode 100644 index 0000000..e1a0735 --- /dev/null +++ b/NewFindACouple/NewFindACouple/NewFindACouple.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/NewFindACouple/NewFindACouple/NewFindACouple.csproj.user b/NewFindACouple/NewFindACouple/NewFindACouple.csproj.user new file mode 100644 index 0000000..7814ea2 --- /dev/null +++ b/NewFindACouple/NewFindACouple/NewFindACouple.csproj.user @@ -0,0 +1,8 @@ + + + + + Form + + + diff --git a/NewFindACouple/NewFindACouple/Program.cs b/NewFindACouple/NewFindACouple/Program.cs new file mode 100644 index 0000000..d1b30bf --- /dev/null +++ b/NewFindACouple/NewFindACouple/Program.cs @@ -0,0 +1,21 @@ +namespace NewFindACouple +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main(string[] args) + { + int result = 0; + bool check = int.TryParse(args[0], out result); + if (!check) + { + throw new IncorectNumberException(); + } + ApplicationConfiguration.Initialize(); + Application.Run(new Form1(result)); + } + } +} \ No newline at end of file