diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..4bedf0b
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,116 @@
+using ProjectAircraftCarrier_.Drawnings;
+
+namespace ProjectAircraftCarrier_.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 300;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 80;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция автомобилей
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция автомобилей
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static int operator +(AbstractCompany company, DrawningWarship warship)
+ {
+ return company._collection.Insert(warship);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningWarship? operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningWarship? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackground(graphics);
+
+ SetObjectsPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningWarship? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackground(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/Docks.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/Docks.cs
new file mode 100644
index 0000000..44ab95c
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/Docks.cs
@@ -0,0 +1,61 @@
+
+using ProjectAircraftCarrier_.Drawnings;
+
+namespace ProjectAircraftCarrier_.CollectionGenericObjects;
+
+public class Docks : AbstractCompany
+{
+ public Docks(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 2);
+ Pen widerPen = new(Color.Black, 5);
+
+ for (int i = 0; i < _pictureHeight / _placeSizeHeight; i++)
+ {
+ int y = _placeSizeHeight;
+ y *= i;
+
+ for (int j = 0; j <= _pictureWidth / _placeSizeWidth; j++)
+ {
+ int x = _placeSizeWidth;
+ x *= j;
+
+ g.DrawLine(widerPen, x, y, x + _placeSizeWidth / 2, y);
+ g.DrawLine(widerPen, x, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
+ g.DrawLine(pen, x, y, x, y + _placeSizeHeight - 10);
+ g.DrawLine(pen, x + _placeSizeWidth / 2, y, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
+ }
+
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int n = 0;
+ int m = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (_collection?.Get(i) != null)
+ {
+ int x = 5 + _placeSizeWidth * n;
+ int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
+
+ _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection?.Get(i)?.SetPosition(x, y);
+ }
+
+ if (n < _pictureWidth / _placeSizeWidth)
+ n++;
+ else
+ {
+ n = 0;
+ m++;
+ }
+ }
+ }
+}
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..c242008
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,49 @@
+namespace ProjectAircraftCarrier_.CollectionGenericObjects;
+
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ T? Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+}
+
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..a3c5478
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,104 @@
+namespace ProjectAircraftCarrier_.CollectionGenericObjects;
+
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position > Count)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+
+ public int Insert(T obj)
+ {
+ // TODO вставка в свободное место набора
+ for (int i = 0; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ // TODO вставка
+ if (position < 0 || position > Count)
+ {
+ return -1;
+ }
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return position;
+ }
+ }
+
+ for (int i = position - 1; i >= 0; i--)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return position;
+ }
+ }
+
+ return -1;
+ }
+
+ public T? Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ if (position < 0 || position > Count || _collection[position] == null)
+ {
+ return null;
+ }
+
+ T? obj = _collection[position];
+ _collection[position] = null;
+ return obj;
+ }
+}
+
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Drawnings/DrawningWarship.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Drawnings/DrawningWarship.cs
index aa2209c..c1c8114 100644
--- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Drawnings/DrawningWarship.cs
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Drawnings/DrawningWarship.cs
@@ -87,12 +87,12 @@ public class DrawningWarship
///
/// Конструктор для наследников
///
- /// Ширина прорисовки военного корабля
- /// Высота прорисовки военного корабля
- protected DrawningWarship(int drawningCarrierWidth, int drawningCarrierHeight) : this()
+ /// Ширина прорисовки военного корабля
+ /// Высота прорисовки военного корабля
+ protected DrawningWarship(int DrawningWarshiprierWidth, int DrawningWarshiprierHeight) : this()
{
- _drawningWarshipWidth = drawningCarrierWidth;
- _drawningWarshipHeight = drawningCarrierHeight;
+ _drawningWarshipWidth = DrawningWarshiprierWidth;
+ _drawningWarshipHeight = DrawningWarshiprierHeight;
}
///
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.Designer.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.Designer.cs
index 33746be..127533f 100644
--- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.Designer.cs
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxAircraftCarrier = new PictureBox();
- buttonCreateAircraftCarrier = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
- buttonCreateWarship = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit();
@@ -45,27 +43,16 @@
pictureBoxAircraftCarrier.Dock = DockStyle.Fill;
pictureBoxAircraftCarrier.Location = new Point(0, 0);
pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier";
- pictureBoxAircraftCarrier.Size = new Size(1167, 653);
+ pictureBoxAircraftCarrier.Size = new Size(1392, 778);
pictureBoxAircraftCarrier.TabIndex = 0;
pictureBoxAircraftCarrier.TabStop = false;
//
- // buttonCreateAircraftCarrier
- //
- buttonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateAircraftCarrier.Location = new Point(12, 601);
- buttonCreateAircraftCarrier.Name = "buttonCreateAircraftCarrier";
- buttonCreateAircraftCarrier.Size = new Size(207, 40);
- buttonCreateAircraftCarrier.TabIndex = 1;
- buttonCreateAircraftCarrier.Text = "Создать авианосец";
- buttonCreateAircraftCarrier.UseVisualStyleBackColor = true;
- buttonCreateAircraftCarrier.Click += ButtonCreateAircraftCarrier_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(1030, 606);
+ buttonLeft.Location = new Point(1255, 731);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
@@ -77,7 +64,7 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(1071, 606);
+ buttonDown.Location = new Point(1296, 731);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 3;
@@ -89,7 +76,7 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(1112, 606);
+ buttonRight.Location = new Point(1337, 731);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 4;
@@ -101,37 +88,28 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(1071, 565);
+ buttonUp.Location = new Point(1296, 690);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 5;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
- // buttonCreateWarship
- //
- buttonCreateWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateWarship.Location = new Point(244, 601);
- buttonCreateWarship.Name = "buttonCreateWarship";
- buttonCreateWarship.Size = new Size(273, 40);
- buttonCreateWarship.TabIndex = 7;
- buttonCreateWarship.Text = "Создать военный корабль";
- buttonCreateWarship.UseVisualStyleBackColor = true;
- buttonCreateWarship.Click += ButtonCreateWarship_Click;
- //
// comboBoxStrategy
//
+ comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
- comboBoxStrategy.Location = new Point(943, 12);
+ comboBoxStrategy.Location = new Point(1168, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(212, 38);
comboBoxStrategy.TabIndex = 8;
//
// buttonStrategyStep
//
- buttonStrategyStep.Location = new Point(1024, 56);
+ buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonStrategyStep.Location = new Point(1249, 56);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(131, 40);
buttonStrategyStep.TabIndex = 9;
@@ -143,15 +121,13 @@
//
AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1167, 653);
+ ClientSize = new Size(1392, 778);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateWarship);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateAircraftCarrier);
Controls.Add(pictureBoxAircraftCarrier);
Name = "FormAircraftCarrier";
Text = "Авианосец";
@@ -162,12 +138,10 @@
#endregion
private PictureBox pictureBoxAircraftCarrier;
- private Button buttonCreateAircraftCarrier;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
- private Button buttonCreateWarship;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.cs
index 6b92af0..fb2c2ac 100644
--- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.cs
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormAircraftCarrier.cs
@@ -18,6 +18,22 @@ public partial class FormAircraftCarrier : Form
///
private AbstractStrategy? _strategy;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningWarship SetWarship
+ {
+ set
+ {
+ _drawningWarship = value;
+ _drawningWarship.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
+
///
/// Конструктор формы
///
@@ -43,51 +59,6 @@ public partial class FormAircraftCarrier : Form
pictureBoxAircraftCarrier.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningWarship):
- _drawningWarship = new DrawningWarship(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
- break;
- case nameof(DrawningAircraftCarrier):
- _drawningWarship = new DrawningAircraftCarrier(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
-
- _drawningWarship.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
- _drawningWarship.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать авианосец"
- ///
- ///
- ///
- private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftCarrier));
-
- ///
- /// Обработка нажатия кнопки "Создать военный корабль"
- ///
- ///
- ///
- private void ButtonCreateWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarship));
-
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs
new file mode 100644
index 0000000..f3ba626
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectAircraftCarrier_
+{
+ partial class FormWarshipCollection
+ {
+ ///
+ /// 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()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonRemoveWarship = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddAircraftCarrier = new Button();
+ buttonAddWarship = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveWarship);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddAircraftCarrier);
+ groupBoxTools.Controls.Add(buttonAddWarship);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(1126, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(326, 912);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 767);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(314, 72);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(6, 595);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(314, 72);
+ 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(6, 432);
+ buttonRemoveWarship.Name = "buttonRemoveWarship";
+ buttonRemoveWarship.Size = new Size(314, 72);
+ buttonRemoveWarship.TabIndex = 4;
+ buttonRemoveWarship.Text = "Удаление военного корабля";
+ buttonRemoveWarship.UseVisualStyleBackColor = true;
+ buttonRemoveWarship.Click += ButtonRemoveWarship_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(6, 391);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(314, 35);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddAircraftCarrier
+ //
+ buttonAddAircraftCarrier.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddAircraftCarrier.Location = new Point(6, 232);
+ buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier";
+ buttonAddAircraftCarrier.Size = new Size(314, 72);
+ buttonAddAircraftCarrier.TabIndex = 2;
+ buttonAddAircraftCarrier.Text = "Добавление авианосца";
+ buttonAddAircraftCarrier.UseVisualStyleBackColor = true;
+ buttonAddAircraftCarrier.Click += ButtonAddAircraftCarrier_Click;
+ //
+ // buttonAddWarship
+ //
+ buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddWarship.Location = new Point(6, 154);
+ buttonAddWarship.Name = "buttonAddWarship";
+ buttonAddWarship.Size = new Size(314, 72);
+ buttonAddWarship.TabIndex = 1;
+ buttonAddWarship.Text = "Добавление военного корабля";
+ buttonAddWarship.UseVisualStyleBackColor = true;
+ buttonAddWarship.Click += ButtonAddWarship_Click;
+ //
+ // 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(6, 34);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(314, 38);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(1126, 912);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormWarshipCollection
+ //
+ AutoScaleDimensions = new SizeF(12F, 30F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1452, 912);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormWarshipCollection";
+ Text = "Коллекция военных кораблей";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonAddWarship;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddAircraftCarrier;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ private Button buttonRemoveWarship;
+ private MaskedTextBox maskedTextBoxPosition;
+ }
+}
\ No newline at end of file
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs
new file mode 100644
index 0000000..577429a
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs
@@ -0,0 +1,187 @@
+using ProjectAircraftCarrier_.CollectionGenericObjects;
+using ProjectAircraftCarrier_.Drawnings;
+
+namespace ProjectAircraftCarrier_;
+
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormWarshipCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormWarshipCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new Docks(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningWarship drawningWarship;
+ switch (type)
+ {
+ case nameof(DrawningWarship):
+ drawningWarship = new DrawningWarship(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningAircraftCarrier):
+ // TODO вызов диалогового окна для выбора цвета
+ drawningWarship = new DrawningAircraftCarrier(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)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningWarship != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ return color;
+ }
+
+ ///
+ /// Добавление военного корабля
+ ///
+ ///
+ ///
+ private void ButtonAddWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarship));
+
+ ///
+ /// Добавление авианосца
+ ///
+ ///
+ ///
+ private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftCarrier));
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveWarship_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_company - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningWarship? warship = null;
+ int counter = 100;
+ while (warship == null)
+ {
+ warship = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (warship == null)
+ {
+ return;
+ }
+
+ FormAircraftCarrier form = new()
+ {
+ SetWarship = warship
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+}
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.resx b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.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
diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Program.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Program.cs
index a84e56d..332bbfa 100644
--- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Program.cs
+++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectAircraftCarrier_
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormAircraftCarrier());
+ Application.Run(new FormWarshipCollection());
}
}
}
\ No newline at end of file