From d11d028f0b65e7275da53fafe7bef99e5abf6bb8 Mon Sep 17 00:00:00 2001 From: grishazagidulin Date: Fri, 5 Apr 2024 16:43:40 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20#5=20+=20=D0=A4=D0=B8=D0=BA=D1=81=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 11 +- .../ICollectionGenericObjects.cs | 4 +- .../ListGenericObjects.cs | 12 +- .../MassiveGenericObjects.cs | 8 +- .../CollectionGenericObjects/ShipDocks.cs | 2 + .../StorageCollection.cs | 10 +- .../Battleship/Entities/EntityBattleship.cs | 11 +- Battleship/Battleship/Entities/EntityShip.cs | 14 +- .../Battleship/FormShipCollection.Designer.cs | 166 ++++---- Battleship/Battleship/FormShipCollection.cs | 105 +++--- .../Battleship/FormShipConfig.Designer.cs | 357 ++++++++++++++++++ Battleship/Battleship/FormShipConfig.cs | 156 ++++++++ Battleship/Battleship/FormShipConfig.resx | 120 ++++++ 13 files changed, 810 insertions(+), 166 deletions(-) create mode 100644 Battleship/Battleship/FormShipConfig.Designer.cs create mode 100644 Battleship/Battleship/FormShipConfig.cs create mode 100644 Battleship/Battleship/FormShipConfig.resx diff --git a/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs b/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs index d5f16d8..2adcccc 100644 --- a/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs +++ b/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs @@ -15,18 +15,22 @@ public abstract class AbstractCompany /// Размер места (ширина) /// protected readonly int _placeSizeWidth = 210; + /// /// Размер места (высота) /// protected readonly int _placeSizeHeight = 100; + /// /// Ширина окна /// protected readonly int _pictureWidth; + /// /// Высота окна /// protected readonly int _pictureHeight; + /// /// Коллекция кораблей /// @@ -67,10 +71,11 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static DrawningShip operator -(AbstractCompany company, int position) + public static DrawningShip? operator -(AbstractCompany company, int position) { return company._collection?.Remove(position); } + /// /// Получение случайного объекта из коллекции /// @@ -80,6 +85,7 @@ public abstract class AbstractCompany Random rnd = new(); return _collection?.Get(rnd.Next(GetMaxCount)); } + /// /// Вывод всей коллекции /// @@ -96,14 +102,15 @@ public abstract class AbstractCompany DrawningShip? obj = _collection?.Get(i); obj?.DrawTransport(graphics); } - return bitmap; } + /// /// Вывод заднего фона /// /// protected abstract void DrawBackground(Graphics g); + /// /// Расстановка объектов /// diff --git a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs index bd3f705..eee43c9 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -41,7 +41,7 @@ public interface ICollectionGenericObjects /// /// Позиция /// true - удачно, false - удаление не удалось - T? Remove(int position); + T Remove(int position); /// /// Получение объекта по позиции @@ -49,4 +49,4 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); -} \ No newline at end of file +} diff --git a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs index eaa1c88..1562e6f 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs @@ -14,12 +14,16 @@ public class ListGenericObjects : ICollectionGenericObjects /// Список объектов, которые храним /// private readonly List _collection; + /// /// Максимально допустимое число объектов в списке /// private int _maxCount; + public int Count => _collection.Count; + public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + /// /// Конструктор /// @@ -27,12 +31,14 @@ public class ListGenericObjects : ICollectionGenericObjects { _collection = new(); } + public T? Get(int position) { if (position < 0 || position >= _collection.Count) return null; return _collection[position]; } + public int Insert(T obj) { if (_collection.Count + 1 <= _maxCount) @@ -42,6 +48,7 @@ public class ListGenericObjects : ICollectionGenericObjects } return -1; } + public bool Insert(T obj, int position) { if (_collection.Count + 1 > _maxCount || position < 0 || position >= _collection.Count) @@ -49,11 +56,12 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.Insert(position, obj); return true; } - public T? Remove(int position) + + public T Remove(int position) { if (position < 0 || position >= _collection.Count) return null; - T? temp = _collection[position]; + T temp = _collection[position]; _collection.RemoveAt(position); return temp; } diff --git a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs index 23e085a..819afe4 100644 --- a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs @@ -98,13 +98,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects return false; } - public T? Remove(int position) + public T Remove(int position) { - if (position < 0 || position >= _collection.Length || _collection[position] == null) // проверка позиции и наличия объекта + if (position < 0 || position >= _collection.Length || _collection[position]==null) // проверка позиции и наличия объекта return null; - T? temp = _collection[position]; + T temp = _collection[position]; _collection[position] = null; return temp; } -} \ No newline at end of file +} diff --git a/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs b/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs index 3a87e6d..ed35c78 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs @@ -22,6 +22,7 @@ public class ShipDocks : AbstractCompany public ShipDocks(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } + protected override void DrawBackground(Graphics g) { Pen pen = new Pen(Color.Brown, 4); @@ -39,6 +40,7 @@ public class ShipDocks : AbstractCompany x = 0; } } + protected override void SetObjectsPosition() { int count = 0; diff --git a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs index 0f81f8f..d925bd8 100644 --- a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs +++ b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ using Battleship.CollectionGenericObjects; + namespace ProjectSportCar.CollectionGenericObjects; /// @@ -12,10 +13,12 @@ public class StorageCollection /// Словарь (хранилище) с коллекциями /// readonly Dictionary> _storages; + /// /// Возвращение списка названий коллекций /// public List Keys => _storages.Keys.ToList(); + /// /// Конструктор /// @@ -23,6 +26,7 @@ public class StorageCollection { _storages = new Dictionary>(); } + /// /// Добавление коллекции в хранилище /// @@ -44,15 +48,17 @@ public class StorageCollection break; } } + /// /// Удаление коллекции /// /// Название коллекции public void DelCollection(string name) { - if (_storages.ContainsKey(name)) + if (_storages.ContainsKey(name)) //??? спрросить, зачем проверка _storages.Remove(name); } + /// /// Доступ к коллекции /// @@ -67,4 +73,4 @@ public class StorageCollection return null; } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Battleship/Battleship/Entities/EntityBattleship.cs b/Battleship/Battleship/Entities/EntityBattleship.cs index 00f0213..09e5600 100644 --- a/Battleship/Battleship/Entities/EntityBattleship.cs +++ b/Battleship/Battleship/Entities/EntityBattleship.cs @@ -7,7 +7,7 @@ namespace Battleship.Entities; // класс-сущность "Боевой корабль" public class EntityBattleship : EntityShip { - public Color AdditionalColor; // дополнительный цвет + public Color AdditionalColor { get; private set; } // дополнительный цвет public bool Weapon { get; private set; } // оружие public bool Rockets { get; set; } // рокеты /// @@ -25,4 +25,13 @@ public class EntityBattleship : EntityShip Weapon = weapon; Rockets = rockets; } + /// + /// Метод смены цвета + /// + /// Основной цвет + /// Дополнительный цвет + public void ChangeAddColor(Color? addColor) + { + AdditionalColor = addColor ?? AdditionalColor; + } } \ No newline at end of file diff --git a/Battleship/Battleship/Entities/EntityShip.cs b/Battleship/Battleship/Entities/EntityShip.cs index 1bb5197..a7b9b2a 100644 --- a/Battleship/Battleship/Entities/EntityShip.cs +++ b/Battleship/Battleship/Entities/EntityShip.cs @@ -10,9 +10,9 @@ namespace Battleship.Entities; /// public class EntityShip { - public int Speed; // скорость - public double Weight; //вес - public Color BodyColor; /*основной цвет*/ + public int Speed { get; private set; } // скорость + public double Weight { get; private set; } //вес + public Color BodyColor { get; private set; } /*основной цвет*/ public double Step => Speed * 100 / Weight; // шаг перемещения корабля /// /// Конструктор сущности @@ -25,4 +25,12 @@ public class EntityShip Weight = weight; BodyColor = bodycolor; } + /// + /// Метод для смены цвета + /// + /// Цвет типа Color + public void ChangeColor(Color? color) + { + BodyColor = color ?? BodyColor; + } } \ No newline at end of file diff --git a/Battleship/Battleship/FormShipCollection.Designer.cs b/Battleship/Battleship/FormShipCollection.Designer.cs index 61fff26..d98eb94 100644 --- a/Battleship/Battleship/FormShipCollection.Designer.cs +++ b/Battleship/Battleship/FormShipCollection.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { Tools = new GroupBox(); + panelCompanyTools = new Panel(); + buttonAddShip = new Button(); + buttonRefresh = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonGoToTest = new Button(); + buttonDelShip = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -38,19 +44,12 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToTest = new Button(); - buttonDelShip = new Button(); - maskedTextBox = new MaskedTextBox(); - buttonAddBettleship = new Button(); - buttonAddShip = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); Tools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); SuspendLayout(); // // Tools @@ -67,6 +66,73 @@ Tools.TabStop = false; Tools.Text = "Инструменты"; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddShip); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonGoToTest); + panelCompanyTools.Controls.Add(buttonDelShip); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(0, 686); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(488, 569); + panelCompanyTools.TabIndex = 8; + // + // buttonAddShip + // + buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddShip.Location = new Point(9, 3); + buttonAddShip.Name = "buttonAddShip"; + buttonAddShip.Size = new Size(473, 90); + buttonAddShip.TabIndex = 1; + buttonAddShip.Text = "Добавить корабль"; + buttonAddShip.UseVisualStyleBackColor = true; + buttonAddShip.Click += ButtonAddShip_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(16, 432); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(466, 90); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // maskedTextBox + // + maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(12, 195); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(470, 39); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonGoToTest + // + buttonGoToTest.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToTest.Location = new Point(16, 336); + buttonGoToTest.Name = "buttonGoToTest"; + buttonGoToTest.Size = new Size(466, 90); + buttonGoToTest.TabIndex = 5; + buttonGoToTest.Text = "Передать на тест"; + buttonGoToTest.UseVisualStyleBackColor = true; + buttonGoToTest.Click += ButtonGoToTest_Click; + // + // buttonDelShip + // + buttonDelShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelShip.Location = new Point(12, 240); + buttonDelShip.Name = "buttonDelShip"; + buttonDelShip.Size = new Size(473, 90); + buttonDelShip.TabIndex = 4; + buttonDelShip.Text = "Удалить корабль"; + buttonDelShip.UseVisualStyleBackColor = true; + buttonDelShip.Click += ButtonDelShip_Click; + // // buttonCreateCompany // buttonCreateCompany.Location = new Point(9, 612); @@ -159,71 +225,6 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(16, 432); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(466, 90); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToTest - // - buttonGoToTest.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToTest.Location = new Point(16, 336); - buttonGoToTest.Name = "buttonGoToTest"; - buttonGoToTest.Size = new Size(466, 90); - buttonGoToTest.TabIndex = 5; - buttonGoToTest.Text = "Передать на тест"; - buttonGoToTest.UseVisualStyleBackColor = true; - buttonGoToTest.Click += ButtonGoToTest_Click; - // - // buttonDelShip - // - buttonDelShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelShip.Location = new Point(12, 240); - buttonDelShip.Name = "buttonDelShip"; - buttonDelShip.Size = new Size(473, 90); - buttonDelShip.TabIndex = 4; - buttonDelShip.Text = "Удалить корабль"; - buttonDelShip.UseVisualStyleBackColor = true; - buttonDelShip.Click += ButtonDelShip_Click; - // - // maskedTextBox - // - maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBox.Location = new Point(12, 195); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(470, 39); - maskedTextBox.TabIndex = 3; - maskedTextBox.ValidatingType = typeof(int); - // - // buttonAddBettleship - // - buttonAddBettleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBettleship.Location = new Point(9, 99); - buttonAddBettleship.Name = "buttonAddBettleship"; - buttonAddBettleship.Size = new Size(473, 90); - buttonAddBettleship.TabIndex = 2; - buttonAddBettleship.Text = "Добавить боевой корабль"; - buttonAddBettleship.UseVisualStyleBackColor = true; - buttonAddBettleship.Click += ButtonAddBattleship_Click; - // - // buttonAddShip - // - buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddShip.Location = new Point(9, 3); - buttonAddShip.Name = "buttonAddShip"; - buttonAddShip.Size = new Size(473, 90); - buttonAddShip.TabIndex = 1; - buttonAddShip.Text = "Добавить корабль"; - buttonAddShip.UseVisualStyleBackColor = true; - buttonAddShip.Click += ButtonAddShip_Click_1; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -245,20 +246,6 @@ pictureBox.TabIndex = 1; pictureBox.TabStop = false; // - // panelCompanyTools - // - panelCompanyTools.Controls.Add(buttonAddShip); - panelCompanyTools.Controls.Add(buttonAddBettleship); - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(maskedTextBox); - panelCompanyTools.Controls.Add(buttonGoToTest); - panelCompanyTools.Controls.Add(buttonDelShip); - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(0, 686); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(488, 569); - panelCompanyTools.TabIndex = 8; - // // FormShipCollection // AutoScaleDimensions = new SizeF(13F, 32F); @@ -269,18 +256,17 @@ Name = "FormShipCollection"; Text = "Коллекция кораблей"; Tools.ResumeLayout(false); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTools.ResumeLayout(false); - panelCompanyTools.PerformLayout(); ResumeLayout(false); } #endregion private GroupBox Tools; - private Button buttonAddBettleship; private Button buttonAddShip; private ComboBox comboBoxSelectorCompany; private Button buttonDelShip; diff --git a/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index f10754d..33cc580 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -20,7 +20,6 @@ public partial class FormShipCollection : Form /// Компания /// private AbstractCompany? _company = null; - /// /// Конструктор /// @@ -29,7 +28,7 @@ public partial class FormShipCollection : Form InitializeComponent(); _storageCollection = new(); } -#region Работа с компанией + #region Работа с компанией /// /// Выбор компании /// @@ -40,59 +39,10 @@ public partial class FormShipCollection : Form panelCompanyTools.Enabled = false; } /// - /// Создание объекта класса-перемещения + /// Кнопка удаления корабля /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - if (_company == null) - { - return; - } - - Random random = new(); - DrawningShip drawningShip; - switch (type) - { - case nameof(DrawningShip): - drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningBattleship): - drawningShip = new DrawningBattleship(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - - if (_company + drawningShip != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - private static Color GetColor(Random random) - { - Color color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - color = dialog.Color; - } - return color; - } - + /// + /// private void ButtonDelShip_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) @@ -116,7 +66,11 @@ public partial class FormShipCollection : Form MessageBox.Show("Не удалось удалить объект"); } } - + /// + /// Кнопка отправки на тест + /// + /// + /// private void ButtonGoToTest_Click(object sender, EventArgs e) { if (_company == null) @@ -148,7 +102,11 @@ public partial class FormShipCollection : Form form.ShowDialog(); } - + /// + /// Кнопка обновить + /// + /// + /// private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) @@ -158,11 +116,36 @@ public partial class FormShipCollection : Form pictureBox.Image = _company.Show(); } - private void ButtonAddBattleship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBattleship)); - - private void ButtonAddShip_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawningShip)); + /// + /// Кнопка добавления корабля + /// + /// + /// + private void ButtonAddShip_Click(object sender, EventArgs e) + { + FormShipConfig form = new(); + form.AddEvent(SetShip); + form.Show(); + } + /// + /// Метод установки корабля в компанию + /// + private void SetShip(DrawningShip? ship) + { + if (_company == null) + return; + if (_company + ship != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } #endregion -#region Работа с коллекцией + #region Работа с коллекцией /// /// Добавление коллекции /// @@ -252,4 +235,6 @@ public partial class FormShipCollection : Form RerfreshListBoxItems(); } #endregion + + } diff --git a/Battleship/Battleship/FormShipConfig.Designer.cs b/Battleship/Battleship/FormShipConfig.Designer.cs new file mode 100644 index 0000000..d38017d --- /dev/null +++ b/Battleship/Battleship/FormShipConfig.Designer.cs @@ -0,0 +1,357 @@ +namespace Battleship +{ + partial class FormShipConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxConfig = new GroupBox(); + groupBoxColors = new GroupBox(); + panelGray = new Panel(); + panelOrange = new Panel(); + panelPink = new Panel(); + panelPurple = new Panel(); + panelBlue = new Panel(); + panelWhite = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxRockets = new CheckBox(); + checkBoxWeapon = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + labelWeight = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + pictureBoxObject = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelBodyColor = new Label(); + groupBoxConfig.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(checkBoxRockets); + groupBoxConfig.Controls.Add(checkBoxWeapon); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Dock = DockStyle.Left; + groupBoxConfig.Location = new Point(0, 0); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(996, 436); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelOrange); + groupBoxColors.Controls.Add(panelPink); + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(499, 52); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(471, 249); + groupBoxColors.TabIndex = 8; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(359, 135); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(76, 71); + panelGray.TabIndex = 3; + // + // panelOrange + // + panelOrange.BackColor = Color.Orange; + panelOrange.Location = new Point(359, 38); + panelOrange.Name = "panelOrange"; + panelOrange.Size = new Size(76, 71); + panelOrange.TabIndex = 1; + // + // panelPink + // + panelPink.BackColor = Color.HotPink; + panelPink.Location = new Point(254, 135); + panelPink.Name = "panelPink"; + panelPink.Size = new Size(76, 71); + panelPink.TabIndex = 4; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(148, 135); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(76, 71); + panelPurple.TabIndex = 5; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(254, 38); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(76, 71); + panelBlue.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(44, 135); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(76, 71); + panelWhite.TabIndex = 2; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(148, 38); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(76, 71); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(44, 38); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(76, 71); + panelRed.TabIndex = 0; + // + // checkBoxRockets + // + checkBoxRockets.AutoSize = true; + checkBoxRockets.Location = new Point(12, 265); + checkBoxRockets.Name = "checkBoxRockets"; + checkBoxRockets.Size = new Size(374, 36); + checkBoxRockets.TabIndex = 7; + checkBoxRockets.Text = "Наличие рокетных установок"; + checkBoxRockets.UseVisualStyleBackColor = true; + // + // checkBoxWeapon + // + checkBoxWeapon.AutoSize = true; + checkBoxWeapon.Location = new Point(12, 207); + checkBoxWeapon.Name = "checkBoxWeapon"; + checkBoxWeapon.Size = new Size(343, 36); + checkBoxWeapon.TabIndex = 6; + checkBoxWeapon.Text = "Наличие оруженой башни"; + checkBoxWeapon.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(150, 124); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(240, 39); + numericUpDownWeight.TabIndex = 5; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(12, 124); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(57, 32); + labelWeight.TabIndex = 4; + labelWeight.Text = "Вес:"; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(150, 52); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(240, 39); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(12, 52); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(121, 32); + labelSpeed.TabIndex = 2; + labelSpeed.Text = "Скорость:"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(757, 326); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(169, 65); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(499, 326); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(169, 65); + labelSimpleObject.TabIndex = 0; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(41, 97); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(379, 249); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(1028, 378); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(150, 46); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(1327, 378); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 46); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(1028, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(449, 360); + panelObject.TabIndex = 4; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(251, 26); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(169, 65); + labelAdditionalColor.TabIndex = 10; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += LabelAdditionalColor_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(41, 26); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(169, 65); + labelBodyColor.TabIndex = 9; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += LabelBodyColor_DragDrop; + labelBodyColor.DragEnter += LabelBodyColor_DragEnter; + // + // FormShipConfig + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1501, 436); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Name = "FormShipConfig"; + Text = "Создание объекта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelSimpleObject; + private Label labelSpeed; + private Label labelModifiedObject; + private CheckBox checkBoxRockets; + private CheckBox checkBoxWeapon; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private GroupBox groupBoxColors; + private Panel panelGray; + private Panel panelOrange; + private Panel panelPink; + private Panel panelPurple; + private Panel panelBlue; + private Panel panelWhite; + private Panel panelGreen; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelBodyColor; + } +} \ No newline at end of file diff --git a/Battleship/Battleship/FormShipConfig.cs b/Battleship/Battleship/FormShipConfig.cs new file mode 100644 index 0000000..857a795 --- /dev/null +++ b/Battleship/Battleship/FormShipConfig.cs @@ -0,0 +1,156 @@ +using Battleship.Drawnings; +using Battleship.Entities; +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; + +namespace Battleship; +/// +/// Форма конфигурации объекта +/// +public partial class FormShipConfig : Form +{ + /// + /// Объект-прорисовка + /// + private DrawningShip? _ship; + /// + /// Событие для передачи объекта + /// + private event Action EventAddShip; + /// + /// Конструктор + /// labelModifiedObject + public FormShipConfig() + { + InitializeComponent(); + panelRed.MouseDown += Panel_MouseDown; + panelGreen.MouseDown += Panel_MouseDown; + panelBlue.MouseDown += Panel_MouseDown; + panelPink.MouseDown += Panel_MouseDown; + panelWhite.MouseDown += Panel_MouseDown; + panelGray.MouseDown += Panel_MouseDown; + panelOrange.MouseDown += Panel_MouseDown; + panelPurple.MouseDown += Panel_MouseDown; + + buttonCancel.Click += (s, e) => Close(); + } + /// + /// Привязка внешнего метода к событию + /// + public void AddEvent(Action action) + { + EventAddShip += action; + } + // + /// Прорисовка объекта + /// + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _ship?.SetPosition(15, 15); + _ship?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Передача данных по нажатию Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); + } + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + e.Effect = DragDropEffects.Copy; + else + e.Effect = DragDropEffects.None; + } + /// + /// Действия при приеме перетаскиваемой информации + /// + /// + /// + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text)?.ToString()) + { + case "labelSimpleObject": + _ship = new DrawningShip((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _ship = new DrawningBattleship((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, + Color.Black, checkBoxWeapon.Checked, checkBoxRockets.Checked); + break; + } + DrawObject(); + } + /// + /// Передаем информацию при нажатии на Panel + /// + /// + /// + private void Panel_MouseDown(object? sender, MouseEventArgs e) + { + (sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + /// + /// Проверка полчаемой в LabelBodyColor информации + /// + /// + /// + private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _ship != null) + e.Effect = DragDropEffects.Copy; + else + e.Effect = DragDropEffects.None; + } + /// + /// Проверка полчаемой в LabelAdditionalColor информации + /// + /// + /// + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _ship != null && _ship is DrawningBattleship) + e.Effect = DragDropEffects.Copy; + else + e.Effect = DragDropEffects.None; + } + private void LabelBodyColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e?.Data?.GetData(typeof(Color)); + _ship?.EntityShip?.ChangeColor(color); + DrawObject(); + } + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e?.Data?.GetData(typeof(Color)); + if (_ship is DrawningBattleship) + { + ((EntityBattleship?)_ship.EntityShip)?.ChangeAddColor(color); + DrawObject(); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } +} diff --git a/Battleship/Battleship/FormShipConfig.resx b/Battleship/Battleship/FormShipConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Battleship/Battleship/FormShipConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From f449db7f6a1049aae4d4ab69132d06da4143c620 Mon Sep 17 00:00:00 2001 From: grishazagidulin Date: Mon, 15 Apr 2024 17:21:24 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=91=D0=B0=D0=B3=D1=84=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICollectionGenericObjects.cs | 4 +- .../ListGenericObjects.cs | 16 +-- .../MassiveGenericObjects.cs | 8 +- .../StorageCollection.cs | 106 +++++++++--------- 4 files changed, 60 insertions(+), 74 deletions(-) diff --git a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs index eee43c9..bd3f705 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -41,7 +41,7 @@ public interface ICollectionGenericObjects /// /// Позиция /// true - удачно, false - удаление не удалось - T Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции @@ -49,4 +49,4 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); -} +} \ No newline at end of file diff --git a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs index 1562e6f..1a773bd 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs @@ -14,16 +14,12 @@ public class ListGenericObjects : ICollectionGenericObjects /// Список объектов, которые храним /// private readonly List _collection; - /// /// Максимально допустимое число объектов в списке /// private int _maxCount; - public int Count => _collection.Count; - public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } - /// /// Конструктор /// @@ -31,14 +27,12 @@ public class ListGenericObjects : ICollectionGenericObjects { _collection = new(); } - public T? Get(int position) { if (position < 0 || position >= _collection.Count) return null; return _collection[position]; } - public int Insert(T obj) { if (_collection.Count + 1 <= _maxCount) @@ -48,21 +42,19 @@ public class ListGenericObjects : ICollectionGenericObjects } return -1; } - public bool Insert(T obj, int position) { - if (_collection.Count + 1 > _maxCount || position < 0 || position >= _collection.Count) + if (_collection.Count + 1 > _maxCount || position < 0 || position >= _collection.Count) return false; _collection.Insert(position, obj); return true; } - - public T Remove(int position) + public T? Remove(int position) { if (position < 0 || position >= _collection.Count) return null; - T temp = _collection[position]; + T? temp = _collection[position]; _collection.RemoveAt(position); return temp; } -} +} \ No newline at end of file diff --git a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs index 819afe4..23e085a 100644 --- a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs @@ -98,13 +98,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects return false; } - public T Remove(int position) + public T? Remove(int position) { - if (position < 0 || position >= _collection.Length || _collection[position]==null) // проверка позиции и наличия объекта + if (position < 0 || position >= _collection.Length || _collection[position] == null) // проверка позиции и наличия объекта return null; - T temp = _collection[position]; + T? temp = _collection[position]; _collection[position] = null; return temp; } -} +} \ No newline at end of file diff --git a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs index d925bd8..1aeddf1 100644 --- a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs +++ b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs @@ -1,5 +1,4 @@ using Battleship.CollectionGenericObjects; - namespace ProjectSportCar.CollectionGenericObjects; /// @@ -7,70 +6,65 @@ namespace ProjectSportCar.CollectionGenericObjects; /// /// public class StorageCollection - where T : class + where T : class { - /// - /// Словарь (хранилище) с коллекциями - /// - readonly Dictionary> _storages; - - /// - /// Возвращение списка названий коллекций - /// - public List Keys => _storages.Keys.ToList(); - - /// - /// Конструктор - /// - public StorageCollection() - { - _storages = new Dictionary>(); - } - - /// - /// Добавление коллекции в хранилище - /// - /// Название коллекции - /// тип коллекции - public void AddCollection(string name, CollectionType collectionType) - { - if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) - return; - switch (collectionType) - { - case CollectionType.List: + /// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> _storages; + /// + /// Возвращение списка названий коллекций + /// + public List Keys => _storages.Keys.ToList(); + /// + /// Конструктор + /// + public StorageCollection() + { + _storages = new Dictionary>(); + } + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// тип коллекции + public void AddCollection(string name, CollectionType collectionType) + { + if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) + return; + switch (collectionType) + { + case CollectionType.List: _storages.Add(name, new ListGenericObjects()); - break; + break; case CollectionType.Massive: _storages.Add(name, new MassiveGenericObjects()); - break; - default: - break; + break; + default: + break; } } - /// /// Удаление коллекции /// /// Название коллекции public void DelCollection(string name) - { - if (_storages.ContainsKey(name)) //??? спрросить, зачем проверка - _storages.Remove(name); - } - - /// - /// Доступ к коллекции - /// - /// Название коллекции - /// - public ICollectionGenericObjects? this[string name] - { - get - { - if (_storages.TryGetValue(name, out ICollectionGenericObjects? value)) - return value; - return null; - } - } + { + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (_storages.TryGetValue(name, out ICollectionGenericObjects? value)) + return value; + return null; + } + } } \ No newline at end of file -- 2.25.1