From aa766d5f54eab146ad52f55506bef67a466016c3 Mon Sep 17 00:00:00 2001
From: KirillFilippow <kirya.29@bk.ru>
Date: Wed, 6 Dec 2023 18:47:21 +0400
Subject: [PATCH] Laba04

---
 .../ContainerShip/AbstractStrategy.cs         |   3 +-
 .../ContainerGenericCollection.cs             |  47 +++--
 .../ContainerShip/ContainerGenericStorage.cs  |  87 ++++++++
 ContainerShip/ContainerShip/DrawningShip.cs   |   4 +-
 .../ContainerShip/EntityContainerShip.cs      |   4 +-
 .../FormContainerCollection.Designer.cs       | 186 +++++++++++++++++
 .../ContainerShip/FormContainerCollection.cs  | 190 ++++++++++++++++++
 ...tion.resx => FormContainerCollection.resx} |   0
 .../FormShipCollection.Designer.cs            | 121 -----------
 .../ContainerShip/FormShipCollection.cs       |  82 --------
 ContainerShip/ContainerShip/MoveToCenter.cs   |   1 -
 ContainerShip/ContainerShip/Program.cs        |   2 +-
 ContainerShip/ContainerShip/SetGeneric.cs     | 100 ++++-----
 13 files changed, 550 insertions(+), 277 deletions(-)
 create mode 100644 ContainerShip/ContainerShip/ContainerGenericStorage.cs
 create mode 100644 ContainerShip/ContainerShip/FormContainerCollection.Designer.cs
 create mode 100644 ContainerShip/ContainerShip/FormContainerCollection.cs
 rename ContainerShip/ContainerShip/{FormShipCollection.resx => FormContainerCollection.resx} (100%)
 delete mode 100644 ContainerShip/ContainerShip/FormShipCollection.Designer.cs
 delete mode 100644 ContainerShip/ContainerShip/FormShipCollection.cs

diff --git a/ContainerShip/ContainerShip/AbstractStrategy.cs b/ContainerShip/ContainerShip/AbstractStrategy.cs
index dd957ac..927a3b5 100644
--- a/ContainerShip/ContainerShip/AbstractStrategy.cs
+++ b/ContainerShip/ContainerShip/AbstractStrategy.cs
@@ -90,7 +90,8 @@ namespace ProjectContainerShip.MovementStrategy
         /// <summary>
         /// Параметры объекта
         /// </summary>
-        protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
+        protected ObjectParameters? GetObjectParameters =>
+       _moveableObject?.GetObjectPosition;
         /// <summary>
         /// Шаг объекта
         /// </summary>
diff --git a/ContainerShip/ContainerShip/ContainerGenericCollection.cs b/ContainerShip/ContainerShip/ContainerGenericCollection.cs
index 968f6df..191f18c 100644
--- a/ContainerShip/ContainerShip/ContainerGenericCollection.cs
+++ b/ContainerShip/ContainerShip/ContainerGenericCollection.cs
@@ -57,13 +57,14 @@ namespace ProjectContainerShip.Generics
         /// <param name="collect"></param>
         /// <param name="obj"></param>
         /// <returns></returns>
-        public static int? operator +(ContainerGenericCollection<T, U> collect, T? obj)
+        public static bool operator +(ContainerGenericCollection<T, U> collect, T?
+        obj)
         {
             if (obj == null)
             {
-                return -1;
+                return false;
             }
-            return collect?._collection.Insert(obj);
+            return collect?._collection.Insert(obj) ?? false;
         }
         /// <summary>
         /// Перегрузка оператора вычитания
@@ -71,16 +72,14 @@ namespace ProjectContainerShip.Generics
         /// <param name="collect"></param>
         /// <param name="pos"></param>
         /// <returns></returns>
-        public static bool operator -(ContainerGenericCollection<T, U> collect, int
-        pos)
+        public static T? operator -(ContainerGenericCollection<T, U> collect, int pos)
         {
-            T? obj = collect._collection.Get(pos);
-            if (obj is not null)
+            T? obj = collect._collection[pos];
+            if (obj != null)
             {
                 collect._collection.Remove(pos);
-                return true;
             }
-            return false;
+            return obj;
         }
         /// <summary>
         /// Получение объекта IMoveableObject
