From e27ebecf0ebb0c8a5a4c0f5e3f221bcc6e186349 Mon Sep 17 00:00:00 2001
From: prodigygirl <Prodigygirl1.0@yandex.ru>
Date: Wed, 30 Nov 2022 17:36:00 +0400
Subject: [PATCH 1/5] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?=
 =?UTF-8?q?=D1=88=D0=B0=D0=B3:=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?=
 =?UTF-8?q?=D0=BA=D0=B0=20=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD?=
 =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?=
 =?UTF-8?q?=D0=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs | 52 ++++++++++++++++++-
 ArmoredCar/ArmoredCar/IDrawningObject.cs      |  2 +-
 .../MapWithSetArmoredCarsGeneric.cs           |  2 +-
 .../ArmoredCar/SetArmoredCarsGeneric.cs       | 10 +++-
 4 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs b/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs
index 22effca..87f94bf 100644
--- a/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs
+++ b/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.DirectoryServices.ActiveDirectory;
 using System.Drawing;
 using System.Linq;
 using System.Text;
@@ -34,7 +35,54 @@ namespace ArmoredCar
                 _armCar.DrawTransport(g);
         }
         public string GetInfo() => _armCar?.GetDataForSave();
-        public static IDrawningObject Create(string data) => new
-       DrawningObjectArmCar(data.CreateDrawningArmoredCar());
+        public static IDrawningObject Create(string data) => new DrawningObjectArmCar(data.CreateDrawningArmoredCar());
+
+        public bool Equals(IDrawningObject? other)
+        {
+            if (other == null)
+            {
+                return false;
+            }
+            var otherCar = other as DrawningObjectArmCar;
+            if (otherCar == null)
+            {
+                return false;
+            }
+            var car = _armCar.ArmoredCar;
+            var otherCarCar = otherCar._armCar.ArmoredCar;
+
+            if (car.GetType() != otherCarCar.GetType())
+                return false;
+
+            if (car.Speed != otherCarCar.Speed)
+            {
+                return false;
+            }
+            if (car.Weight != otherCarCar.Weight)
+            {
+                return false;
+            }
+            if (car.BodyColor != otherCarCar.BodyColor)
+            {
+                return false;
+            }
+            if (car is EntityTank tank && otherCarCar is EntityTank otherTank)
+            {
+                if (tank.DopColor != otherTank.DopColor)
+                {
+                    return false;
+                }
+                if (tank.TowerWeapon != otherTank.TowerWeapon)
+                {
+                    return false;
+                }
+                if (tank.AMachineGun != otherTank.AMachineGun)
+                {
+                    return false;
+                }
+            }        
+            return true;
+        }
+
     }
 }
