From d81aa61eb0088a440228c30734310bc658084842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 31 Oct 2022 06:03:27 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=86=D0=B2=D0=B5=D1=82=D1=83=20=D0=B8=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirplaneCompareByColor.cs | 31 ++++++++++++++++ AirBomber/AirBomber/AirplaneCompareByType.cs | 37 +++++++++++++++++++ AirBomber/AirBomber/DrawningObject.cs | 18 ++++----- AirBomber/AirBomber/Program.cs | 2 + 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 AirBomber/AirBomber/AirplaneCompareByColor.cs create mode 100644 AirBomber/AirBomber/AirplaneCompareByType.cs diff --git a/AirBomber/AirBomber/AirplaneCompareByColor.cs b/AirBomber/AirBomber/AirplaneCompareByColor.cs new file mode 100644 index 0000000..28e2879 --- /dev/null +++ b/AirBomber/AirBomber/AirplaneCompareByColor.cs @@ -0,0 +1,31 @@ +namespace AirBomber +{ + internal class AirplaneCompareByColor : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + var xAirplane = x as DrawningObject; + var yAirplane = y as DrawningObject; + if (xAirplane == yAirplane) + { + return 0; + } + if (xAirplane == null) + { + return 1; + } + if (yAirplane == null) + { + return -1; + } + var xEntity = xAirplane.Airplane.Airplane; + var yEntity = yAirplane.Airplane.Airplane; + var colorWeight = xEntity.BodyColor.ToArgb().CompareTo(yEntity.BodyColor.ToArgb()); + if (colorWeight != 0 || xEntity is not EntityAirBomber || yEntity is not EntityAirBomber) + { + return colorWeight; + } + return ((EntityAirBomber)xEntity).DopColor.ToArgb().CompareTo(((EntityAirBomber)yEntity).DopColor.ToArgb()); + } + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/AirplaneCompareByType.cs b/AirBomber/AirBomber/AirplaneCompareByType.cs new file mode 100644 index 0000000..464b8f6 --- /dev/null +++ b/AirBomber/AirBomber/AirplaneCompareByType.cs @@ -0,0 +1,37 @@ +namespace AirBomber +{ + internal class AirplaneCompareByType : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + var xAirplane = x as DrawningObject; + var yAirplane = y as DrawningObject; + if (xAirplane == yAirplane) + { + return 0; + } + if (xAirplane == null) + { + return 1; + } + if (yAirplane == null) + { + return -1; + } + if (xAirplane.GetType().Name != yAirplane.Airplane.GetType().Name) + { + if (xAirplane.Airplane.GetType().Name == "DrawningAirplane") + { + return -1; + } + return 1; + } + var speedCompare = xAirplane.Airplane.Airplane.Speed.CompareTo(yAirplane.Airplane.Airplane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xAirplane.Airplane.Airplane.Weight.CompareTo(yAirplane.Airplane.Airplane.Weight); + } + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs index 4bb3594..487ccef 100644 --- a/AirBomber/AirBomber/DrawningObject.cs +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -8,36 +8,36 @@ namespace AirBomber { internal class DrawningObject : IDrawningObject { - private DrawningAirplane _airplane = null; - public DrawningObject(DrawningAirplane airplane) { - _airplane = airplane; + Airplane = airplane; } - public float Step => _airplane?.Airplane?.Step ?? 0; + public float Step => Airplane?.Airplane?.Step ?? 0; + + public DrawningAirplane Airplane { get; private set; } public RectangleF GetCurrentPosition() { - return _airplane.GetCurrentPosition(); + return Airplane.GetCurrentPosition(); } public void MoveObject(Direction direction) { - _airplane?.MoveTransport(direction); + Airplane?.MoveTransport(direction); } public void SetObject(int x, int y, int width, int height) { - _airplane?.SetPosition(x, y, width, height); + Airplane?.SetPosition(x, y, width, height); } public void DrawObject(Graphics g) { - _airplane?.DrawTransport(g); + Airplane?.DrawTransport(g); } - public string GetInfo() => _airplane?.GetDataForSave(); + public string GetInfo() => Airplane?.GetDataForSave() ?? string.Empty; public static IDrawningObject Create(string data) => new DrawningObject(data.CreateDrawningAirplane()); } diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index f0821c2..4485161 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -17,6 +17,8 @@ namespace AirBomber { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. + var cmp = new AirplaneCompareByType(); + cmp.Compare(null, null); ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); From c03e76fb60cfee1d1dcddc82d740456fc982be3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 31 Oct 2022 06:30:18 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=20=D0=BD=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirplaneCompareByColor.cs | 6 +++-- AirBomber/AirBomber/DrawningObject.cs | 26 +++++++++++++++++++ .../AirBomber/FormMapWithSetAirplanes.cs | 5 ++++ AirBomber/AirBomber/IDrawningObject.cs | 2 +- AirBomber/AirBomber/SetAirplanesGeneric.cs | 6 ++++- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/AirBomber/AirBomber/AirplaneCompareByColor.cs b/AirBomber/AirBomber/AirplaneCompareByColor.cs index 28e2879..35b0020 100644 --- a/AirBomber/AirBomber/AirplaneCompareByColor.cs +++ b/AirBomber/AirBomber/AirplaneCompareByColor.cs @@ -21,11 +21,13 @@ var xEntity = xAirplane.Airplane.Airplane; var yEntity = yAirplane.Airplane.Airplane; var colorWeight = xEntity.BodyColor.ToArgb().CompareTo(yEntity.BodyColor.ToArgb()); - if (colorWeight != 0 || xEntity is not EntityAirBomber || yEntity is not EntityAirBomber) + if (colorWeight != 0 || + xEntity is not EntityAirBomber xEntityAirBomber || + yEntity is not EntityAirBomber yEntityAirBomber) { return colorWeight; } - return ((EntityAirBomber)xEntity).DopColor.ToArgb().CompareTo(((EntityAirBomber)yEntity).DopColor.ToArgb()); + return xEntityAirBomber.DopColor.ToArgb().CompareTo(yEntityAirBomber.DopColor.ToArgb()); } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs index 487ccef..45790d7 100644 --- a/AirBomber/AirBomber/DrawningObject.cs +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -40,5 +40,31 @@ namespace AirBomber public string GetInfo() => Airplane?.GetDataForSave() ?? string.Empty; public static IDrawningObject Create(string data) => new DrawningObject(data.CreateDrawningAirplane()); + + public bool Equals(IDrawningObject? other) + { + if (other is not DrawningObject otherAirplane) + { + return false; + } + var entity = Airplane.Airplane; + var otherEntity = otherAirplane.Airplane.Airplane; + if (entity.GetType() != otherEntity.GetType() || + entity.Speed != otherEntity.Speed || + entity.Weight != otherEntity.Weight || + entity.BodyColor != otherEntity.BodyColor) + { + return false; + } + if (entity is EntityAirBomber entityAirBomber && + otherEntity is EntityAirBomber otherEntityAirBomber && ( + entityAirBomber.HasBombs != otherEntityAirBomber.HasBombs || + entityAirBomber.DopColor != otherEntityAirBomber.DopColor || + entityAirBomber.HasFuelTanks != otherEntityAirBomber.HasFuelTanks)) + { + return false; + } + return true; + } } } diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index c4f6072..ba0b13e 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -149,6 +149,11 @@ namespace AirBomber _logger.LogWarning("Ошибка переполнения хранилища: {0}", ex.Message); MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } + catch (ArgumentException ex) + { + _logger.LogWarning("Ошибка добавления: {0}. Объект: {@Airplane}", ex.Message, airplane); + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } /// diff --git a/AirBomber/AirBomber/IDrawningObject.cs b/AirBomber/AirBomber/IDrawningObject.cs index 87584d8..139757c 100644 --- a/AirBomber/AirBomber/IDrawningObject.cs +++ b/AirBomber/AirBomber/IDrawningObject.cs @@ -9,7 +9,7 @@ namespace AirBomber /// /// Интерфейс для работы с объектом, прорисовываемым на форме /// - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 986ccf7..9e0c62c 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -11,7 +11,7 @@ namespace AirBomber /// /// internal class SetAirplanesGeneric - where T : class + where T : class, IEquatable { /// /// Список объектов, которые храним @@ -51,9 +51,13 @@ namespace AirBomber /// /// Добавляемый самолет /// Позиция + /// Исключения генерируется при попытке добавить дубликат в набор + /// /// Возвращает позицию вставленного объекта, либо -1 если его не удалось вставить public int Insert(T airplane, int position) { + if (_places.Contains(airplane)) + throw new ArgumentException($"Объект {airplane} уже есть в наборе"); if (Count == _maxcount) throw new StorageOverflowException(_maxcount); if (!isCorrectPosition(position)) From 88ccde9c4d3249ae2add64b90e78254264ab997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 31 Oct 2022 06:47:47 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D1=82=D0=B8=D0=BF=D1=83=20?= =?UTF-8?q?=D0=B8=20=D1=86=D0=B2=D0=B5=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetAirplanes.Designer.cs | 61 ++++++++++++++----- .../AirBomber/FormMapWithSetAirplanes.cs | 18 ++++++ .../AirBomber/FormMapWithSetAirplanes.resx | 9 +++ .../AirBomber/MapWithSetAirplanesGeneric.cs | 9 +++ AirBomber/AirBomber/SetAirplanesGeneric.cs | 12 ++++ 5 files changed, 93 insertions(+), 16 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs index 9bd368d..b7aa21f 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs @@ -51,13 +51,18 @@ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.buttonSortByColor = new System.Windows.Forms.Button(); + this.buttonSortByType = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.buttonSortByType); + this.groupBoxTools.Controls.Add(this.buttonSortByColor); this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane); @@ -69,9 +74,9 @@ this.groupBoxTools.Controls.Add(this.buttonShowOnMap); this.groupBoxTools.Controls.Add(this.buttonAddAirplane); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(811, 0); + this.groupBoxTools.Location = new System.Drawing.Point(811, 24); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(204, 632); + this.groupBoxTools.Size = new System.Drawing.Size(204, 625); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -140,16 +145,17 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 399); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); this.maskedTextBoxPosition.TabIndex = 2; this.maskedTextBoxPosition.ValidatingType = typeof(int); + this.maskedTextBoxPosition.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBoxPosition_MaskInputRejected); // // buttonRemoveAirplane // - this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 384); + this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 428); this.buttonRemoveAirplane.Name = "buttonRemoveAirplane"; this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35); this.buttonRemoveAirplane.TabIndex = 3; @@ -159,7 +165,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(17, 437); + this.buttonShowStorage.Location = new System.Drawing.Point(17, 472); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); this.buttonShowStorage.TabIndex = 4; @@ -172,7 +178,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(91, 582); + this.buttonDown.Location = new System.Drawing.Point(90, 588); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 10; @@ -184,7 +190,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(127, 582); + this.buttonRight.Location = new System.Drawing.Point(126, 588); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 9; @@ -196,7 +202,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(55, 582); + this.buttonLeft.Location = new System.Drawing.Point(54, 588); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; @@ -208,7 +214,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(91, 546); + this.buttonUp.Location = new System.Drawing.Point(90, 552); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; @@ -217,7 +223,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487); + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 513); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); this.buttonShowOnMap.TabIndex = 5; @@ -227,7 +233,7 @@ // // buttonAddAirplane // - this.buttonAddAirplane.Location = new System.Drawing.Point(17, 314); + this.buttonAddAirplane.Location = new System.Drawing.Point(17, 358); this.buttonAddAirplane.Name = "buttonAddAirplane"; this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35); this.buttonAddAirplane.TabIndex = 1; @@ -238,9 +244,9 @@ // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Location = new System.Drawing.Point(0, 24); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(811, 632); + this.pictureBox.Size = new System.Drawing.Size(811, 625); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -265,14 +271,14 @@ // SaveToolStripMenuItem // this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.SaveToolStripMenuItem.Text = "Сохранение"; this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); // // LoadToolStripMenuItem // this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.LoadToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.LoadToolStripMenuItem.Text = "Загрузка"; this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); // @@ -284,11 +290,31 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByColor + // + this.buttonSortByColor.Location = new System.Drawing.Point(17, 317); + this.buttonSortByColor.Name = "buttonSortByColor"; + this.buttonSortByColor.Size = new System.Drawing.Size(175, 35); + this.buttonSortByColor.TabIndex = 11; + this.buttonSortByColor.Text = "Отсортировать по цвету"; + this.buttonSortByColor.UseVisualStyleBackColor = true; + this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByType_Click); + // + // buttonSortByType + // + this.buttonSortByType.Location = new System.Drawing.Point(17, 276); + this.buttonSortByType.Name = "buttonSortByType"; + this.buttonSortByType.Size = new System.Drawing.Size(175, 35); + this.buttonSortByType.TabIndex = 12; + this.buttonSortByType.Text = "Отсортировать по типу"; + this.buttonSortByType.UseVisualStyleBackColor = true; + this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByColor_Click); + // // FormMapWithSetAirplanes // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1015, 632); + this.ClientSize = new System.Drawing.Size(1015, 649); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.menuStrip); @@ -303,6 +329,7 @@ this.menuStrip.ResumeLayout(false); this.menuStrip.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -331,5 +358,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button buttonSortByType; + private Button buttonSortByColor; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index ba0b13e..f2d56d0 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -294,5 +294,23 @@ namespace AirBomber } } } + + private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) + { + + } + + private void SortBy(IComparer comparer) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(comparer); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + + private void ButtonSortByType_Click (object sender, EventArgs e) => SortBy(new AirplaneCompareByType()); + private void ButtonSortByColor_Click(object sender, EventArgs e) => SortBy(new AirplaneCompareByColor()); } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.resx b/AirBomber/AirBomber/FormMapWithSetAirplanes.resx index f298a7b..1d824c7 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.resx +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.resx @@ -57,4 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 125, 17 + + + 258, 17 + \ No newline at end of file diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index 6a18d52..cd48a0b 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -208,5 +208,14 @@ namespace AirBomber _setAirplanes.Insert(DrawningObject.Create(rec) as T); } } + + /// + /// Сортировка + /// + /// + public void Sort(IComparer comparer) + { + _setAirplanes.SortSet(comparer); + } } } diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 9e0c62c..af5bc85 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -117,5 +117,17 @@ namespace AirBomber } } + /// + /// Сортировка набора объектов + /// + /// + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } } } From 087813f8fb302f627612be491d06b3d9a0d69c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 31 Oct 2022 07:29:26 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirplaneCompareByType.cs | 4 ++-- AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs | 4 ++-- AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AirBomber/AirBomber/AirplaneCompareByType.cs b/AirBomber/AirBomber/AirplaneCompareByType.cs index 464b8f6..43bc7ce 100644 --- a/AirBomber/AirBomber/AirplaneCompareByType.cs +++ b/AirBomber/AirBomber/AirplaneCompareByType.cs @@ -18,9 +18,9 @@ { return -1; } - if (xAirplane.GetType().Name != yAirplane.Airplane.GetType().Name) + if (xAirplane.Airplane.GetType().Name != yAirplane.Airplane.GetType().Name) { - if (xAirplane.Airplane.GetType().Name == "DrawningAirplane") + if (xAirplane.Airplane.GetType() == typeof(DrawningAirplane)) { return -1; } diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs index b7aa21f..9c855b6 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs @@ -298,7 +298,7 @@ this.buttonSortByColor.TabIndex = 11; this.buttonSortByColor.Text = "Отсортировать по цвету"; this.buttonSortByColor.UseVisualStyleBackColor = true; - this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByType_Click); + this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click); // // buttonSortByType // @@ -308,7 +308,7 @@ this.buttonSortByType.TabIndex = 12; this.buttonSortByType.Text = "Отсортировать по типу"; this.buttonSortByType.UseVisualStyleBackColor = true; - this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByColor_Click); + this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click); // // FormMapWithSetAirplanes // diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index cd48a0b..96b94fb 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirBomber { internal class MapWithSetAirplanesGeneric - where T : class, IDrawningObject + where T : class, IEquatable, IDrawningObject where U : AbstractMap { /// From 6adfe4966994fd313b182553dc60eebdc034f733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 31 Oct 2022 07:48:44 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20Equals=20=D0=B2=20Abs?= =?UTF-8?q?tractMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractMap.cs | 29 ++++++++++++++++++++++++++++- AirBomber/AirBomber/Program.cs | 2 -- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs index 62dbec5..b9104c6 100644 --- a/AirBomber/AirBomber/AbstractMap.cs +++ b/AirBomber/AirBomber/AbstractMap.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirBomber { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawningObject = null; private Bitmap? _staticBitMap; @@ -174,5 +174,32 @@ namespace AirBomber protected abstract void GenerateMap(); protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); + + public bool Equals(AbstractMap? other) + { + if (other == null || + _map != other._map || + _width != other._width || + _size_x != other._size_x || + _size_y != other._size_y || + _height != other._height || + GetType() != other.GetType() || + _map.GetLength(0) != other._map.GetLength(0) || + _map.GetLength(1) != other._map.GetLength(1)) + { + return false; + } + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] != other._map[i, j]) + { + return false; + } + } + } + return true; + } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 4485161..f0821c2 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -17,8 +17,6 @@ namespace AirBomber { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. - var cmp = new AirplaneCompareByType(); - cmp.Compare(null, null); ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); From 69caa4463d5c97abba8156b0959b9b12ca96ea85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Tue, 1 Nov 2022 20:18:43 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs | 1 - AirBomber/AirBomber/FormMapWithSetAirplanes.cs | 5 ----- 2 files changed, 6 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs index 9c855b6..52a27f9 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs @@ -151,7 +151,6 @@ this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); this.maskedTextBoxPosition.TabIndex = 2; this.maskedTextBoxPosition.ValidatingType = typeof(int); - this.maskedTextBoxPosition.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBoxPosition_MaskInputRejected); // // buttonRemoveAirplane // diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index f2d56d0..d822bab 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -295,11 +295,6 @@ namespace AirBomber } } - private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) - { - - } - private void SortBy(IComparer comparer) { if (listBoxMaps.SelectedIndex == -1) From 93d704a1b8446b5cdbcfea479b57dec0f096ef67 Mon Sep 17 00:00:00 2001 From: "d.agil" Date: Wed, 2 Nov 2022 11:52:30 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapsCollection.cs | 49 ++++++++++++--------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index 7ba6aa9..c9aaea7 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -110,39 +110,34 @@ namespace AirBomber { throw new FileNotFoundException("Файл не найден"); } - List strs = new List(); using (StreamReader fs = new(filename)) { + if (!fs.ReadLine().Contains("MapsCollection")) + { + //если нет такой записи, то это не те данные + throw new FileFormatException("Формат данных в файле не правильный"); + } + //очищаем записи + _mapStorages.Clear(); while (!fs.EndOfStream) { - strs.Add(fs.ReadLine()); + var elem = fs.ReadLine().Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "WallMap": + map = new WallMap(); + break; + } + _mapStorages.Add(elem[0], new + MapWithSetAirplanesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, + StringSplitOptions.RemoveEmptyEntries)); } } - if (!strs[0].Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - throw new FileFormatException("Формат данных в файле не правильный"); - } - //очищаем записи - _mapStorages.Clear(); - for (int i = 1; i < strs.Count; ++i) - { - var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) - { - case "SimpleMap": - map = new SimpleMap(); - break; - case "WallMap": - map = new WallMap(); - break; - } - _mapStorages.Add(elem[0], new - MapWithSetAirplanesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, - StringSplitOptions.RemoveEmptyEntries)); - } } } }