@@ -89,7 +88,7 @@ namespace ProjectContainerShip.Generics
         /// <returns></returns>
         public U? GetU(int pos)
         {
-            return (U?)_collection.Get(pos)?.GetObjectPosition;
+            return (U?)_collection[pos]?.GetMoveableObject;
         }
         /// <summary>
         /// Вывод всего набора объектов
@@ -112,7 +111,8 @@ namespace ProjectContainerShip.Generics
             Pen pen = new(Color.Black, 2);
             for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
             {
-                for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+                for (int j = 0; j < _pictureHeight / _placeSizeHeight +
+                1; ++j)
                 {
                     g.DrawLine(pen, i * _placeSizeWidth, j *
                     _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth , j *
@@ -126,21 +126,26 @@ namespace ProjectContainerShip.Generics
         /// Метод прорисовки объектов
         /// </summary>
         /// <param name="g"></param>
+        /// 
         private void DrawObjects(Graphics g)
         {
             int width = _pictureWidth / _placeSizeWidth;
             int height = _pictureHeight / _placeSizeHeight;
             for (int i = 0; i < _collection.Count; i++)
-            {
-                DrawningShip? ship = _collection.Get(i);
-                if (ship == null)
-                    continue;
-                int row = height - 1 - (i / width);
-                int col = width - 1 - (i % width);
-                ship.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight + 25 );
-                ship.DrawTransport(g);
-            }
-        }
+                foreach (var contShip in _collection.GetShip())
+                {
+                if (contShip != null)
+                {
+                        T? ship = _collection[i];
+                        if (ship == null)
+                            continue;
+                        int row = height - 1 - (i / width);
+                        int col = width - 1 - (i % width); 
+                        ship.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight + 25);
+                        ship.DrawTransport(g);
+                }
+                }
+        }  
     }
 }
 
diff --git a/ContainerShip/ContainerShip/ContainerGenericStorage.cs b/ContainerShip/ContainerShip/ContainerGenericStorage.cs
new file mode 100644
index 0000000..3a77585
--- /dev/null
+++ b/ContainerShip/ContainerShip/ContainerGenericStorage.cs
@@ -0,0 +1,87 @@
+using ProjectContainerShip.DrawningObjects;
+using ProjectContainerShip.Generics;
+using ProjectContainerShip.MovementStrategy;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectContainerShip
+{
+    /// <summary>
+    /// Класс для хранения коллекции
+    /// </summary>
+    internal class ContainerGenericStorage
+    {
+        /// <summary>
+        /// Словарь (хранилище)
+        /// </summary>
+        readonly Dictionary<string, ContainerGenericCollection<DrawningShip,
+        DrawningObjectShip>> _shipStorages;
+        /// <summary>
+        /// Возвращение списка названий наборов
+        /// </summary>
+        public List<string> Keys => _shipStorages.Keys.ToList();
+        /// <summary>
+        /// Ширина окна отрисовки
+        /// </summary>
+        private readonly int _pictureWidth;
+        /// <summary>
+        /// Высота окна отрисовки
+        /// </summary>
+        private readonly int _pictureHeight;
+        /// <summary>
+        /// Конструктор
+        /// </summary>
+        /// <param name="pictureWidth"></param>
+        /// <param name="pictureHeight"></param>
+        public ContainerGenericStorage(int pictureWidth, int pictureHeight)
+        {
+            _shipStorages = new Dictionary<string,
+            ContainerGenericCollection<DrawningShip, DrawningObjectShip>>();
+            _pictureWidth = pictureWidth;
+            _pictureHeight = pictureHeight;
+        }
+        /// <summary>
+        /// Добавление набора
+        /// </summary>
+        /// <param name="name">Название набора</param>
+        public void AddSet(string name)
+        {
+            if (!_shipStorages.ContainsKey(name))
+            {
+                ContainerGenericCollection<DrawningShip, DrawningObjectShip> newSet = new ContainerGenericCollection<DrawningShip, DrawningObjectShip>(_pictureWidth, _pictureHeight);
+                _shipStorages.Add(name, newSet);
+            }
+        }
+        /// <summary>
+        /// Удаление набора
+        /// </summary>
+        /// <param name="name">Название набора</param>
+        public void DelSet(string name)
+        {
+            if (_shipStorages.ContainsKey(name))
+            {
+                _shipStorages.Remove(name);
+            }
+        }
+        /// <summary>
+        /// Доступ к набору
+        /// </summary>
+        /// <param name="ind"></param>
+        /// <returns></returns>
+        public ContainerGenericCollection<DrawningShip, DrawningObjectShip>? this[string ind]
+        {
+            get
+            {
+                if (_shipStorages.ContainsKey(ind))
+                {
+                    return _shipStorages[ind];
+                }
+                return null;
+            }
+        }
+    }
+}
+
diff --git a/ContainerShip/ContainerShip/DrawningShip.cs b/ContainerShip/ContainerShip/DrawningShip.cs
index 60bfd79..3784b27 100644
--- a/ContainerShip/ContainerShip/DrawningShip.cs
+++ b/ContainerShip/ContainerShip/DrawningShip.cs
@@ -176,11 +176,11 @@ namespace ProjectContainerShip.DrawningObjects
         /// </summary>
         /// <param name="g"></param>
         public virtual void DrawTransport(Graphics g)