diff --git a/ArmoredCar/ArmoredCar/IDrawningObject.cs b/ArmoredCar/ArmoredCar/IDrawningObject.cs
index 4e97bfa..d7ae519 100644
--- a/ArmoredCar/ArmoredCar/IDrawningObject.cs
+++ b/ArmoredCar/ArmoredCar/IDrawningObject.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 namespace ArmoredCar
 {
-    internal interface IDrawningObject
+    internal interface IDrawningObject : IEquatable<IDrawningObject>
     {
         /// <summary>
         /// Шаг перемещения объекта
diff --git a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
index e4a7e64..db64685 100644
--- a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
+++ b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
 namespace ArmoredCar
 {
     internal class MapWithSetArmoredCarsGeneric<T, U>
-        where T : class, IDrawningObject
+        where T : class, IDrawningObject, IEquatable<T>
         where U : AbstractMap
     {
         /// <summary>
diff --git a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
index 6d63325..1aef614 100644
--- a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
+++ b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 namespace ArmoredCar
 {
     internal class SetArmoredCarsGeneric<T>
-        where T : class
+        where T : class, IEquatable<T>
     {
         /// <summary>
         /// Список объектов, которые храним
@@ -43,13 +43,19 @@ namespace ArmoredCar
         /// <param name="position">Позиция</param>
         /// <returns></returns>
         public int Insert(T armoredCar, int position)
-        {
+        {                
             if (Count >= _maxCount)
                 throw new StorageOverflowException(Count);
 
             if (position < 0 || position >= _maxCount)
                 return -1;
 
+            // проверка на уникальность
+            if (_places.Contains(armoredCar))
+            {
+                return -1;
+            }
+
             _places.Insert(position, armoredCar);         
             return position;
         }
-- 
2.25.1


From bd3d96264e7366525b8ef9538d2bf1f30284a880 Mon Sep 17 00:00:00 2001
From: prodigygirl <Prodigygirl1.0@yandex.ru>
Date: Wed, 30 Nov 2022 18:03:40 +0400
Subject: [PATCH 2/5] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?=
 =?UTF-8?q?=D1=88=D0=B0=D0=B3:=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80?=
 =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?=
 =?UTF-8?q?=D0=BE=D0=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../ArmoredCar/ArmoredCarCompareByColor.cs    | 64 +++++++++++++++++++
 .../ArmoredCar/ArmoredCarCompareByType.cs     | 55 ++++++++++++++++
 ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs |  2 +
 .../MapWithSetArmoredCarsGeneric.cs           |  9 +++
 .../ArmoredCar/SetArmoredCarsGeneric.cs       | 12 ++++
 5 files changed, 142 insertions(+)
 create mode 100644 ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs
 create mode 100644 ArmoredCar/ArmoredCar/ArmoredCarCompareByType.cs

diff --git a/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs b/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs
new file mode 100644
index 0000000..d85bec5
--- /dev/null
+++ b/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ArmoredCar
+{
+    internal class ArmoredCarCompareByColor : IComparer<IDrawningObject>
+    {
+        public int Compare(IDrawningObject x, IDrawningObject y)
+        {
+            if (x == null && y == null)
+            {
+                return 0;
+            }
+            if (x == null && y != null)
+            {
+                return 1;
+            }
+            if (x != null && y == null)
+            {
+                return -1;
+            }
+            var xCar = x as DrawningObjectArmCar;
+            var yCar = y as DrawningObjectArmCar;
+            if (xCar == null && yCar == null)
+            {
+                return 0;
+            }
+            if (xCar == null && yCar != null)
+            {
+                return 1;
+            }
+            if (xCar != null && yCar == null)
+            {
+                return -1;
+            }
+            string xCarColor = xCar.GetArmoredCar.ArmoredCar.BodyColor.Name;
+            string yCarColor = yCar.GetArmoredCar.ArmoredCar.BodyColor.Name;
+            if (xCarColor != yCarColor)
+            {             
+                return xCarColor.CompareTo(yCarColor);
+            }
+
+            if (xCar.GetArmoredCar.ArmoredCar is EntityTank xTank && yCar.GetArmoredCar.ArmoredCar is EntityTank yTank) 
+            {
+                string xCarDopColor = xTank.DopColor.Name;
+                string yCarDopColor = yTank.DopColor.Name;
+                if (xCarDopColor != yCarDopColor)
+                {
+                    return xCarColor.CompareTo(yCarColor);
+                }
+            }
+
+            var speedCompare = xCar.GetArmoredCar.ArmoredCar.Speed.CompareTo(yCar.GetArmoredCar.ArmoredCar.Speed);
+            if (speedCompare != 0)
+            {
+                return speedCompare;
+            }
+            return xCar.GetArmoredCar.ArmoredCar.Weight.CompareTo(yCar.GetArmoredCar.ArmoredCar.Weight);
+        }
+    }
+}
diff --git a/ArmoredCar/ArmoredCar/ArmoredCarCompareByType.cs b/ArmoredCar/ArmoredCar/ArmoredCarCompareByType.cs
new file mode 100644
index 0000000..a02d251
--- /dev/null
+++ b/ArmoredCar/ArmoredCar/ArmoredCarCompareByType.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ArmoredCar
+{
+    internal class ArmoredCarCompareByType : IComparer<IDrawningObject>
+    {
+        public int Compare(IDrawningObject x, IDrawningObject y)
+        {
+            if (x == null && y == null)
+            {
+                return 0;
+            }
+            if (x == null && y != null)
+            {
+                return 1;
+            }
+            if (x != null && y == null)
+            {
+                return -1;
+            }
+            var xCar = x as DrawningObjectArmCar;
+            var yCar = y as DrawningObjectArmCar;
+            if (xCar == null && yCar == null)
+            {
+                return 0;
+            }
+            if (xCar == null && yCar != null)
+            {
+                return 1;
+            }
+            if (xCar != null && yCar == null)
+            {
+                return -1;
+            }
+            if (xCar.GetArmoredCar.GetType().Name != yCar.GetArmoredCar.GetType().Name)
+            {
+                if (xCar.GetArmoredCar.GetType().Name == "DrawningArmoredCar")
+                {
+                    return -1;
+                }
+                return 1;
+            }
+            var speedCompare = xCar.GetArmoredCar.ArmoredCar.Speed.CompareTo(yCar.GetArmoredCar.ArmoredCar.Speed);
+            if (speedCompare != 0)
+            {
+                return speedCompare;
+            }
+            return xCar.GetArmoredCar.ArmoredCar.Weight.CompareTo(yCar.GetArmoredCar.ArmoredCar.Weight);
+        }
+    }
+}
diff --git a/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs b/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs
index 87f94bf..8b14e12 100644
--- a/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs
+++ b/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs
@@ -11,6 +11,8 @@ namespace ArmoredCar
     internal class DrawningObjectArmCar : IDrawningObject
     {
         private DrawningArmoredCar _armCar = null;
+
+        public DrawningArmoredCar GetArmoredCar => _armCar;
         public DrawningObjectArmCar(DrawningArmoredCar car)
         {
             _armCar = car;
diff --git a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
index db64685..184d333 100644
--- a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
+++ b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
@@ -206,5 +206,14 @@ namespace ArmoredCar
                 _setCars.Insert(DrawningObjectArmCar.Create(rec) as T);
             }
         }
+
+        /// <summary>
+        /// Сортировка
+        /// </summary>
+        /// <param name="comparer"></param>
+        public void Sort(IComparer<T> comparer)
+        {
+            _setCars.SortSet(comparer);
+        }
     }
 }
diff --git a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
index 1aef614..3fa6226 100644
--- a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
+++ b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
@@ -114,6 +114,18 @@ namespace ArmoredCar
                 }
             }
         }
+        /// <summary>
+        /// Сортировка набора объектов
+        /// </summary>
+        /// <param name="comparer"></param>
+        public void SortSet(IComparer<T> comparer)
+        {
+            if (comparer == null)
+            {
+                return;
+            }
+            _places.Sort(comparer);
+        }
 
     }
 }
