From a145a52010275dab54995fbb7bdd08ac47abde2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Fri, 2 Dec 2022 20:40:53 +0300 Subject: [PATCH 1/3] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirPlaneWithRadar/DrawingObjectPlane.cs | 30 +++++++++++++++++++ .../AirPlaneWithRadar/IDrawingObject.cs | 2 +- .../MapWithSetPlainGeneric.cs | 2 +- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 3 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs index 775f898..d448c49 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs @@ -39,5 +39,35 @@ namespace AirPlaneWithRadar { _plain.setPosition(x, y, width, height); } + + public bool Equals(IDrawingObject? other) + { + if (other == null) + { + return false; + } + var otherPlain = other as DrawingObjectPlane; + if (otherPlain == null) + { + return false; + } + var plain = _plain.Plain; + var otherPlainPlain = otherPlain._plain.Plain; + + if (plain.Speed != otherPlainPlain.Speed) + { + return false; + } + if (plain.Weight != otherPlainPlain.Weight) + { + return false; + } + if (plain.BodyColor != otherPlainPlain.BodyColor) + { + return false; + } + + return true; + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs b/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs index f635355..5cd8596 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirPlaneWithRadar { - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { public float Step { get; } void SetObject(int x, int y, int width, int height); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index 7ad30c9..f7db018 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -8,7 +8,7 @@ namespace AirPlaneWithRadar { internal class MapWithSetPlainGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index bc20ae1..3d0bee2 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirPlaneWithRadar { internal class SetPlaneGeneric - where T : class + where T : class, IEquatable { private readonly List _places; @@ -26,6 +26,7 @@ namespace AirPlaneWithRadar } public int Insert(T plain, int position) { + ///// if (_places.Count == _maxCount) { throw new StorageOverFullException(_maxCount); -- 2.25.1 From 71fb1ccbde308aa3a12c04a051e7a55e72dd3e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Fri, 2 Dec 2022 20:50:53 +0300 Subject: [PATCH 2/3] =?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=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirPlaneWithRadar/DrawingObjectPlane.cs | 2 +- .../FormMapWithSetPlains.Designer.cs | 54 +++++++++++++----- .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 14 +++++ .../MapWithSetPlainGeneric.cs | 5 +- .../AirPlaneWithRadar/PlaneCompareByColor.cs | 16 ++++++ .../AirPlaneWithRadar/PlaneCompareByType.cs | 55 +++++++++++++++++++ .../AirPlaneWithRadar/SetPlaneGeneric.cs | 6 ++ 7 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByType.cs diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs index d448c49..dee3243 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs @@ -34,7 +34,7 @@ namespace AirPlaneWithRadar { _plain?.MoveTransport(direction); } - + public DrawingPlain GetPlane => _plain; public void SetObject(int x, int y, int width, int height) { _plain.setPosition(x, y, width, height); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs index fad62a9..17532cc 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs @@ -28,6 +28,8 @@ /// private void InitializeComponent() { + this.buttonSortByType = new System.Windows.Forms.Button(); + this.buttonSortByColor = new System.Windows.Forms.Button(); this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.buttonAddMap = new System.Windows.Forms.Button(); @@ -57,8 +59,30 @@ this.menuStrip.SuspendLayout(); this.SuspendLayout(); // + // buttonSortByType + // + this.buttonSortByType.Location = new System.Drawing.Point(20, 368); + this.buttonSortByType.Name = "buttonSortByType"; + this.buttonSortByType.Size = new System.Drawing.Size(196, 47); + this.buttonSortByType.TabIndex = 12; + this.buttonSortByType.Text = "Сортировать по типу"; + this.buttonSortByType.UseVisualStyleBackColor = true; + this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click); + // + // buttonSortByColor + // + this.buttonSortByColor.Location = new System.Drawing.Point(23, 432); + this.buttonSortByColor.Name = "buttonSortByColor"; + this.buttonSortByColor.Size = new System.Drawing.Size(196, 47); + this.buttonSortByColor.TabIndex = 11; + this.buttonSortByColor.Text = "Сортировать по цвету"; + this.buttonSortByColor.UseVisualStyleBackColor = true; + this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click); + // // 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.buttonRemovePlain); @@ -74,7 +98,7 @@ this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupBoxTools.Size = new System.Drawing.Size(233, 815); + this.groupBoxTools.Size = new System.Drawing.Size(233, 909); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -150,7 +174,7 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 473); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 540); this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; @@ -160,7 +184,7 @@ // // buttonRemovePlain // - this.buttonRemovePlain.Location = new System.Drawing.Point(19, 512); + this.buttonRemovePlain.Location = new System.Drawing.Point(17, 579); this.buttonRemovePlain.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemovePlain.Name = "buttonRemovePlain"; this.buttonRemovePlain.Size = new System.Drawing.Size(200, 47); @@ -171,7 +195,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(19, 583); + this.buttonShowStorage.Location = new System.Drawing.Point(17, 650); this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(200, 47); @@ -185,7 +209,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(104, 748); + this.buttonDown.Location = new System.Drawing.Point(104, 842); this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(34, 40); @@ -198,7 +222,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(145, 748); + this.buttonRight.Location = new System.Drawing.Point(145, 842); this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(34, 40); @@ -211,7 +235,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(63, 748); + this.buttonLeft.Location = new System.Drawing.Point(63, 842); this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(34, 40); @@ -224,7 +248,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(104, 700); + this.buttonUp.Location = new System.Drawing.Point(104, 794); this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(34, 40); @@ -234,7 +258,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(19, 649); + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 716); this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47); @@ -245,7 +269,7 @@ // // buttonAddPlain // - this.buttonAddPlain.Location = new System.Drawing.Point(19, 419); + this.buttonAddPlain.Location = new System.Drawing.Point(17, 486); this.buttonAddPlain.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddPlain.Name = "buttonAddPlain"; this.buttonAddPlain.Size = new System.Drawing.Size(200, 47); @@ -260,7 +284,7 @@ this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(927, 815); + this.pictureBox.Size = new System.Drawing.Size(927, 909); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -287,14 +311,14 @@ // SaveToolStrip // this.SaveToolStrip.Name = "SaveToolStrip"; - this.SaveToolStrip.Size = new System.Drawing.Size(224, 26); + this.SaveToolStrip.Size = new System.Drawing.Size(177, 26); this.SaveToolStrip.Text = "Сохранение"; this.SaveToolStrip.Click += new System.EventHandler(this.SaveToolStrip_Click); // // loadToolStrip // this.loadToolStrip.Name = "loadToolStrip"; - this.loadToolStrip.Size = new System.Drawing.Size(224, 26); + this.loadToolStrip.Size = new System.Drawing.Size(177, 26); this.loadToolStrip.Text = "Загрузка"; this.loadToolStrip.Click += new System.EventHandler(this.loadToolStrip_Click); // @@ -310,7 +334,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1160, 843); + this.ClientSize = new System.Drawing.Size(1160, 937); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.menuStrip); @@ -354,6 +378,8 @@ private ToolStripMenuItem loadToolStrip; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button buttonSortByType; + private Button buttonSortByColor; } } \ No newline at end of file diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 0508b87..8aa96ba 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -275,6 +275,20 @@ namespace AirPlaneWithRadar } } + private void ButtonSortByType_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new PlaneCompareByType()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + + private void ButtonSortByColor_Click(object sender, EventArgs e) + { + + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index f7db018..6b087d3 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -121,7 +121,10 @@ namespace AirPlaneWithRadar } return data; } - + public void Sort(IComparer comparer) + { + _setPlains.SortSet(comparer); + } public void LoadData(string[] records) { foreach (var rec in records) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs b/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs new file mode 100644 index 0000000..218a4a6 --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + internal class PlaneCompareByColor : IComparer + { + public int Compare(IDrawingObject? x, IDrawingObject? y) + { + throw new NotImplementedException(); + } + } +} diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByType.cs b/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByType.cs new file mode 100644 index 0000000..062c4dd --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByType.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 PlaneCompareByType : 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 xPlain = x as DrawingObjectPlane; + var yPlain = y as DrawingObjectPlane; + if (xPlain == null && yPlain == null) + { + return 0; + } + if (xPlain == null && yPlain != null) + { + return 1; + } + if (xPlain != null && yPlain == null) + { + return -1; + } + if (!(xPlain.GetPlane.GetType().Name.Equals(yPlain.GetPlane.GetType().Name))) + { + if (xPlain.GetPlane.GetType().Name.Equals("DrawingPlain")) + { + return -1; + } + return 1; + } + var speedCompare = xPlain.GetPlane.Plain.Speed.CompareTo(yPlain.GetPlane.Plain.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xPlain.GetPlane.Plain.Weight.CompareTo(yPlain.GetPlane.Plain.Weight); + } + } +} diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index 3d0bee2..f96b2b7 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -83,6 +83,12 @@ namespace AirPlaneWithRadar yield break; } } + public void SortSet(IComparer comparer) + { + if (comparer == null) + return; + _places.Sort(comparer); + } } } -- 2.25.1 From 7699e88659f7a5a107ccf34ecf6142bf36423c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Fri, 2 Dec 2022 21:23:47 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirPlaneWithRadar/AbstractMap.cs | 34 ++++++++++- .../AirPlaneWithRadar/DrawingObjectPlane.cs | 14 ++++- .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 7 ++- AirPlaneWithRadar/AirPlaneWithRadar/Log.txt | 58 +++++++++++++++++++ .../AirPlaneWithRadar/PlaneCompareByColor.cs | 38 +++++++++++- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 4 +- 6 files changed, 149 insertions(+), 6 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/AbstractMap.cs b/AirPlaneWithRadar/AirPlaneWithRadar/AbstractMap.cs index 1e193f7..1e39948 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 _drawningObject = null; protected int[,] _map = null; @@ -145,5 +145,37 @@ 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 string ArrToStr(int[,] arr) + { + string res = ""; + foreach (int i in arr) + { + res += i; + } + return res; + } + public bool Equals(AbstractMap? other) + { + if (other == null) + { + return false; + } + var curMap = this; + var otherMap = other; + if (curMap._height != otherMap._height) + return false; + if (curMap._width != otherMap._width) + return false; + if (curMap._size_x != otherMap._size_x) + return false; + if (curMap._size_y != otherMap._size_y) + return false; + string arr1 = ArrToStr(curMap._map); + string arr2 = ArrToStr(curMap._map); + if (!arr1.Equals(arr2)) + return false; + return true; + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs index dee3243..b5bc709 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs @@ -66,7 +66,19 @@ namespace AirPlaneWithRadar { return false; } - + var RadPlain = plain as RadioPlane; + var otherRadPlain = otherPlainPlain as RadioPlane; + if (RadPlain == null && otherRadPlain == null) + return true; + if (RadPlain == null || otherRadPlain == null) + return false; + if (!(RadPlain.DopColor.Equals(otherRadPlain.DopColor))) + return false; + if (!(RadPlain.Radar.Equals(otherRadPlain.Radar))) + return false; + if (!(RadPlain.OilBox.Equals(otherRadPlain.OilBox))) + return false; + return true; } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 8aa96ba..e31acf1 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -287,7 +287,12 @@ namespace AirPlaneWithRadar private void ButtonSortByColor_Click(object sender, EventArgs e) { - + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new PlaneCompareByColor()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/Log.txt b/AirPlaneWithRadar/AirPlaneWithRadar/Log.txt index 0274be1..c7bbdf4 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/Log.txt +++ b/AirPlaneWithRadar/AirPlaneWithRadar/Log.txt @@ -37,3 +37,61 @@ 2022-12-02 19:35:15.398 +03:00 [WRN] Неизвестная ошибка при удалении самолета на карту 1234 : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') 2022-12-02 19:35:20.416 +03:00 [INF] С карты 1234 был удален самолет 2022-12-02 19:35:24.176 +03:00 [WRN] Неизвестная ошибка при удалении самолета на карту 1234 : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') +2022-12-02 20:58:51.450 +03:00 [INF] Переключение на карту 0 +2022-12-02 20:58:51.469 +03:00 [INF] Была проведена загрузка из файла C:\Users\Вова\Documents\test2.txt +2022-12-02 20:58:52.939 +03:00 [INF] Переключение на карту 2 +2022-12-02 20:58:53.435 +03:00 [INF] Переключение на карту 123 +2022-12-02 20:58:53.906 +03:00 [INF] Переключение на карту 2 +2022-12-02 20:59:11.008 +03:00 [INF] На карту 2 добавлен новый самолет +2022-12-02 20:59:17.699 +03:00 [INF] На карту 2 добавлен новый самолет +2022-12-02 21:02:18.006 +03:00 [INF] Переключение на карту 1 +2022-12-02 21:02:18.017 +03:00 [INF] Добавлена карта: 1 +2022-12-02 21:02:23.228 +03:00 [INF] На карту 1 добавлен новый самолет +2022-12-02 21:02:29.188 +03:00 [INF] На карту 1 добавлен новый самолет +2022-12-02 21:02:41.779 +03:00 [INF] На карту 1 добавлен новый самолет +2022-12-02 21:04:40.932 +03:00 [INF] Переключение на карту 12 +2022-12-02 21:04:40.942 +03:00 [INF] Добавлена карта: 12 +2022-12-02 21:04:47.181 +03:00 [INF] На карту 12 добавлен новый самолет +2022-12-02 21:04:51.926 +03:00 [INF] На карту 12 добавлен новый самолет +2022-12-02 21:06:03.473 +03:00 [INF] Переключение на карту 12 +2022-12-02 21:06:03.483 +03:00 [INF] Добавлена карта: 12 +2022-12-02 21:06:11.530 +03:00 [INF] На карту 12 добавлен новый самолет +2022-12-02 21:08:09.171 +03:00 [INF] Переключение на карту 12 +2022-12-02 21:08:09.180 +03:00 [INF] Добавлена карта: 12 +2022-12-02 21:09:01.146 +03:00 [INF] На карту 12 добавлен новый самолет +2022-12-02 21:10:09.720 +03:00 [INF] Переключение на карту 12 +2022-12-02 21:10:09.734 +03:00 [INF] Добавлена карта: 12 +2022-12-02 21:10:19.563 +03:00 [INF] На карту 12 добавлен новый самолет +2022-12-02 21:10:27.721 +03:00 [INF] Добавление самолета на карту 12 прошло неудачно +2022-12-02 21:10:36.916 +03:00 [INF] Переключение на карту 0 +2022-12-02 21:10:36.917 +03:00 [INF] Была проведена загрузка из файла C:\Users\Вова\Documents\test.txt +2022-12-02 21:10:37.991 +03:00 [INF] Переключение на карту 123 +2022-12-02 21:10:38.462 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:10:54.307 +03:00 [INF] На карту 2 добавлен новый самолет +2022-12-02 21:11:04.627 +03:00 [INF] На карту 2 добавлен новый самолет +2022-12-02 21:11:11.001 +03:00 [INF] Добавление самолета на карту 2 прошло неудачно +2022-12-02 21:11:30.530 +03:00 [INF] На карту 2 добавлен новый самолет +2022-12-02 21:11:42.503 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:42.503 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:43.232 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:43.232 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:43.412 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:43.412 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:45.214 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:45.214 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:47.256 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:47.256 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:47.612 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:47.612 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:47.780 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:47.780 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:11:47.996 +03:00 [INF] Переключение на карту 2 +2022-12-02 21:11:47.996 +03:00 [INF] Добавлена карта: 2 +2022-12-02 21:22:56.692 +03:00 [INF] Переключение на карту 123 +2022-12-02 21:22:56.708 +03:00 [INF] Добавлена карта: 123 +2022-12-02 21:23:01.316 +03:00 [INF] На карту 123 добавлен новый самолет +2022-12-02 21:23:05.600 +03:00 [INF] Добавление самолета на карту 123 прошло неудачно +2022-12-02 21:23:09.917 +03:00 [INF] На карту 123 добавлен новый самолет +2022-12-02 21:23:19.050 +03:00 [INF] На карту 123 добавлен новый самолет +2022-12-02 21:23:30.002 +03:00 [INF] На карту 123 добавлен новый самолет +2022-12-02 21:23:34.691 +03:00 [INF] На карту 123 добавлен новый самолет diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs b/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs index 218a4a6..d0d885c 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs @@ -10,7 +10,43 @@ namespace AirPlaneWithRadar { public int Compare(IDrawingObject? x, IDrawingObject? y) { - throw new NotImplementedException(); + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xPlain = x as DrawingObjectPlane; + var yPlain = y as DrawingObjectPlane; + if (xPlain == null && yPlain == null) + { + return 0; + } + if (xPlain == null && yPlain != null) + { + return 1; + } + if (xPlain != null && yPlain == null) + { + return -1; + } + int res = string.Compare(xPlain.GetPlane.Plain.BodyColor.Name, yPlain.GetPlane.Plain.BodyColor.Name); + if (res != 0) + { + return res; + } + var speedCompare = xPlain.GetPlane.Plain.Speed.CompareTo(yPlain.GetPlane.Plain.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xPlain.GetPlane.Plain.Weight.CompareTo(yPlain.GetPlane.Plain.Weight); } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index f96b2b7..7b37d9b 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -20,13 +20,13 @@ namespace AirPlaneWithRadar } public int Insert(T plain) { - + if (_places.Contains(plain)) { return -1; } Insert(plain, 0); return _places.Count; } public int Insert(T plain, int position) { - ///// + if (_places.Count == _maxCount) { throw new StorageOverFullException(_maxCount); -- 2.25.1