-        {      
+        {           
             if (EntityShip == null)
             {
                 return;
-            }            
+            }           
             Brush bodyBrush = new SolidBrush(EntityShip.BodyColor);
             //границы корабля
             Brush brRd = new SolidBrush(Color.Red);
diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs
index e1bfc29..c29793c 100644
--- a/ContainerShip/ContainerShip/EntityContainerShip.cs
+++ b/ContainerShip/ContainerShip/EntityContainerShip.cs
@@ -28,8 +28,8 @@ namespace ProjectContainerShip.Entities
         /// <param name="weight">Вес </param>
         /// <param name="bodyColor">Основной цвет</param>
         /// <param name="additionalColor">Дополнительный цвет</param>
-        /// <param name="сrane">Признак наличия труб</param>
-        /// <param name="сontainer">Признак наличия топлива</param>
+        /// <param name="Crane">Признак наличия труб</param>
+        /// <param name="Container">Признак наличия топлива</param>
         public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed, weight, bodyColor)
         {
             AdditionalColor = additionalColor;
diff --git a/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs b/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs
new file mode 100644
index 0000000..9e579cb
--- /dev/null
+++ b/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs
@@ -0,0 +1,186 @@
+namespace ProjectContainerShip
+{
+    partial class FormContainerCollection
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            pictureBoxCollection = new PictureBox();
+            maskedTextBoxNumber = new MaskedTextBox();
+            buttonAddEx = new Button();
+            buttonRemoveEx = new Button();
+            buttonRefreshCollection = new Button();
+            groupBox1 = new GroupBox();
+            groupBox2 = new GroupBox();
+            textBoxStorageName = new TextBox();
+            buttonDelObject = new Button();
+            listBoxStorages = new ListBox();
+            buttonAddObject = new Button();
+            ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+            groupBox1.SuspendLayout();
+            groupBox2.SuspendLayout();
+            SuspendLayout();
+            // 
+            // pictureBoxCollection
+            // 
+            pictureBoxCollection.Dock = DockStyle.Fill;
+            pictureBoxCollection.Location = new Point(0, 0);
+            pictureBoxCollection.Name = "pictureBoxCollection";
+            pictureBoxCollection.Size = new Size(932, 503);
+            pictureBoxCollection.TabIndex = 0;
+            pictureBoxCollection.TabStop = false;
+            // 
+            // maskedTextBoxNumber
+            // 
+            maskedTextBoxNumber.Location = new Point(21, 326);
+            maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+            maskedTextBoxNumber.Size = new Size(95, 27);
+            maskedTextBoxNumber.TabIndex = 1;
+            // 
+            // buttonAddEx
+            // 
+            buttonAddEx.Location = new Point(21, 282);
+            buttonAddEx.Name = "buttonAddEx";
+            buttonAddEx.Size = new Size(95, 27);
+            buttonAddEx.TabIndex = 2;
+            buttonAddEx.Text = "Добавить";
+            buttonAddEx.UseVisualStyleBackColor = true;
+            buttonAddEx.Click += ButtonAddShip_Click;
+            // 
+            // buttonRemoveEx
+            // 
+            buttonRemoveEx.Location = new Point(19, 359);
+            buttonRemoveEx.Name = "buttonRemoveEx";
+            buttonRemoveEx.Size = new Size(95, 27);
+            buttonRemoveEx.TabIndex = 3;
+            buttonRemoveEx.Text = "Удалить";
+            buttonRemoveEx.UseVisualStyleBackColor = true;
+            buttonRemoveEx.Click += ButtonRemoveShip_Click;
+            // 
+            // buttonRefreshCollection
+            // 
+            buttonRefreshCollection.Location = new Point(21, 405);
+            buttonRefreshCollection.Name = "buttonRefreshCollection";
+            buttonRefreshCollection.Size = new Size(95, 27);
+            buttonRefreshCollection.TabIndex = 4;
+            buttonRefreshCollection.Text = "Обновить";
+            buttonRefreshCollection.UseVisualStyleBackColor = true;
+            buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
+            // 
+            // groupBox1
+            // 
+            groupBox1.Controls.Add(groupBox2);
+            groupBox1.Controls.Add(buttonAddEx);
+            groupBox1.Controls.Add(buttonRefreshCollection);
+            groupBox1.Controls.Add(maskedTextBoxNumber);
+            groupBox1.Controls.Add(buttonRemoveEx);
+            groupBox1.Location = new Point(812, 0);
+            groupBox1.Name = "groupBox1";
+            groupBox1.Size = new Size(120, 461);
+            groupBox1.TabIndex = 5;
+            groupBox1.TabStop = false;
+            groupBox1.Text = "Инструменты";
+            // 
+            // groupBox2
+            // 
+            groupBox2.Controls.Add(textBoxStorageName);
+            groupBox2.Controls.Add(buttonDelObject);
+            groupBox2.Controls.Add(listBoxStorages);
+            groupBox2.Controls.Add(buttonAddObject);
+            groupBox2.Location = new Point(13, 28);
+            groupBox2.Name = "groupBox2";
+            groupBox2.Size = new Size(116, 214);
+            groupBox2.TabIndex = 5;
+            groupBox2.TabStop = false;
+            groupBox2.Text = "Наборы";
+            // 
+            // textBoxStorageName
+            // 
+            textBoxStorageName.Location = new Point(8, 26);
+            textBoxStorageName.Name = "textBoxStorageName";
+            textBoxStorageName.Size = new Size(95, 27);
+            textBoxStorageName.TabIndex = 6;
+            textBoxStorageName.TextChanged += textBoxStorageName_TextChanged;
+            // 
+            // buttonDelObject
+            // 
+            buttonDelObject.Location = new Point(8, 162);
+            buttonDelObject.Name = "buttonDelObject";
+            buttonDelObject.Size = new Size(95, 27);
+            buttonDelObject.TabIndex = 8;
+            buttonDelObject.Text = "Удалить набор";
+            buttonDelObject.UseVisualStyleBackColor = true;
+            buttonDelObject.Click += ButtonDelObject_Click;
+            // 
+            // listBoxStorages
+            // 
+            listBoxStorages.FormattingEnabled = true;
+            listBoxStorages.ItemHeight = 20;
+            listBoxStorages.Location = new Point(8, 92);
+            listBoxStorages.Name = "listBoxStorages";
+            listBoxStorages.Size = new Size(95, 64);
+            listBoxStorages.TabIndex = 6;
+            listBoxStorages.Click += ListBoxObjects_SelectedIndexChanged;
+            // 
+            // buttonAddObject
+            // 
+            buttonAddObject.Location = new Point(8, 59);
+            buttonAddObject.Name = "buttonAddObject";
+            buttonAddObject.Size = new Size(95, 27);
+            buttonAddObject.TabIndex = 7;
+            buttonAddObject.Text = "Добавить набор";
+            buttonAddObject.UseVisualStyleBackColor = true;
+            buttonAddObject.Click += ButtonAddObject_Click;
+            // 
+            // FormContainerCollection
+            // 
+            ClientSize = new Size(932, 503);
+            Controls.Add(groupBox1);
+            Controls.Add(pictureBoxCollection);
+            Name = "FormContainerCollection";
+            ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+            groupBox1.ResumeLayout(false);
+            groupBox1.PerformLayout();
+            groupBox2.ResumeLayout(false);
+            groupBox2.PerformLayout();
+            ResumeLayout(false);
+        }
+
+        #endregion
+
+        private PictureBox pictureBoxCollection;
+        private MaskedTextBox maskedTextBoxNumber;
+        private Button buttonAddEx;
+        private Button buttonRemoveEx;
+        private Button buttonRefreshCollection;
+        private GroupBox groupBox1;
+        private GroupBox groupBox2;
+        private TextBox textBoxStorageName;
+        private Button buttonDelObject;
+        private ListBox listBoxStorages;
+        private Button buttonAddObject;
+    }
+}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormContainerCollection.cs b/ContainerShip/ContainerShip/FormContainerCollection.cs
new file mode 100644
index 0000000..2c61240
--- /dev/null
+++ b/ContainerShip/ContainerShip/FormContainerCollection.cs
@@ -0,0 +1,190 @@
+using ProjectContainerShip;
+using ProjectContainerShip.DrawningObjects;
+using ProjectContainerShip.Generics;
+using ProjectContainerShip.MovementStrategy;
+
+namespace ProjectContainerShip
+{
+    /// <summary>
+    /// Форма для работы с набором объектов класса DrawningShip
+    /// </summary>
+    public partial class FormContainerCollection : Form
+    {
+        /// <summary>
+        /// Набор объектов
+        /// </summary>
+        private readonly ContainerGenericStorage _storage;
+        /// <summary>
+        /// Конструктор
+        /// </summary>
+        public FormContainerCollection()
+        {
+            InitializeComponent();
+            _storage = new ContainerGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
+        }
+        /// <summary>
+        /// Заполнение listBoxObjects
+        /// </summary>
+        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;
+                var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+            string.Empty];
+                if (obj == null)
+                {
+                    return;
+                }
+                pictureBoxCollection.Image = obj.ShowContainer();
+            }
+        }
+        /// <summary>
+        /// Добавление набора в коллекцию
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        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();
+        }
+        /// <summary>
+        /// Выбор набора
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ListBoxObjects_SelectedIndexChanged(object sender,
+        EventArgs e)
+        {
+            pictureBoxCollection.Image =
+            _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowContainer();
+        }
+        /// <summary>
+        /// Удаление набора
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ButtonDelObject_Click(object sender, EventArgs e)
+        {
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
+        MessageBoxIcon.Question) == DialogResult.Yes)
+            {
+                _storage.DelSet(listBoxStorages.SelectedItem.ToString()
+                ?? string.Empty);
+                ReloadObjects();
+            }
+        }
+        /// <summary>
+        /// Добавление объекта в набор
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ButtonAddShip_Click(object sender, EventArgs e)
+        {
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+            string.Empty];
+            if (obj == null)
+            {
+                return;
+            }
+            FormContainerShip form = new();
+            if (form.ShowDialog() == DialogResult.OK)
+            {
+                if (obj + form.SelectedShip)
+                {
+                    MessageBox.Show("Объект добавлен");
+                    pictureBoxCollection.Image = obj.ShowContainer();
+                }
+                else
+                {
+                    MessageBox.Show("Не удалось добавить объект");
+                }
+            }
+        }
+        /// <summary>
+        /// Удаление объекта из набора
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ButtonRemoveShip_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 (obj - pos != null)
+            {
+                MessageBox.Show("Объект удален");
+                pictureBoxCollection.Image = obj.ShowContainer();
+            }
+            else
+            {
+                MessageBox.Show("Не удалось удалить объект");
+            }
+        }
+        /// <summary>
+        /// Обновление рисунка по набору
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+        {
+            if (listBoxStorages.SelectedIndex == -1)
+            {
+                return;
+            }
+            var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+            string.Empty];
+            if (obj == null)
+            {
+                return;
+            }
+            pictureBoxCollection.Image = obj.ShowContainer();
+        }
+        private void textBoxStorageName_TextChanged(object sender, EventArgs e)
+        {
+        }
+    }
+}
+
+
+
diff --git a/ContainerShip/ContainerShip/FormShipCollection.resx b/ContainerShip/ContainerShip/FormContainerCollection.resx
similarity index 100%
rename from ContainerShip/ContainerShip/FormShipCollection.resx
rename to ContainerShip/ContainerShip/FormContainerCollection.resx
diff --git a/ContainerShip/ContainerShip/FormShipCollection.Designer.cs b/ContainerShip/ContainerShip/FormShipCollection.Designer.cs
deleted file mode 100644
index 1e8dcd5..0000000
--- a/ContainerShip/ContainerShip/FormShipCollection.Designer.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-namespace ProjectContainerShip
-{
-    partial class FormShipCollection
-    {
-        /// <summary>
-        /// Required designer variable.
-        /// </summary>
-        private System.ComponentModel.IContainer components = null;
-
-        /// <summary>
-        /// Clean up any resources being used.
-        /// </summary>
-        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing && (components != null))
-            {
-                components.Dispose();
-            }
-            base.Dispose(disposing);
-        }
-
-        #region Windows Form Designer generated code
-
-        /// <summary>
-        /// Required method for Designer support - do not modify
-        /// the contents of this method with the code editor.
-        /// </summary>
-        private void InitializeComponent()
-        {
-            pictureBoxCollection = new PictureBox();
-            maskedTextBoxNumber = new MaskedTextBox();
-            buttonAddShip = new Button();
-            buttonRemoveShip = new Button();
-            buttonRefreshCollection = new Button();
-            groupBox1 = new GroupBox();
-            ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
-            groupBox1.SuspendLayout();
-            SuspendLayout();
-            // 
-            // pictureBoxCollection
-            // 
-            pictureBoxCollection.Dock = DockStyle.Fill;
-            pictureBoxCollection.Location = new Point(0, 0);
-            pictureBoxCollection.Name = "pictureBoxCollection";
-            pictureBoxCollection.Size = new Size(932, 503);
-            pictureBoxCollection.TabIndex = 0;
-            pictureBoxCollection.TabStop = false;
-            // 
-            // maskedTextBoxNumber
-            // 
-            maskedTextBoxNumber.Location = new Point(6, 120);
-            maskedTextBoxNumber.Name = "maskedTextBoxNumber";
-            maskedTextBoxNumber.Size = new Size(108, 27);
-            maskedTextBoxNumber.TabIndex = 1;
-            // 
-            // buttonAddShip
-            // 
-            buttonAddShip.Location = new Point(6, 57);
-            buttonAddShip.Name = "buttonAddShip";
-            buttonAddShip.Size = new Size(108, 30);
-            buttonAddShip.TabIndex = 2;
-            buttonAddShip.Text = "Добавить ";
-            buttonAddShip.UseVisualStyleBackColor = true;
-            buttonAddShip.Click += ButtonAddShip_Click;
-            // 
-            // buttonRemoveShip
-            // 
-            buttonRemoveShip.Location = new Point(6, 166);
-            buttonRemoveShip.Name = "buttonRemoveShip";
-            buttonRemoveShip.Size = new Size(108, 30);
-            buttonRemoveShip.TabIndex = 3;
-            buttonRemoveShip.Text = "Удалить ";
-            buttonRemoveShip.UseVisualStyleBackColor = true;
-            buttonRemoveShip.Click += ButtonRemoveShip_Click;
-            // 
-            // buttonRefreshCollection
-            // 
-            buttonRefreshCollection.Location = new Point(6, 230);
-            buttonRefreshCollection.Name = "buttonRefreshCollection";
-            buttonRefreshCollection.Size = new Size(108, 30);
-            buttonRefreshCollection.TabIndex = 4;
-            buttonRefreshCollection.Text = "Обновить ";
-            buttonRefreshCollection.UseVisualStyleBackColor = true;
-            buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
-            // 
-            // groupBox1
-            // 
-            groupBox1.Controls.Add(buttonAddShip);
-            groupBox1.Controls.Add(buttonRefreshCollection);
-            groupBox1.Controls.Add(maskedTextBoxNumber);
-            groupBox1.Controls.Add(buttonRemoveShip);
-            groupBox1.Location = new Point(812, 21);
-            groupBox1.Name = "groupBox1";
-            groupBox1.Size = new Size(120, 461);
-            groupBox1.TabIndex = 5;
-            groupBox1.TabStop = false;
-            groupBox1.Text = "Инструменты";
-            // 
-            // FormShipCollection
-            // 
-            ClientSize = new Size(932, 503);
-            Controls.Add(groupBox1);
-            Controls.Add(pictureBoxCollection);
-            Name = "FormShipCollection";
-            ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
-            groupBox1.ResumeLayout(false);
-            groupBox1.PerformLayout();
-            ResumeLayout(false);
-        }
-
-        #endregion
-
-        private PictureBox pictureBoxCollection;
-        private MaskedTextBox maskedTextBoxNumber;
-        private Button buttonAddShip;
-        private Button buttonRemoveShip;
-        private Button buttonRefreshCollection;
-        private GroupBox groupBox1;
-    }
-}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormShipCollection.cs b/ContainerShip/ContainerShip/FormShipCollection.cs
deleted file mode 100644
index 744252c..0000000
--- a/ContainerShip/ContainerShip/FormShipCollection.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using ProjectContainerShip.DrawningObjects;
-using ProjectContainerShip.Generics;
-using ProjectContainerShip.MovementStrategy;
-
-namespace ProjectContainerShip
-{
-    /// <summary>
-    /// Форма для работы с набором объектов класса 
-    /// </summary>
-    public partial class FormShipCollection : Form
-    {
-        /// <summary>
-        /// Набор объектов
-        /// </summary>
-        private readonly ContainerGenericCollection<DrawningShip,
-        DrawningObjectShip> _containerShip;
-        /// <summary>
-        /// Конструктор
-        /// </summary>
-        public FormShipCollection()
-        {
-            InitializeComponent();
-            _containerShip = new ContainerGenericCollection<DrawningShip,
-        DrawningObjectShip>(pictureBoxCollection.Width, pictureBoxCollection.Height);
-        }
-        /// <summary>
-        /// Добавление объекта в набор
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void ButtonAddShip_Click(object sender, EventArgs e)
-        {
-            FormContainerShip form = new();
-            if (form.ShowDialog() == DialogResult.OK)
-            {
-                if (_containerShip + form.SelectedShip > -1)
-                {
-                    MessageBox.Show("Объект добавлен");
-                    pictureBoxCollection.Image = _containerShip.ShowContainer();
-                }
-                else
-                {
-                    MessageBox.Show("Не удалось добавить объект");
-                }
-            }
-        }
-        /// <summary>
-        /// Удаление объекта из набора
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void ButtonRemoveShip_Click(object sender, EventArgs e)
-        {
-            if (MessageBox.Show("Удалить объект?", "Удаление",
-            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
-            {
-                return;
-            }
-            int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
-            if (_containerShip - pos != null)
-            {
-                MessageBox.Show("Объект удален");
-                pictureBoxCollection.Image = _containerShip.ShowContainer();
-            }
-            else
-            {
-                MessageBox.Show("Не удалось удалить объект");
-            }
-        }
-        /// <summary>
-        /// Обновление рисунка по набору
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void ButtonRefreshCollection_Click(object sender, EventArgs e)
-        {
-            pictureBoxCollection.Image = _containerShip.ShowContainer();
-        }
-    }
-}
-
-
diff --git a/ContainerShip/ContainerShip/MoveToCenter.cs b/ContainerShip/ContainerShip/MoveToCenter.cs
index 2d0c83f..e61f5e5 100644
--- a/ContainerShip/ContainerShip/MoveToCenter.cs
+++ b/ContainerShip/ContainerShip/MoveToCenter.cs
@@ -59,4 +59,3 @@ namespace ProjectContainerShip.MovementStrategy
 }
 
 
-
diff --git a/ContainerShip/ContainerShip/Program.cs b/ContainerShip/ContainerShip/Program.cs
index a57705c..7bf5e39 100644
--- a/ContainerShip/ContainerShip/Program.cs
+++ b/ContainerShip/ContainerShip/Program.cs
@@ -13,7 +13,7 @@ namespace ProjectContainerShip
             // To customize application configuration such as set high DPI settings or default font,
             // see https://aka.ms/applicationconfiguration.
             ApplicationConfiguration.Initialize();
-            Application.Run(new FormShipCollection());
+            Application.Run(new FormContainerCollection());
 
         }
     }