-- 
2.25.1


From 74f2ec51e4e48cd7052600afd18b7b14fbf317c4 Mon Sep 17 00:00:00 2001
From: prodigygirl <Prodigygirl1.0@yandex.ru>
Date: Wed, 30 Nov 2022 18:12:19 +0400
Subject: [PATCH 3/5] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?=
 =?UTF-8?q?=D1=88=D0=B0=D0=B3:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?=
 =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../FormMapWithSetArmoredCars.Designer.cs     | 54 ++++++++++++++-----
 .../ArmoredCar/FormMapWithSetArmoredCars.cs   | 19 +++++++
 2 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs
index 0cd41b5..8752fdf 100644
--- a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs
+++ b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs
@@ -31,6 +31,8 @@ namespace ArmoredCar
         private void InitializeComponent()
         {
             this.groupBoxTools = new System.Windows.Forms.GroupBox();
+            this.ButtonSortByType = new System.Windows.Forms.Button();
+            this.ButtonSortByColor = new System.Windows.Forms.Button();
             this.groupBoxMaps = new System.Windows.Forms.GroupBox();
             this.buttonAddMap = new System.Windows.Forms.Button();
             this.buttonDeleteMap = new System.Windows.Forms.Button();
@@ -61,6 +63,8 @@ namespace ArmoredCar
             // 
             // 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.buttonRemoveCar);
@@ -72,13 +76,33 @@ namespace ArmoredCar
             this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
             this.groupBoxTools.Controls.Add(this.buttonAddCar);
             this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
-            this.groupBoxTools.Location = new System.Drawing.Point(802, 24);
+            this.groupBoxTools.Location = new System.Drawing.Point(798, 24);
             this.groupBoxTools.Name = "groupBoxTools";
-            this.groupBoxTools.Size = new System.Drawing.Size(204, 637);
+            this.groupBoxTools.Size = new System.Drawing.Size(204, 639);
             this.groupBoxTools.TabIndex = 0;
             this.groupBoxTools.TabStop = false;
             this.groupBoxTools.Text = "Инструменты";
             // 
+            // ButtonSortByType
+            // 
+            this.ButtonSortByType.Location = new System.Drawing.Point(17, 269);
+            this.ButtonSortByType.Name = "ButtonSortByType";
+            this.ButtonSortByType.Size = new System.Drawing.Size(175, 35);
+            this.ButtonSortByType.TabIndex = 13;
+            this.ButtonSortByType.Text = "Сортировать по типу";
+            this.ButtonSortByType.UseVisualStyleBackColor = true;
+            this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
+            // 
+            // ButtonSortByColor
+            // 
+            this.ButtonSortByColor.Location = new System.Drawing.Point(17, 311);
+            this.ButtonSortByColor.Name = "ButtonSortByColor";
+            this.ButtonSortByColor.Size = new System.Drawing.Size(175, 35);
+            this.ButtonSortByColor.TabIndex = 12;
+            this.ButtonSortByColor.Text = "Сортировать по цвету";
+            this.ButtonSortByColor.UseVisualStyleBackColor = true;
+            this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
+            // 
             // groupBoxMaps
             // 
             this.groupBoxMaps.Controls.Add(this.buttonAddMap);
@@ -143,7 +167,7 @@ namespace ArmoredCar
             // 
             // maskedTextBoxPosition
             // 
-            this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355);
+            this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 393);
             this.maskedTextBoxPosition.Mask = "00";
             this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
             this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
