-
Notifications
You must be signed in to change notification settings - Fork 0
Неудача #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Неудача #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -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(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| for (int i = 0; i < size * size; i++) | ||||||
| { | ||||||
| arrayForNumbers[i] = i; | ||||||
| } | ||||||
|
|
||||||
| for (int i = 0; i < size; i++) | ||||||
| { | ||||||
| var random = new Random(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||
| { | ||||||
|
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
| 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> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||
| namespace NewFindACouple; | ||||||
| internal class IncorectNumberException : Exception{} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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> |
| 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> |
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| if (!check) | ||||||||
| { | ||||||||
| throw new IncorectNumberException(); | ||||||||
| } | ||||||||
| ApplicationConfiguration.Initialize(); | ||||||||
| Application.Run(new Form1(result)); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
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;и дальше без фигурной скобки и отступа