Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions NewFindACouple/NewFindACouple.sln
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions NewFindACouple/NewFindACouple/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions NewFindACouple/NewFindACouple/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;

namespace NewFindACouple

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо использовать file-scoped namespaces, 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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.Copy не нужен, просто присвоения достаточно

}

public void AddGrid(int size)
{

int[] arrayForNumbers = new int[size * size];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int[] arrayForNumbers = new int[size * size];
var 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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Никогда не создавайте 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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Button button = new Button();
Button button = new();

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Непонятно, как обеспечивается "парность" кнопок, в массиве ведь просто числа от 0 до size * size

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)
{

}
}
}
60 changes: 60 additions & 0 deletions NewFindACouple/NewFindACouple/Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<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>
2 changes: 2 additions & 0 deletions NewFindACouple/NewFindACouple/IncorectNumberException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
namespace NewFindACouple;
internal class IncorectNumberException : Exception{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal class IncorectNumberException : Exception{}
internal class IncorrectNumberException : Exception{}

11 changes: 11 additions & 0 deletions NewFindACouple/NewFindACouple/NewFindACouple.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions NewFindACouple/NewFindACouple/NewFindACouple.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions NewFindACouple/NewFindACouple/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NewFindACouple
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int result = 0;
bool check = int.TryParse(args[0], out result);
Comment on lines +11 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int result = 0;
bool check = int.TryParse(args[0], out result);
bool check = int.TryParse(args[0], out int result);

if (!check)
{
throw new IncorectNumberException();
}
ApplicationConfiguration.Initialize();
Application.Run(new Form1(result));
}
}
}