@@ -152,7 +176,7 @@ namespace ArmoredCar
             // 
             // buttonRemoveCar
             // 
-            this.buttonRemoveCar.Location = new System.Drawing.Point(17, 384);
+            this.buttonRemoveCar.Location = new System.Drawing.Point(17, 422);
             this.buttonRemoveCar.Name = "buttonRemoveCar";
             this.buttonRemoveCar.Size = new System.Drawing.Size(175, 35);
             this.buttonRemoveCar.TabIndex = 3;
@@ -162,7 +186,7 @@ namespace ArmoredCar
             // 
             // buttonShowStorage
             // 
-            this.buttonShowStorage.Location = new System.Drawing.Point(17, 437);
+            this.buttonShowStorage.Location = new System.Drawing.Point(17, 475);
             this.buttonShowStorage.Name = "buttonShowStorage";
             this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
             this.buttonShowStorage.TabIndex = 4;
@@ -175,7 +199,7 @@ namespace ArmoredCar
             this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonDown.BackgroundImage = global::ArmoredCar.Properties.Resources.Down;
             this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
-            this.buttonDown.Location = new System.Drawing.Point(91, 587);
+            this.buttonDown.Location = new System.Drawing.Point(91, 603);
             this.buttonDown.Name = "buttonDown";
             this.buttonDown.Size = new System.Drawing.Size(30, 30);
             this.buttonDown.TabIndex = 10;
@@ -187,7 +211,7 @@ namespace ArmoredCar
             this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonRight.BackgroundImage = global::ArmoredCar.Properties.Resources.Right;
             this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
-            this.buttonRight.Location = new System.Drawing.Point(127, 587);
+            this.buttonRight.Location = new System.Drawing.Point(127, 603);
             this.buttonRight.Name = "buttonRight";
             this.buttonRight.Size = new System.Drawing.Size(30, 30);
             this.buttonRight.TabIndex = 9;
@@ -199,7 +223,7 @@ namespace ArmoredCar
             this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonLeft.BackgroundImage = global::ArmoredCar.Properties.Resources.Left;
             this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
