From 79f59d77432667f61cfccded3185bdf71b5bc42f Mon Sep 17 00:00:00 2001
From: DavidMakarov <davidmakarow@mail.ru>
Date: Tue, 31 Oct 2023 21:17:10 +0400
Subject: [PATCH 1/3] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=204?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../AirplaneWithRadar/AbstractStrategy.cs     |  8 +-
 .../AirplaneWithRadar/AirplaneEntity.cs       |  8 +-
 .../AirplaneWithRadarEntity.cs                |  8 +-
 .../AirplanesGenericCollection.cs             | 15 +--
 .../AirplanesGenericStorage.cs                | 37 ++++++++
 .../FormAirplaneCollection.Designer.cs        | 72 ++++++++++++++-
 .../FormAirplaneCollection.cs                 | 92 ++++++++++++++-----
 .../FormAirplaneCollection.resx               | 62 ++++++++++++-
 .../AirplaneWithRadar/GenericClass.cs         | 15 ---
 .../AirplaneWithRadar/IMoveableObject.cs      |  8 +-
 .../AirplaneWithRadar/MoveToBorder.cs         |  8 +-
 .../AirplaneWithRadar/MoveToCenter.cs         |  9 +-
 .../AirplaneWithRadar/Movement.cs             |  8 +-
 .../AirplaneWithRadar/ObjectParameters.cs     |  8 +-
 .../AirplaneWithRadar/PaintAirplane.cs        |  7 +-
 .../PaintAirplaneWithRadar.cs                 | 10 +-
 .../AirplaneWithRadar/PaintObjectAirplane.cs  |  8 +-
 .../AirplaneWithRadar/SetGeneric.cs           | 67 +++++++++-----
 AirplaneWithRadar/AirplaneWithRadar/Status.cs |  8 +-
 19 files changed, 298 insertions(+), 160 deletions(-)
 create mode 100644 AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs
 delete mode 100644 AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs

diff --git a/AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs b/AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
index cc4bbf8..e886814 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.MovementStrategy
+namespace AirplaneWithRadar.MovementStrategy
 {
     public abstract class AbstractStrategy
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
index 5446a8e..a2add34 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.Entities
+namespace AirplaneWithRadar.Entities
 {
     public class AirplaneEntity
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs
index 7b20c5b..c531730 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.Entities
+namespace AirplaneWithRadar.Entities
 {
     public class AirplaneWithRadarEntity : AirplaneEntity
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs
index 5f6614c..04f5daf 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs
@@ -1,9 +1,4 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-using AirplaneWithRadar.PaintObjects;
+using AirplaneWithRadar.PaintObjects;
 using AirplaneWithRadar.MovementStrategy;
 
 namespace AirplaneWithRadar.Generics
@@ -38,7 +33,7 @@ namespace AirplaneWithRadar.Generics
         }
         public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
         {
-            T? obj = collect.collection.Get(pos);
+            T? obj = collect.collection[pos];
             if (obj == null)
             {
                 return false;
@@ -48,7 +43,7 @@ namespace AirplaneWithRadar.Generics
 
         public U? GetU(int pos)
         {
-            return (U?)collection.Get(pos)?.GetMoveableObject;
+            return (U?)collection[pos]?.GetMoveableObject;
         }
 
         public Bitmap ShowAirplanes()
@@ -80,9 +75,7 @@ namespace AirplaneWithRadar.Generics
             int j = 3;
             int k = 0;
 
-            for (int i = 0; i < collection.Count; i++)
-            {
-                PaintAirplane? airplane = collection.Get(i);
+            foreach (var airplane in collection.GetAirplanes()) {
                 if (j < 0)
                 {
                     j += 4;
diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs
new file mode 100644
index 0000000..2eeb4b5
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs
@@ -0,0 +1,37 @@
+using AirplaneWithRadar.PaintObjects;
+using AirplaneWithRadar.MovementStrategy;
+
+namespace AirplaneWithRadar.Generics
+{
+    internal class AirplanesGenericStorage
+    {
+        readonly Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>> airplaneStorages;
+        public List<string> Keys => airplaneStorages.Keys.ToList();
+        private readonly int pictWidth;
+        private readonly int pictHeight;
+        public AirplanesGenericStorage(int pictureWidth, int pictureHeight)
+        {
+            airplaneStorages = new Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>>();
+            pictWidth = pictureWidth;
+            pictHeight = pictureHeight;
+        }
+
+        public void AddSet(string name)
+        {
+            airplaneStorages.Add(name, new AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>(pictWidth, pictHeight));
+        }
+        public void DelSet(string name)
+        {
+            airplaneStorages.Remove(name);
+        }
+        public AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>? this[string ind]
+        {
+            get
+            {
+                if (airplaneStorages.ContainsKey(ind)) return airplaneStorages[ind];
+                return null;
+            }
+        }
+    }
+
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
index 2c0f837..ca4c9ed 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
@@ -29,17 +29,24 @@
         private void InitializeComponent()
         {
             groupBox1 = new GroupBox();
+            groupBox2 = new GroupBox();
+            buttonDelObject = new Button();
+            buttonAddObject = new Button();
+            textBoxStorageName = new TextBox();
+            listBoxStorages = new ListBox();
             maskedTextBoxNumber = new TextBox();
             ButtonRefreshCollection = new Button();
             ButtonDeleteAirplane = new Button();
             ButtonAddAirplane = new Button();
             pictureBoxCollection = new PictureBox();
             groupBox1.SuspendLayout();
+            groupBox2.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
             SuspendLayout();
             // 
             // groupBox1
             // 
+            groupBox1.Controls.Add(groupBox2);
             groupBox1.Controls.Add(maskedTextBoxNumber);
             groupBox1.Controls.Add(ButtonRefreshCollection);
             groupBox1.Controls.Add(ButtonDeleteAirplane);
@@ -51,16 +58,66 @@
             groupBox1.TabStop = false;
             groupBox1.Text = "Инструменты";
             // 
+            // groupBox2
+            // 
+            groupBox2.Controls.Add(buttonDelObject);
+            groupBox2.Controls.Add(buttonAddObject);
+            groupBox2.Controls.Add(textBoxStorageName);
+            groupBox2.Controls.Add(listBoxStorages);
+            groupBox2.Location = new Point(13, 22);
+            groupBox2.Name = "groupBox2";
+            groupBox2.Size = new Size(204, 209);
+            groupBox2.TabIndex = 5;
+            groupBox2.TabStop = false;
+            groupBox2.Text = "Наборы";
+            // 
+            // buttonDelObject
+            // 
+            buttonDelObject.Location = new Point(17, 178);
+            buttonDelObject.Name = "buttonDelObject";
+            buttonDelObject.Size = new Size(170, 25);
+            buttonDelObject.TabIndex = 7;
+            buttonDelObject.Text = "Удалить набор";
+            buttonDelObject.UseVisualStyleBackColor = true;
+            buttonDelObject.Click += buttonDelObject_Click;
+            // 
+            // buttonAddObject
+            // 
+            buttonAddObject.Location = new Point(17, 51);
+            buttonAddObject.Name = "buttonAddObject";
+            buttonAddObject.Size = new Size(170, 23);
+            buttonAddObject.TabIndex = 6;
+            buttonAddObject.Text = "Добавить набор";
+            buttonAddObject.UseVisualStyleBackColor = true;
+            buttonAddObject.Click += buttonAddObject_Click;
+            // 
+            // textBoxStorageName
+            // 
+            textBoxStorageName.Location = new Point(10, 22);
+            textBoxStorageName.Name = "textBoxStorageName";
+            textBoxStorageName.Size = new Size(188, 23);
+            textBoxStorageName.TabIndex = 5;
+            // 
+            // listBoxStorages
+            // 
+            listBoxStorages.FormattingEnabled = true;
+            listBoxStorages.ItemHeight = 15;
+            listBoxStorages.Location = new Point(10, 93);
+            listBoxStorages.Name = "listBoxStorages";
+            listBoxStorages.Size = new Size(188, 79);
+            listBoxStorages.TabIndex = 4;
+            listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
+            // 
             // maskedTextBoxNumber
             // 
-            maskedTextBoxNumber.Location = new Point(39, 148);
+            maskedTextBoxNumber.Location = new Point(39, 289);
             maskedTextBoxNumber.Name = "maskedTextBoxNumber";
             maskedTextBoxNumber.Size = new Size(161, 23);
             maskedTextBoxNumber.TabIndex = 3;
             // 
             // ButtonRefreshCollection
             // 
-            ButtonRefreshCollection.Location = new Point(20, 229);
+            ButtonRefreshCollection.Location = new Point(20, 370);
             ButtonRefreshCollection.Name = "ButtonRefreshCollection";
             ButtonRefreshCollection.Size = new Size(194, 46);
             ButtonRefreshCollection.TabIndex = 2;
@@ -70,7 +127,7 @@
             // 
             // ButtonDeleteAirplane
             // 
-            ButtonDeleteAirplane.Location = new Point(20, 177);
+            ButtonDeleteAirplane.Location = new Point(20, 318);
             ButtonDeleteAirplane.Name = "ButtonDeleteAirplane";
             ButtonDeleteAirplane.Size = new Size(194, 46);
             ButtonDeleteAirplane.TabIndex = 1;
@@ -80,7 +137,7 @@
             // 
             // ButtonAddAirplane
             // 
-            ButtonAddAirplane.Location = new Point(20, 22);
+            ButtonAddAirplane.Location = new Point(23, 237);
             ButtonAddAirplane.Name = "ButtonAddAirplane";
             ButtonAddAirplane.Size = new Size(194, 46);
             ButtonAddAirplane.TabIndex = 0;
@@ -108,6 +165,8 @@
             Text = "FormAirplaneCollection";
             groupBox1.ResumeLayout(false);
             groupBox1.PerformLayout();
+            groupBox2.ResumeLayout(false);
+            groupBox2.PerformLayout();
             ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
             ResumeLayout(false);
         }
@@ -120,5 +179,10 @@
         private Button ButtonAddAirplane;
         private PictureBox pictureBoxCollection;
         private TextBox maskedTextBoxNumber;
+        private ListBox listBoxStorages;
+        private GroupBox groupBox2;
+        private Button buttonDelObject;
+        private Button buttonAddObject;
+        private TextBox textBoxStorageName;
     }
 }
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
index e5b058a..d8e5a67 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
@@ -1,69 +1,119 @@
 using AirplaneWithRadar.Generics;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using AirplaneWithRadar.PaintObjects;
-using AirplaneWithRadar.MovementStrategy;
-
 
 namespace AirplaneWithRadar
 {
     public partial class FormAirplaneCollection : Form
     {
-        private readonly AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane> airplanes;
+        private readonly AirplanesGenericStorage storage;
         public FormAirplaneCollection()
         {
             InitializeComponent();
-            airplanes = new AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
+            storage = new AirplanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
         }
 
+        private void ReloadObjects()
+        {
+            int index = listBoxStorages.SelectedIndex;
+            listBoxStorages.Items.Clear();
+            for (int i = 0; i < storage.Keys.Count; i++)
+            {
+                listBoxStorages.Items.Add(storage.Keys[i]);
+            }
+            if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
+            {
+                listBoxStorages.SelectedIndex = 0;
+            }
+            else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
+            {
+                listBoxStorages.SelectedIndex = index;
+            }
+        }
+        private void buttonAddObject_Click(object sender, EventArgs e)
+        {
+            if (string.IsNullOrEmpty(textBoxStorageName.Text))
+            {
+                MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
+            }
+            storage.AddSet(textBoxStorageName.Text);
+            ReloadObjects();
+
+        }
+
+        private void buttonDelObject_Click(object sender, EventArgs e)
+        {
+            pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
+        }
         private void ButtonAddAirplane_Click(object sender, EventArgs e)
         {
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+            if (obj == null)
+            {
+                return;
+            }
             PlaneVisual form = new();
             if (form.ShowDialog() == DialogResult.OK)
             {
-                if (airplanes + form.SelectedAirplane != -1)
+                if (!(obj + form.SelectedAirplane == -1))
                 {
                     MessageBox.Show("Объект добавлен");
-                    pictureBoxCollection.Image = airplanes.ShowAirplanes();
+                    pictureBoxCollection.Image = obj.ShowAirplanes();
                 }
                 else
                 {
                     MessageBox.Show("Не удалось добавить объект");
                 }
             }
-
         }
 
         private void ButtonDeleteAirplane_Click(object sender, EventArgs e)
         {
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+            if (obj == null)
+            {
+                return;
+            }
             if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
             {
                 return;
             }
             int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
-            if (airplanes - pos != false)
+            if (obj - pos != false)
             {
                 MessageBox.Show("Объект удален");
-                pictureBoxCollection.Image = airplanes.ShowAirplanes();
+                pictureBoxCollection.Image = obj.ShowAirplanes();
             }
             else
             {
                 MessageBox.Show("Не удалось удалить объект");
             }
-
         }
 
         private void ButtonRefreshCollection_Click(object sender, EventArgs e)
         {
-            pictureBoxCollection.Image = airplanes.ShowAirplanes();
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+            if (obj == null)
+            {
+                return;
+            }
+            pictureBoxCollection.Image = obj.ShowAirplanes();
+        }
 
+        private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
         }
     }
 }
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx
index f298a7b..a395bff 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx
@@ -1,4 +1,64 @@
-<root>
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!--
+    Microsoft ResX Schema 
+
+    Version 2.0
+
+    The primary goals of this format is to allow a simple XML format
+    that is mostly human readable. The generation and parsing of the
+    various data types are done through the TypeConverter classes
+    associated with the data types.
+
+    Example:
+
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+
+    There are any number of "resheader" rows that contain simple
+    name/value pairs.
+
+    Each data row contains a name, and value. The row also contains a
+    type or mimetype. Type corresponds to a .NET class that support
+    text/value conversion through the TypeConverter architecture.
+    Classes that don't support this are serialized and stored with the
+    mimetype set.
+
+    The mimetype is used for serialized objects, and tells the
+    ResXResourceReader how to depersist the object. This is currently not
+    extensible. For a given mimetype the value must be set accordingly:
+
+    Note - application/x-microsoft.net.object.binary.base64 is the format
+    that the ResXResourceWriter will generate, however the reader can
+    read any of the formats listed below.
+
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
   <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
     <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
     <xsd:element name="root" msdata:IsDataSet="true">
diff --git a/AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs b/AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs
deleted file mode 100644
index b6660b9..0000000
--- a/AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar
-{
-    internal class GenericClass<T>
-        where T : AirplaneWithRadar.PaintObjects.PaintAirplaneWithRadar 
-    {
-
-    }
-}
-
diff --git a/AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs b/AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
index 7a91c94..29d8857 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.MovementStrategy
+namespace AirplaneWithRadar.MovementStrategy
 {
     public interface IMoveableObject
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs b/AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
index bb71a67..1598377 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.MovementStrategy
+namespace AirplaneWithRadar.MovementStrategy
 {
     public class MoveToBorder : AbstractStrategy
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs b/AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
index f220cfb..d3f01c0 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
@@ -1,11 +1,4 @@
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.MovementStrategy
+namespace AirplaneWithRadar.MovementStrategy
 {
     public class MoveToCenter : AbstractStrategy
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/Movement.cs b/AirplaneWithRadar/AirplaneWithRadar/Movement.cs
index 797b628..9eb9585 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Movement.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Movement.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar
+namespace AirplaneWithRadar
 {
     public enum Movement
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs b/AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
index cf4c3de..01de238 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.MovementStrategy
+namespace AirplaneWithRadar.MovementStrategy
 {
     public class ObjectParameters
     {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
index e57be41..4b1d36d 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing.Drawing2D;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Drawing.Drawing2D;
 using AirplaneWithRadar.Entities;
 using AirplaneWithRadar.MovementStrategy;
 
diff --git a/AirplaneWithRadar/AirplaneWithRadar/PaintAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/PaintAirplaneWithRadar.cs
index 6bb7691..31ac10d 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/PaintAirplaneWithRadar.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/PaintAirplaneWithRadar.cs
@@ -1,12 +1,4 @@
-
-using System.Collections.Generic;
-using System.Drawing.Drawing2D;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-
-using AirplaneWithRadar.Entities;
+using AirplaneWithRadar.Entities;
 
 namespace AirplaneWithRadar.PaintObjects
 {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
index 82666cf..5322b9e 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
@@ -1,10 +1,4 @@
-using AirplaneWithRadar.MovementStrategy;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using AirplaneWithRadar.PaintObjects;
+using AirplaneWithRadar.PaintObjects;
 
 
 namespace AirplaneWithRadar.MovementStrategy
diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
index f7f03fb..4a310b5 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
@@ -1,22 +1,24 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.Generics;
+namespace AirplaneWithRadar.Generics;
 
 internal class SetGeneric<T>
     where T : class
 {
-    private readonly T?[] places;
-    public int Count => places.Length;
+    private readonly List<T?> places;
+    public int Count => places.Count;
+    public readonly int maxCount;
     public SetGeneric(int count)
     {
-        places = new T?[count];
+        maxCount = count;
+        places = new List<T?>(count);
     }
 
     public int Insert(T airplane)
     {
+        if (Count == 0)
+        {
+            places.Add(airplane);
+            return 0;
+        }
         int emptyPosition = -1;
         for (int i = 0; i < Count; i++)
         {
@@ -28,15 +30,10 @@ internal class SetGeneric<T>
         }
         if (emptyPosition < 0)
         {
-            return -1;
+            places.Add(airplane);
+            return 0;
         }
-
-        for (int i = emptyPosition; i > 0; i--)
-        {
-            places[i] = places[i - 1];
-        }
-
-        places[0] = airplane;
+        Insert(airplane, emptyPosition);
         return 0;
     }
     public int Insert(T airplane, int position)
@@ -79,15 +76,41 @@ internal class SetGeneric<T>
         {
             return false;
         }
-        places[position] = null;
+        places[position]=null;
         return true;
     }
-    public T? Get(int position)
+
+    public T? this[int position]
     {
-        if (position >= Count && position < 0)
+        get
         {
-            return null;
+            if (position >= Count || position < 0)
+            {
+                return null;
+            }
+            return places[position];
+        }
+        set
+        {
+            if (position >= Count || position < 0)
+            {
+                return;
+            }
+            if (Count <= maxCount)
+            {
+                Insert(value, position);
+            }
+        }
+    }
+    public IEnumerable<T?> GetAirplanes(int? maxAirplanes = null)
+    {
+        for (int i = 0; i < places.Count; ++i)
+        {
+            yield return places[i];
+            if (maxAirplanes.HasValue && i == maxAirplanes.Value)
+            {
+                yield break;
+            }
         }
-        return places[position];
     }
 }
diff --git a/AirplaneWithRadar/AirplaneWithRadar/Status.cs b/AirplaneWithRadar/AirplaneWithRadar/Status.cs
index 98eb831..2e5b7b7 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Status.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Status.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar.MovementStrategy
+namespace AirplaneWithRadar.MovementStrategy
 {
     public enum Status
     {
-- 
2.25.1


From fc9c663a4eb168543aad63059332cb64399698d6 Mon Sep 17 00:00:00 2001
From: DavidMakarov <davidmakarow@mail.ru>
Date: Tue, 31 Oct 2023 21:22:33 +0400
Subject: [PATCH 2/3] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20?=
 =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20=D0=BD=D0=B0=D0=B1?=
 =?UTF-8?q?=D0=BE=D1=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../FormAirplaneCollection.cs                 | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
index d8e5a67..f0335c6 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
@@ -39,10 +39,23 @@ namespace AirplaneWithRadar
             ReloadObjects();
 
         }
+        private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
+        }
 
         private void buttonDelObject_Click(object sender, EventArgs e)
         {
-            pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+{
+                storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
+                ReloadObjects();
+            }
+
         }
         private void ButtonAddAirplane_Click(object sender, EventArgs e)
         {
@@ -110,10 +123,5 @@ namespace AirplaneWithRadar
             }
             pictureBoxCollection.Image = obj.ShowAirplanes();
         }
-
-        private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
-        {
-            pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
-        }
     }
 }
-- 
2.25.1


From 4f80893e3ebdd9e389623a1a3bcd8c7beac26229 Mon Sep 17 00:00:00 2001
From: DavidMakarov <davidmakarow@mail.ru>
Date: Fri, 3 Nov 2023 21:52:36 +0400
Subject: [PATCH 3/3] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?=
 =?UTF-8?q?=20=D0=B2=20AirplanesGenericStorage.cs?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../AirplaneWithRadar/AirplanesGenericStorage.cs              | 4 +++-
 AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs
index 2eeb4b5..8a99bfb 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericStorage.cs
@@ -18,11 +18,13 @@ namespace AirplaneWithRadar.Generics
 
         public void AddSet(string name)
         {
+            if (airplaneStorages.ContainsKey(name)) { return; }
             airplaneStorages.Add(name, new AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>(pictWidth, pictHeight));
         }
         public void DelSet(string name)
         {
-            airplaneStorages.Remove(name);
+            if (airplaneStorages.ContainsKey(name))
+                airplaneStorages.Remove(name);
         }
         public AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>? this[string ind]
         {
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
index f0335c6..e590196 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
@@ -50,12 +50,11 @@ namespace AirplaneWithRadar
             {
                 return;
             }
-            if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+            if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
 {
                 storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
                 ReloadObjects();
             }
-
         }
         private void ButtonAddAirplane_Click(object sender, EventArgs e)
         {
-- 
2.25.1