From 6008fd74ab49e22c32c61a49650b80d3fd8dc9bb Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 12 Dec 2022 14:59:18 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=A1=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingObjectAirplane.cs | 43 +++++++++++++++++++ .../AirplaneWithRadar/IDrawingObject.cs | 2 +- .../MapWithSetAirplanesGeneric.cs | 2 +- .../AirplaneWithRadar/SetAirplanesGeneric.cs | 6 ++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs index 252c1bd..c3765ed 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs @@ -33,5 +33,48 @@ namespace AirplaneWithRadar public string GetInfo() => _airplane?.GetDataForSave(); public static IDrawingObject Create(string data) => new DrawingObjectAirplane(data.CreateDrawingAirplane()); + public bool Equals(IDrawingObject? other) + { + if (other == null) + { + return false; + } + var otherAirplane = other as DrawingObjectAirplane; + if (otherAirplane == null) + { + return false; + } + var airplane = _airplane.Airplane; + var otherAirplaneAirplane = otherAirplane._airplane.Airplane; + if (airplane.Speed != otherAirplaneAirplane.Speed) + { + return false; + } + if (airplane.Weight != otherAirplaneAirplane.Weight) + { + return false; + } + if (airplane.BodyColor != otherAirplaneAirplane.BodyColor) + { + return false; + } + // TODO доделать проверки в случае продвинутого объекта + if (airplane is EntityAirplaneWithRadar airpl && otherAirplaneAirplane is EntityAirplaneWithRadar otherAirpl) + { + if (airpl.DopColor != otherAirpl.DopColor) + { + return false; + } + if (airpl.Radar != otherAirpl.Radar) + { + return false; + } + if (airpl.ExtraFuelTank != otherAirpl.ExtraFuelTank) + { + return false; + } + } + return true; + } } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs b/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs index 35c63ab..36a1535 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs @@ -3,7 +3,7 @@ /// /// Интерфейс для работы с объектом, прорисовываемым на форме /// - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs index 20d539d..fbe21f0 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs @@ -13,7 +13,7 @@ namespace AirplaneWithRadar /// /// internal class MapWithSetAirplanesGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { /// diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs index 43b5ce2..9b0fc52 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs @@ -11,7 +11,7 @@ namespace AirplaneWithRadar /// /// internal class SetAirplanesGeneric - where T : class + where T : class, IEquatable { /// /// Список объектов, которые храним @@ -59,6 +59,10 @@ namespace AirplaneWithRadar { // TODO проверка позиции // TODO вставка по позиции + if (_places.Contains(airplane)) + { + throw new ArgumentException($"Данный объект ({airplane}) уже есть в наборе"); + } if (position < 0 || position >= _maxCount) { throw new StorageOverflowException(_maxCount); -- 2.25.1 From 4f83cc4366712a64cfded531e98e5b516a78ece8 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 12 Dec 2022 15:24:53 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneCompareByColor.cs | 62 +++++++++++++++++++ .../AirplaneCompareByType.cs | 55 ++++++++++++++++ .../DrawingObjectAirplane.cs | 2 + .../FormMapWithSetAirplanes.Designer.cs | 50 +++++++++++---- .../FormMapWithSetAirplanes.cs | 29 +++++++++ .../MapWithSetAirplanesGeneric.cs | 9 +++ .../AirplaneWithRadar/SetAirplanesGeneric.cs | 12 ++++ 7 files changed, 207 insertions(+), 12 deletions(-) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs new file mode 100644 index 0000000..eb9a760 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class AirplaneCompareByColor : IComparer + { + public int Compare(IDrawingObject x, IDrawingObject y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xAirplane = x as DrawingObjectAirplane; + var yAirplane = y as DrawingObjectAirplane; + if (xAirplane == null && yAirplane == null) + { + return 0; + } + if (xAirplane == null && yAirplane != null) + { + return 1; + } + if (xAirplane != null && yAirplane == null) + { + return -1; + } + string xAirplaneColor = xAirplane.GetAirplane.Airplane.BodyColor.Name; + string yAirplaneColor = yAirplane.GetAirplane.Airplane.BodyColor.Name; + if (xAirplaneColor != yAirplaneColor) + { + return xAirplaneColor.CompareTo(yAirplane); + } + if (xAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar xAirpl && yAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar yAirpl) + { + string xAirplaneDopColor = xAirpl.DopColor.Name; + string yAirplaneDopColor = yAirpl.DopColor.Name; + if (xAirplaneDopColor != yAirplaneDopColor) + { + return xAirplaneDopColor.CompareTo(yAirplaneDopColor); + } + } + var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xAirplane.GetAirplane.Airplane.Weight.CompareTo(yAirplane.GetAirplane.Airplane.Weight); + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs new file mode 100644 index 0000000..2c33797 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class AirplaneCompareByType : IComparer + { + public int Compare(IDrawingObject? x, IDrawingObject? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xAirplane = x as DrawingObjectAirplane; + var yAirplane = y as DrawingObjectAirplane; + if (xAirplane == null && yAirplane == null) + { + return 0; + } + if (xAirplane == null && yAirplane != null) + { + return 1; + } + if (xAirplane != null && yAirplane == null) + { + return -1; + } + if (xAirplane.GetAirplane.GetType().Name != yAirplane.GetAirplane.GetType().Name) + { + if (xAirplane.GetAirplane.GetType().Name == "DrawingAirplane") + { + return 1; + } + return -1; + } + var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xAirplane.GetAirplane.Airplane.Weight.CompareTo(yAirplane.GetAirplane.Airplane.Weight); + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs index c3765ed..d2e1a3d 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs @@ -14,6 +14,8 @@ namespace AirplaneWithRadar _airplane = airplane; } public float Step => _airplane?.Airplane?.Step ?? 0; + public DrawingAirplane GetAirplane => _airplane; + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return _airplane?.GetCurrentPosition() ?? default; diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs index 7cc1fa7..3720f3c 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs @@ -29,6 +29,8 @@ private void InitializeComponent() { this.groupBox = new System.Windows.Forms.GroupBox(); + this.buttonSortByColor = new System.Windows.Forms.Button(); + this.buttonSortByType = new System.Windows.Forms.Button(); this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.buttonDeleteMap = new System.Windows.Forms.Button(); this.listBoxMaps = new System.Windows.Forms.ListBox(); @@ -59,6 +61,8 @@ // // groupBox // + this.groupBox.Controls.Add(this.buttonSortByColor); + this.groupBox.Controls.Add(this.buttonSortByType); this.groupBox.Controls.Add(this.groupBoxMaps); this.groupBox.Controls.Add(this.buttonRight); this.groupBox.Controls.Add(this.buttonDown); @@ -72,11 +76,31 @@ this.groupBox.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox.Location = new System.Drawing.Point(901, 33); this.groupBox.Name = "groupBox"; - this.groupBox.Size = new System.Drawing.Size(257, 750); + this.groupBox.Size = new System.Drawing.Size(257, 859); this.groupBox.TabIndex = 0; this.groupBox.TabStop = false; this.groupBox.Text = "Инструменты"; // + // buttonSortByColor + // + this.buttonSortByColor.Location = new System.Drawing.Point(23, 424); + this.buttonSortByColor.Name = "buttonSortByColor"; + this.buttonSortByColor.Size = new System.Drawing.Size(222, 34); + this.buttonSortByColor.TabIndex = 13; + this.buttonSortByColor.Text = "Сортировка по цвету"; + this.buttonSortByColor.UseVisualStyleBackColor = true; + this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click); + // + // buttonSortByType + // + this.buttonSortByType.Location = new System.Drawing.Point(23, 384); + this.buttonSortByType.Name = "buttonSortByType"; + this.buttonSortByType.Size = new System.Drawing.Size(222, 34); + this.buttonSortByType.TabIndex = 12; + this.buttonSortByType.Text = " Сортировка по типу "; + this.buttonSortByType.UseVisualStyleBackColor = true; + this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click); + // // groupBoxMaps // this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); @@ -144,7 +168,7 @@ // this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(153, 701); + this.buttonRight.Location = new System.Drawing.Point(149, 792); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 10; @@ -155,7 +179,7 @@ // this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(117, 701); + this.buttonDown.Location = new System.Drawing.Point(113, 792); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 9; @@ -166,7 +190,7 @@ // this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(81, 701); + this.buttonLeft.Location = new System.Drawing.Point(77, 792); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; @@ -177,7 +201,7 @@ // this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(117, 665); + this.buttonUp.Location = new System.Drawing.Point(113, 756); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; @@ -186,7 +210,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(23, 603); + this.buttonShowOnMap.Location = new System.Drawing.Point(23, 690); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(222, 34); this.buttonShowOnMap.TabIndex = 6; @@ -196,7 +220,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(23, 549); + this.buttonShowStorage.Location = new System.Drawing.Point(23, 638); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(222, 37); this.buttonShowStorage.TabIndex = 5; @@ -206,7 +230,7 @@ // // buttonRemoveAirplane // - this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 497); + this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 588); this.buttonRemoveAirplane.Name = "buttonRemoveAirplane"; this.buttonRemoveAirplane.Size = new System.Drawing.Size(222, 34); this.buttonRemoveAirplane.TabIndex = 4; @@ -216,7 +240,7 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 460); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 551); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(222, 31); @@ -224,7 +248,7 @@ // // buttonAddAirplane // - this.buttonAddAirplane.Location = new System.Drawing.Point(23, 406); + this.buttonAddAirplane.Location = new System.Drawing.Point(23, 496); this.buttonAddAirplane.Name = "buttonAddAirplane"; this.buttonAddAirplane.Size = new System.Drawing.Size(222, 34); this.buttonAddAirplane.TabIndex = 2; @@ -237,7 +261,7 @@ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 33); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(901, 750); + this.pictureBox.Size = new System.Drawing.Size(901, 859); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -286,7 +310,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1158, 783); + this.ClientSize = new System.Drawing.Size(1158, 892); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox); this.Controls.Add(this.menuStrip); @@ -330,5 +354,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button buttonSortByColor; + private Button buttonSortByType; } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs index a234cdf..ee744ac 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs @@ -306,6 +306,35 @@ namespace AirplaneWithRadar } } } + /// + /// Сортировка по типу + /// + /// + /// + private void ButtonSortByType_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirplaneCompareByType()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + /// + /// Сортировка по цвету + /// + /// + /// + private void ButtonSortByColor_Click(object sender, EventArgs e) + { + // TODO прописать логику + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirplaneCompareByColor()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs index fbe21f0..f9dee65 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs @@ -138,6 +138,15 @@ namespace AirplaneWithRadar _setAirplanes.Insert(DrawingObjectAirplane.Create(rec) as T); } } + /// + /// Сортировка + /// + /// + public void Sort(IComparer comparer) + { + _setAirplanes.SortSet(comparer); + } + /// /// "Взбалтываем" набор, чтобы все элементы оказались в начале /// diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs index 9b0fc52..f5f463e 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs @@ -141,5 +141,17 @@ namespace AirplaneWithRadar } } } + /// + /// Сортировка набора объектов + /// + /// + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } } } -- 2.25.1 From 7457b3483601e0b54798fc0412b993c24a3a2ff6 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Tue, 13 Dec 2022 11:35:28 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D0=B0=20AbstractMap=20=D0=BE=D1=82=20IEquatable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/AbstractMap.cs | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs index 8c78481..7a75b5f 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirplaneWithRadar { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawingObject _drawingObject = null; protected int[,] _map = null; @@ -130,5 +130,43 @@ namespace AirplaneWithRadar 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) + { + return false; + } + var otherMap = other as AbstractMap; + if (otherMap == null) + { + return false; + } + if (_width != otherMap._width) + { + return false; + } + if (_height != otherMap._height) + { + return false; + } + if (_size_x != otherMap._size_x) + { + return false; + } + if (_size_y != otherMap._size_y) + { + return false; + } + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] != otherMap._map[i, j]) + return false; + } + } + return true; + } } } -- 2.25.1 From 590b2985a654dcf6acced096dc92f9edb235216c Mon Sep 17 00:00:00 2001 From: Anastasia Date: Thu, 22 Dec 2022 21:58:41 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=B2=D0=BE=D1=81=D1=8C=D0=BC=D0=B0=D1=8F=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/AirplaneCompareByColor.cs | 16 +++++++--------- .../AirplaneWithRadar/AirplaneCompareByType.cs | 4 ++-- .../AirplaneWithRadar/DrawingObjectAirplane.cs | 2 ++ .../AirplaneWithRadar/FormAirplaneWithRadar.cs | 6 +++++- .../AirplaneWithRadar/SetAirplanesGeneric.cs | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs index eb9a760..a380cc3 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs @@ -8,7 +8,7 @@ namespace AirplaneWithRadar { internal class AirplaneCompareByColor : IComparer { - public int Compare(IDrawingObject x, IDrawingObject y) + public int Compare(IDrawingObject? x, IDrawingObject? y) { if (x == null && y == null) { @@ -36,19 +36,17 @@ namespace AirplaneWithRadar { return -1; } - string xAirplaneColor = xAirplane.GetAirplane.Airplane.BodyColor.Name; - string yAirplaneColor = yAirplane.GetAirplane.Airplane.BodyColor.Name; - if (xAirplaneColor != yAirplaneColor) + var baseColorCompare = xAirplane.GetAirplane.Airplane.BodyColor.ToString().CompareTo(yAirplane.GetAirplane.Airplane.BodyColor.ToString()); + if (baseColorCompare != 0) { - return xAirplaneColor.CompareTo(yAirplane); + return baseColorCompare; } if (xAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar xAirpl && yAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar yAirpl) { - string xAirplaneDopColor = xAirpl.DopColor.Name; - string yAirplaneDopColor = yAirpl.DopColor.Name; - if (xAirplaneDopColor != yAirplaneDopColor) + var dopColorCompare = xAirpl.DopColor.ToString().CompareTo(yAirpl.DopColor.ToString()); + if (dopColorCompare != 0) { - return xAirplaneDopColor.CompareTo(yAirplaneDopColor); + return dopColorCompare; } } var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed); diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs index 2c33797..771d540 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs @@ -40,9 +40,9 @@ namespace AirplaneWithRadar { if (xAirplane.GetAirplane.GetType().Name == "DrawingAirplane") { - return 1; + return -1; } - return -1; + return 1; } var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed); if (speedCompare != 0) diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs index d2e1a3d..def80df 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs @@ -76,6 +76,8 @@ namespace AirplaneWithRadar return false; } } + else if (airplane is EntityAirplaneWithRadar || otherAirplaneAirplane is EntityAirplaneWithRadar) return false; + return true; } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs index 21d57ce..7a8ffa8 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs @@ -48,7 +48,11 @@ namespace AirplaneWithRadar SetData(); Draw(); } - + /// + /// + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs index f5f463e..b9cb5fe 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs @@ -152,6 +152,6 @@ namespace AirplaneWithRadar return; } _places.Sort(comparer); - } + } } } -- 2.25.1