-            this.buttonLeft.Location = new System.Drawing.Point(55, 587);
+            this.buttonLeft.Location = new System.Drawing.Point(55, 603);
             this.buttonLeft.Name = "buttonLeft";
             this.buttonLeft.Size = new System.Drawing.Size(30, 30);
             this.buttonLeft.TabIndex = 8;
@@ -211,7 +235,7 @@ namespace ArmoredCar
             this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonUp.BackgroundImage = global::ArmoredCar.Properties.Resources.Up;
             this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
-            this.buttonUp.Location = new System.Drawing.Point(91, 551);
+            this.buttonUp.Location = new System.Drawing.Point(91, 567);
             this.buttonUp.Name = "buttonUp";
             this.buttonUp.Size = new System.Drawing.Size(30, 30);
             this.buttonUp.TabIndex = 7;
@@ -220,7 +244,7 @@ namespace ArmoredCar
             // 
             // buttonShowOnMap
             // 
-            this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487);
+            this.buttonShowOnMap.Location = new System.Drawing.Point(17, 525);
             this.buttonShowOnMap.Name = "buttonShowOnMap";
             this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
             this.buttonShowOnMap.TabIndex = 5;
@@ -230,7 +254,7 @@ namespace ArmoredCar
             // 
             // buttonAddCar
             // 
-            this.buttonAddCar.Location = new System.Drawing.Point(17, 314);
+            this.buttonAddCar.Location = new System.Drawing.Point(17, 352);
             this.buttonAddCar.Name = "buttonAddCar";
             this.buttonAddCar.Size = new System.Drawing.Size(175, 35);
             this.buttonAddCar.TabIndex = 1;
@@ -243,7 +267,7 @@ namespace ArmoredCar
             this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
             this.pictureBox.Location = new System.Drawing.Point(0, 24);
             this.pictureBox.Name = "pictureBox";
-            this.pictureBox.Size = new System.Drawing.Size(802, 637);
+            this.pictureBox.Size = new System.Drawing.Size(798, 639);
             this.pictureBox.TabIndex = 1;
             this.pictureBox.TabStop = false;
             // 
@@ -253,7 +277,7 @@ namespace ArmoredCar
             this.FileToolStripMenuItem});
             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
             this.menuStrip1.Name = "menuStrip1";
-            this.menuStrip1.Size = new System.Drawing.Size(1006, 24);
+            this.menuStrip1.Size = new System.Drawing.Size(1002, 24);
             this.menuStrip1.TabIndex = 2;
             this.menuStrip1.Text = "menuStrip1";
             // 
@@ -292,7 +316,7 @@ namespace ArmoredCar
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1006, 661);
+            this.ClientSize = new System.Drawing.Size(1002, 663);
             this.Controls.Add(this.pictureBox);
             this.Controls.Add(this.groupBoxTools);
             this.Controls.Add(this.menuStrip1);
@@ -336,5 +360,7 @@ namespace ArmoredCar
         private ToolStripMenuItem LoadToolStripMenuItem;
         private OpenFileDialog openFileDialog;
         private SaveFileDialog saveFileDialog;
+        private Button ButtonSortByType;
+        private Button ButtonSortByColor;
     }
 }
\ No newline at end of file
diff --git a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs
index 60af64b..9af7a3c 100644
--- a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs
+++ b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs
@@ -313,5 +313,24 @@ namespace ArmoredCar
             }
         }
 
+        private void ButtonSortByType_Click(object sender, EventArgs e)
+        {
+            if (listBoxMaps.SelectedIndex == -1)
+            {
+                return;
+            }
+            _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new ArmoredCarCompareByType());
+            pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+        }
+
+        private void ButtonSortByColor_Click(object sender, EventArgs e)
+        {
+            if (listBoxMaps.SelectedIndex == -1)
+            {
+                return;
+            }
+            _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new ArmoredCarCompareByColor());
+            pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+        }
     }
 }
\ No newline at end of file
-- 
2.25.1