diff --git a/ContainerShip/ContainerShip/SetGeneric.cs b/ContainerShip/ContainerShip/SetGeneric.cs
index 9b636f0..afdd0f3 100644
--- a/ContainerShip/ContainerShip/SetGeneric.cs
+++ b/ContainerShip/ContainerShip/SetGeneric.cs
@@ -14,64 +14,39 @@ namespace ProjectContainerShip.Generics
     where T : class
     {
         /// <summary>
-        /// Массив объектов, которые храним
+        /// Список объектов, которые храним
         /// </summary>
-        private readonly T?[] _places;
+        private readonly List<T?> _places;
         /// <summary>
         /// Количество объектов в массиве
         /// </summary>
-        public int Count => _places.Length;
+        public int Count => _places.Count;
+        /// <summary>
+        /// Максимальное количество объектов в списке
+        /// </summary>
+        private readonly int _maxCount;
         /// <summary>
         /// Конструктор
         /// </summary>
         /// <param name="count"></param>
         public SetGeneric(int count)
         {
-            _places = new T?[count];
+            _maxCount = count;
+            _places = new List<T?>(count);
         }
         /// <summary>
         /// Добавление объекта в набор
         /// </summary>
-        /// <param name="ship">Добавляемый корабль</param>
+        /// <param name="ship">Добавляемый контейнеровоз</param>
         /// <returns></returns>
-        public int Insert(T ship)
+        public bool Insert(T ship)
         {
-            return Insert(ship, 0);
-        }
-        /// <summary>
-        /// Добавление объекта в набор на конкретную позицию
-        /// </summary>
-        /// <param name="ship">Добавляемый корабля</param>
-        /// <param name="position">Позиция</param>
-        /// <returns></returns>
-        public int Insert(T ship, int position)
-        {
-            if (position < 0 && position > Count)
+            if (_places.Count >= _maxCount)
             {
-                return -1;
+                return false;
             }
-            if (_places[position] != null)
-            {
-                int d = 0;
-                for (int j = 1; j < Count - position; j++)
-                {
-                    if (_places[position + j] == null)
-                    {
-                        d = position + j;
-                        break;
-                    }
-                }
-                if (d == 0)
-                {
-                    return -1;
-                }
-                for (int j = d; j > position; j--)
-                {
-                    _places[j] = _places[j - 1];
-                }
-            }
-            _places[position] = ship;
-            return position;
+            _places.Insert(0, ship);
+            return true;
         }
         /// <summary>
         /// Удаление объекта из набора с конкретной позиции
@@ -80,11 +55,11 @@ namespace ProjectContainerShip.Generics
         /// <returns></returns>
         public bool Remove(int position)
         {
-            if (position < 0 || position >= _places.Length)
+            if (position < 0 || position >= _places.Count)
             {
                 return false;
             }
-            _places[position] = null;
+            _places.RemoveAt(position);
             return true;
         }
         /// <summary>
@@ -92,14 +67,47 @@ namespace ProjectContainerShip.Generics
         /// </summary>
         /// <param name="position"></param>
         /// <returns></returns>
-        public T? Get(int position)
+        public T? this[int position]
         {
-            if (position < 0 || position >= _places.Length)
-                return null;
-            return _places[position];
+            get
+            {
+                if (position < 0 || position >= _places.Count)
+                {
+                    return null;
+                }
+                return _places[position];
+            }
+            set
+            {
+                if (position < 0 || position >= _places.Count)
+                {
+                    return;
+                }
+                if (_places.Count >= _maxCount)
+                {
+                    return;
+                }
+                _places.Insert(position, value);
+            }
+        }
+        /// <summary>
+        /// Проход по списку
+        /// </summary>
+        /// <returns></returns>
+        public IEnumerable<T?> GetShip(int? maxShip = null)
+        {
+            for (int i = 0; i < _places.Count; ++i)
+            {
+                yield return _places[i];
+                if (maxShip.HasValue && i == maxShip.Value)
+                {
+                    yield break;
+                }
+            }
         }
     }
 }
 
 
 
+
-- 
2.25.1