diff --git a/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs b/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs
index 2f8e832..2ad89f3 100644
--- a/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs
+++ b/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs
@@ -24,6 +24,9 @@ public abstract class AbstractCompany
///
protected int _pictureHeight;
+ ///
+ /// Коллекция объектов
+ ///
protected ICollectionGenericObjects? _collection = null;
///
@@ -31,7 +34,6 @@ public abstract class AbstractCompany
///
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight) + 2;
-
///
/// Конструктор
///
diff --git a/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs b/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..bce8661
--- /dev/null
+++ b/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace Battleship.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs
index 4cb31a9..ec93c9b 100644
--- a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -6,7 +6,6 @@
/// Параметр: ограничение - ссылочный тип
public interface ICollectionGenericObjects
where T : class
-
{
///
/// Количество объектов в коллекции
diff --git a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..f75ef90
--- /dev/null
+++ b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,76 @@
+namespace Battleship.CollectionGenericObjects;
+
+///
+/// Конструктор
+///
+///
+public class ListGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Список объектов, которые храним
+ ///
+ private readonly List _collection;
+
+ ///
+ /// Максимально допустимое число объектов в списке
+ ///
+ private int _maxCount;
+
+ public int Count => _collection.Count;
+ public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
+
+ ///
+ /// Конструктор
+ ///
+ public ListGenericObjects()
+ {
+ _collection = new();
+ }
+
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if (position >= Count || position < 0)
+ return null;
+ return _collection[position];
+ }
+
+ public int Insert(T obj)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (Count == _maxCount) return -1;
+ _collection.Add(obj);
+ return Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (position >= Count || position < 0)
+ {
+ return -1;
+ }
+ if (Count == _maxCount)
+ {
+ return -1;
+ }
+ _collection.Insert(position, obj);
+ return position;
+ }
+
+ public T Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из списка
+ if (position >= Count || position < 0)
+ return null;
+ T obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
+ }
+}
diff --git a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs
index fce9967..df3df6f 100644
--- a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,6 +1,4 @@
-using Battleship.CollectionGenericObjects;
-
-//namespace Battleship.CollectionGenericObjects;
+namespace Battleship.CollectionGenericObjects;
///
/// Параметризованный набор объектов
@@ -16,7 +14,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public int Count => _collection.Length;
- public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (Count > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
///
/// Конструктор
@@ -26,7 +40,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
_collection = Array.Empty();
}
- public T? Get(int position)
+ public T Get(int position)
{
// TODO проверка позиции
if (position >= _collection.Length || position < 0)
@@ -47,7 +61,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
_collection[index] = obj;
return index;
}
- index++;
+ ++index;
}
return -1;
}
@@ -56,53 +70,47 @@ public class MassiveGenericObjects : ICollectionGenericObjects
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // ищется свободное место после этой позиции и идет вставка туда
- // если нет после, ищем до
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
// TODO вставка
if (position >= _collection.Length || position < 0)
return -1;
-
- // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- if (_collection[position] != null)
+ if (_collection[position] == null)
{
- // проверка, что после вставляемого элемента в массиве есть пустой элемент
- int nullIndex = -1;
- for (int i = position + 1; i < Count; i++)
- {
- if (_collection[i] == null)
- {
- nullIndex = i;
- break;
- }
- }
- // Если пустого элемента нет, то выходим
- if (nullIndex < 0)
- {
- return -1;
- }
- // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
- int j = nullIndex - 1;
- while (j >= position)
- {
- _collection[j + 1] = _collection[j];
- j--;
- }
+ _collection[position] = obj;
+ return position;
}
- // TODO вставка по позиции
- _collection[position] = obj;
- return position;
+ int index = position + 1;
+ while (index < _collection.Length)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return index;
+ }
+ ++index;
+ }
+ index = position - 1;
+ while (index >= 0)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return index;
+ }
+ --index;
+ }
+ return -1;
}
- public T? Remove(int position)
+ public T Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= _collection.Length || position < 0)
- {
return null;
- }
- T temp = _collection[position];
+ T obj = _collection[position];
_collection[position] = null;
- return temp;
+ return obj;
}
}
\ No newline at end of file
diff --git a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..51ff3c0
--- /dev/null
+++ b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,79 @@
+namespace Battleship.CollectionGenericObjects;
+
+///
+/// Класс-хранилище коллекций
+///
+///
+public class StorageCollection
+ where T : class
+{
+ ///
+ /// Словарь (хранилище) с коллекциями
+ ///
+ private Dictionary> _storages;
+
+ ///
+ /// Возвращение списка названий коллекции
+ ///
+ public List Keys => _storages.Keys.ToList();
+
+ ///
+ /// Конструктор
+ ///
+ public StorageCollection()
+ {
+ _storages = new Dictionary>();
+ }
+
+ ///
+ /// Добавление коллекции в хранилище
+ ///
+ /// Название коллекции
+ /// Тип коллекции
+ public void AddCollection(string name, CollectionType collectionType)
+ {
+ // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
+ if (_storages.ContainsKey(name))
+ return;
+
+ // TODO Прописать логику для добавления
+ if (collectionType == CollectionType.List)
+ {
+ _storages.Add(name, new ListGenericObjects());
+ }
+ if (collectionType == CollectionType.Massive)
+ {
+ _storages.Add(name, new MassiveGenericObjects());
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ public void DelCollection(string name)
+ {
+ // TODO Прописать логику для удаления коллекции
+ if (!_storages.ContainsKey(name))
+ return;
+ _storages.Remove(name);
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ ///
+ public ICollectionGenericObjects this[string name]
+ {
+ get
+ {
+ // TODO Продумать логику получения объекта
+ if (_storages.ContainsKey((string)name))
+ {
+ return _storages[name];
+ }
+ return null;
+ }
+ }
+}
diff --git a/Battleship/Battleship/FormWarshipCollection.Designer.cs b/Battleship/Battleship/FormWarshipCollection.Designer.cs
index 47b969c..146784d 100644
--- a/Battleship/Battleship/FormWarshipCollection.Designer.cs
+++ b/Battleship/Battleship/FormWarshipCollection.Designer.cs
@@ -29,138 +29,261 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ panelCompanyTools = new Panel();
buttonRefresh = new Button();
+ maskedTextBox1 = new MaskedTextBox();
buttonGoToCheck = new Button();
+ buttonAddWarship = new Button();
buttonRemoveWarship = new Button();
buttonAddBattleship = new Button();
- buttonAddWarship = new Button();
- comboBoxSelectionCompany = new ComboBox();
+ panelStorage = new Panel();
+ comboBoxSelectorCompany = new ComboBox();
+ buttonCollectionDel = new Button();
+ buttonCreateCompany = new Button();
+ listBoxCollection = new ListBox();
+ buttonCollectionAdd = new Button();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
pictureBox = new PictureBox();
- maskedTextBox1 = new MaskedTextBox();
groupBoxTools.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(maskedTextBox1);
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonRemoveWarship);
- groupBoxTools.Controls.Add(buttonAddBattleship);
- groupBoxTools.Controls.Add(buttonAddWarship);
- groupBoxTools.Controls.Add(comboBoxSelectionCompany);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(861, 0);
+ groupBoxTools.Location = new Point(876, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(292, 583);
+ groupBoxTools.Size = new Size(292, 656);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(maskedTextBox1);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonAddWarship);
+ panelCompanyTools.Controls.Add(buttonRemoveWarship);
+ panelCompanyTools.Controls.Add(buttonAddBattleship);
+ panelCompanyTools.Location = new Point(6, 374);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(283, 276);
+ panelCompanyTools.TabIndex = 10;
+ //
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(12, 477);
+ buttonRefresh.Location = new Point(3, 228);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(274, 42);
+ buttonRefresh.Size = new Size(277, 42);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
+ // maskedTextBox1
+ //
+ maskedTextBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBox1.Location = new Point(3, 99);
+ maskedTextBox1.Mask = "00";
+ maskedTextBox1.Name = "maskedTextBox1";
+ maskedTextBox1.Size = new Size(277, 27);
+ maskedTextBox1.TabIndex = 7;
+ //
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(12, 381);
+ buttonGoToCheck.Location = new Point(3, 180);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(274, 42);
+ buttonGoToCheck.Size = new Size(277, 42);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
//
- // buttonRemoveWarship
- //
- buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveWarship.Location = new Point(12, 283);
- buttonRemoveWarship.Name = "buttonRemoveWarship";
- buttonRemoveWarship.Size = new Size(274, 42);
- buttonRemoveWarship.TabIndex = 4;
- buttonRemoveWarship.Text = "Удалить корабль";
- buttonRemoveWarship.UseVisualStyleBackColor = true;
- buttonRemoveWarship.Click += buttonRemoveWarship_Click_1;
- //
- // buttonAddBattleship
- //
- buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddBattleship.Location = new Point(12, 143);
- buttonAddBattleship.Name = "buttonAddBattleship";
- buttonAddBattleship.Size = new Size(274, 42);
- buttonAddBattleship.TabIndex = 2;
- buttonAddBattleship.Text = "Добавление линкора";
- buttonAddBattleship.UseVisualStyleBackColor = true;
- buttonAddBattleship.Click += ButtonAddBattleship_Click;
- //
// buttonAddWarship
//
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddWarship.Location = new Point(12, 95);
+ buttonAddWarship.Location = new Point(3, 3);
buttonAddWarship.Name = "buttonAddWarship";
- buttonAddWarship.Size = new Size(274, 42);
+ buttonAddWarship.Size = new Size(277, 42);
buttonAddWarship.TabIndex = 1;
buttonAddWarship.Text = "Добавление корабля";
buttonAddWarship.UseVisualStyleBackColor = true;
buttonAddWarship.Click += ButtonAddWarship_Click;
//
- // comboBoxSelectionCompany
+ // buttonRemoveWarship
//
- comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList;
- comboBoxSelectionCompany.FormattingEnabled = true;
- comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectionCompany.Location = new Point(12, 26);
- comboBoxSelectionCompany.Name = "comboBoxSelectionCompany";
- comboBoxSelectionCompany.Size = new Size(274, 28);
- comboBoxSelectionCompany.TabIndex = 0;
- comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveWarship.Location = new Point(0, 132);
+ buttonRemoveWarship.Name = "buttonRemoveWarship";
+ buttonRemoveWarship.Size = new Size(280, 42);
+ buttonRemoveWarship.TabIndex = 4;
+ buttonRemoveWarship.Text = "Удалить корабль";
+ buttonRemoveWarship.UseVisualStyleBackColor = true;
+ buttonRemoveWarship.Click += ButtonRemoveWarship_Click_1;
+ //
+ // buttonAddBattleship
+ //
+ buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddBattleship.Location = new Point(3, 51);
+ buttonAddBattleship.Name = "buttonAddBattleship";
+ buttonAddBattleship.Size = new Size(277, 42);
+ buttonAddBattleship.TabIndex = 2;
+ buttonAddBattleship.Text = "Добавление линкора";
+ buttonAddBattleship.UseVisualStyleBackColor = true;
+ buttonAddBattleship.Click += ButtonAddBattleship_Click;
+ //
+ // panelStorage
+ //
+ panelStorage.Controls.Add(comboBoxSelectorCompany);
+ panelStorage.Controls.Add(buttonCollectionDel);
+ panelStorage.Controls.Add(buttonCreateCompany);
+ panelStorage.Controls.Add(listBoxCollection);
+ panelStorage.Controls.Add(buttonCollectionAdd);
+ panelStorage.Controls.Add(radioButtonList);
+ panelStorage.Controls.Add(radioButtonMassive);
+ panelStorage.Controls.Add(textBoxCollectionName);
+ panelStorage.Controls.Add(labelCollectionName);
+ panelStorage.Dock = DockStyle.Top;
+ panelStorage.Location = new Point(3, 23);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(286, 345);
+ panelStorage.TabIndex = 8;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Location = new Point(9, 310);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(271, 28);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCollectionDel.Location = new Point(9, 240);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(274, 29);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удаление из коллекции";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCreateCompany.Location = new Point(35, 275);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(218, 29);
+ buttonCreateCompany.TabIndex = 9;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.Location = new Point(9, 130);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(274, 104);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCollectionAdd.Location = new Point(9, 95);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(274, 29);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(203, 65);
+ radioButtonList.Name = "radioButtonList";
+ radioButtonList.Size = new Size(80, 24);
+ radioButtonList.TabIndex = 3;
+ radioButtonList.TabStop = true;
+ radioButtonList.Text = "Список";
+ radioButtonList.UseVisualStyleBackColor = true;
+ //
+ // radioButtonMassive
+ //
+ radioButtonMassive.AutoSize = true;
+ radioButtonMassive.Location = new Point(9, 65);
+ radioButtonMassive.Name = "radioButtonMassive";
+ radioButtonMassive.Size = new Size(82, 24);
+ radioButtonMassive.TabIndex = 2;
+ radioButtonMassive.TabStop = true;
+ radioButtonMassive.Text = "Массив";
+ radioButtonMassive.UseVisualStyleBackColor = true;
+ //
+ // textBoxCollectionName
+ //
+ textBoxCollectionName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxCollectionName.Location = new Point(9, 32);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(274, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(67, 9);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(155, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции";
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(861, 583);
+ pictureBox.Size = new Size(876, 656);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
- // maskedTextBox1
- //
- maskedTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBox1.Location = new Point(12, 250);
- maskedTextBox1.Mask = "00";
- maskedTextBox1.Name = "maskedTextBox1";
- maskedTextBox1.Size = new Size(274, 27);
- maskedTextBox1.TabIndex = 7;
- //
// FormWarshipCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1153, 583);
+ ClientSize = new Size(1168, 656);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormWarshipCollection";
Text = "Коллекция кораблей";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
- private ComboBox comboBoxSelectionCompany;
+ private ComboBox comboBoxSelectorCompany;
private Button buttonAddBattleship;
private Button buttonAddWarship;
private Button buttonRemoveWarship;
@@ -168,5 +291,15 @@
private Button buttonRefresh;
private Button buttonGoToCheck;
private MaskedTextBox maskedTextBox1;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCollectionAdd;
+ private ListBox listBoxCollection;
+ private Button buttonCreateCompany;
+ private Button buttonCollectionDel;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/Battleship/Battleship/FormWarshipCollection.cs b/Battleship/Battleship/FormWarshipCollection.cs
index 21a1d8b..c3518d4 100644
--- a/Battleship/Battleship/FormWarshipCollection.cs
+++ b/Battleship/Battleship/FormWarshipCollection.cs
@@ -8,6 +8,11 @@ namespace Battleship;
///
public partial class FormWarshipCollection : Form
{
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -19,6 +24,7 @@ public partial class FormWarshipCollection : Form
public FormWarshipCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -28,12 +34,27 @@ public partial class FormWarshipCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectionCompany.Text)
- {
- case "Хранилище":
- _company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
+ }
+
+ ///
+ /// Добавление линкора
+ ///
+ ///
+ ///
+ private void ButtonAddBattleship_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawingBattleship));
+ }
+
+ ///
+ /// Добавление военного корабля
+ ///
+ ///
+ ///
+ private void ButtonAddWarship_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawingWarship));
}
///
@@ -46,6 +67,7 @@ public partial class FormWarshipCollection : Form
{
return;
}
+
Random random = new();
DrawingWarship drawingWarship;
switch (type)
@@ -57,7 +79,7 @@ public partial class FormWarshipCollection : Form
drawingWarship = new DrawingBattleship(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random),
GetColor(random),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
break;
default:
return;
@@ -90,6 +112,35 @@ public partial class FormWarshipCollection : Form
return color;
}
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveWarship_Click_1(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBox1.Text);
+ if (_company - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
///
/// Передача на тесты
///
@@ -122,55 +173,6 @@ public partial class FormWarshipCollection : Form
}
- ///
- /// Добавление линкора
- ///
- ///
- ///
- private void ButtonAddBattleship_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawingBattleship));
- }
-
- ///
- /// Добавление военного корабля
- ///
- ///
- ///
- private void ButtonAddWarship_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawingWarship));
- }
-
- ///
- /// Удаление объекта
- ///
- ///
- ///
- private void buttonRemoveWarship_Click_1(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
- {
- return;
- }
-
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
- {
- return;
- }
-
- int pos = Convert.ToInt32(maskedTextBox1.Text);
- if (_company - pos != null)
- {
- MessageBox.Show("Объект удален");
- pictureBox.Image = _company.Show();
- }
- else
- {
- MessageBox.Show("Не удалось удалить объект");
- }
- }
-
///
/// Обновление
///
@@ -184,4 +186,102 @@ public partial class FormWarshipCollection : Form
}
pictureBox.Image = _company.Show();
}
+
+ ///
+ /// Обновление списка в listBoxCollection
+ ///
+ private void RerfreshListBoxItems()
+ {
+ listBoxCollection.Items.Clear();
+ for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
+ {
+ string? colName = _storageCollection.Keys?[i];
+ if (!string.IsNullOrEmpty(colName))
+ {
+ listBoxCollection.Items.Add(colName);
+ }
+ }
+ }
+
+ ///
+ /// Добавление коллекции
+ ///
+ ///
+ ///
+ private void ButtonCollectionAdd_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ CollectionType collectionType = CollectionType.None;
+ if (radioButtonMassive.Checked)
+ {
+ collectionType = CollectionType.Massive;
+ }
+ else if (radioButtonList.Checked)
+ {
+ collectionType = CollectionType.List;
+ }
+ _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
+ RerfreshListBoxItems();
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ ///
+ private void ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ // TODO прописать логику удаления элемента из коллекции
+ // нужно убедиться, что есть выбранная коллекция
+ // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
+ // удалить и обновить ListBox
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RerfreshListBoxItems();
+ }
+
+ ///
+ /// Создание компании
+ ///
+ ///
+ ///
+ private void ButtonCreateCompany_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+
+ ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
+
+ if (collection == null)
+ {
+ MessageBox.Show("Коллекция не проинициализирована");
+ return;
+ }
+
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+ }
}
\ No newline at end of file