From 3d48cbaba7c8b533a919eb0fa8c17c1739fee758 Mon Sep 17 00:00:00 2001
From: prodigygirl <Prodigygirl1.0@yandex.ru>
Date: Wed, 30 Nov 2022 18:27:31 +0400
Subject: [PATCH 4/5] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D0=B8=D0=B9=20?=
 =?UTF-8?q?=D1=88=D0=B0=D0=B3:=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?=
 =?UTF-8?q?=D1=81=20AbstractMap?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ArmoredCar/ArmoredCar/AbstractMap.cs | 58 +++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 10 deletions(-)

diff --git a/ArmoredCar/ArmoredCar/AbstractMap.cs b/ArmoredCar/ArmoredCar/AbstractMap.cs
index 8b2f5c0..a8bab00 100644
--- a/ArmoredCar/ArmoredCar/AbstractMap.cs
+++ b/ArmoredCar/ArmoredCar/AbstractMap.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 namespace ArmoredCar
 {
-    internal abstract class AbstractMap
+    internal abstract class AbstractMap : IEquatable<AbstractMap>
     {
         private IDrawningObject _drawningObject = null;
         protected int[,] _map = null;
@@ -31,7 +31,7 @@ namespace ArmoredCar
             return DrawMapWithObject();
         }
         public Bitmap MoveObject(Direction direction)
-        {                       
+        {
             bool flag = true;
             float step = _drawningObject.Step;
             (float left, float right, float top, float bottom) = _drawningObject.GetCurrentPosition();
@@ -40,7 +40,7 @@ namespace ArmoredCar
             int y1_obj_next = (int)((top - step) / _size_y);
             int x2_obj_next = (int)((right + step) / _size_x);
             int y2_obj_next = (int)((bottom + step) / _size_y);
-   
+
             int x1_obj_current = (int)(left / _size_x);
             int y1_obj_current = (int)(top / _size_y);
             int x2_obj_current = (int)(right / _size_x);
@@ -53,7 +53,7 @@ namespace ArmoredCar
                     {
                         if (x1_obj_next < 0)
                         {
-                                flag = false;
+                            flag = false;
                         }
                         else
                         {
@@ -132,9 +132,9 @@ namespace ArmoredCar
                             }
                         }
                         break;
-                    }            
-                }
- 
+                    }
+            }
+
             if (flag)
             {
                 _drawningObject.MoveObject(direction);
@@ -151,9 +151,9 @@ namespace ArmoredCar
             int y = _random.Next(0, 10);
             _drawningObject.SetObject(x, y, _width, _height);
             (float left, float right, float top, float bottom) = _drawningObject.GetCurrentPosition();
-            for (int i = (int)(x / _size_x); i <= (int) (right / _size_x); i++)
+            for (int i = (int)(x / _size_x); i <= (int)(right / _size_x); i++)
             {
-                for (int j = (int)(y / _size_y); j <= (int) (bottom / _size_y); j++)
+                for (int j = (int)(y / _size_y); j <= (int)(bottom / _size_y); j++)
                 {
                     if (_map[i, j] == _barrier)
                     {
@@ -171,7 +171,7 @@ namespace ArmoredCar
                 return bmp;
             }
             Graphics gr = Graphics.FromImage(bmp);
-           
+
             for (int i = 0; i < _map.GetLength(0); ++i)
             {
                 for (int j = 0; j < _map.GetLength(1); ++j)
@@ -193,5 +193,43 @@ namespace ArmoredCar
         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 f6db743cbedf9dbf9e52cb73a64696b12a8e932f Mon Sep 17 00:00:00 2001
From: prodigygirl <Prodigygirl1.0@yandex.ru>
Date: Sun, 4 Dec 2022 13:06:00 +0400
Subject: [PATCH 5/5] =?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=B8=D0=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs b/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs
index d85bec5..ce3292b 100644
--- a/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs
+++ b/ArmoredCar/ArmoredCar/ArmoredCarCompareByColor.cs
@@ -49,7 +49,7 @@ namespace ArmoredCar
                 string yCarDopColor = yTank.DopColor.Name;
                 if (xCarDopColor != yCarDopColor)
                 {
-                    return xCarColor.CompareTo(yCarColor);
+                    return xCarDopColor.CompareTo(yCarDopColor);
                 }
             }
 
-- 
2.25.1