diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..4a2efd1
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,109 @@
+using ProjectAirFighter.Drawnings;
+
+namespace ProjectAirFighter.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию самолетов
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места(ширина)
+ ///
+ protected readonly int _placeSizeWidth = 180;
+
+ ///
+ /// Размер места(высота)
+ ///
+ protected readonly int _placeSizeHeight = 210;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningWarPlane warPlane)
+ {
+ if (company._collection == null) return -1;
+ return company._collection.Insert(warPlane);
+ }
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningWarPlane operator -(AbstractCompany company, int position)
+ {
+ if (company._collection == null) return null;
+ return company._collection.Remove(position);
+ }
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningWarPlane? GetRandomObjects()
+ {
+ 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)
+ {
+ DrawningWarPlane? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackground(Graphics graphics);
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/PlaneHangar.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/PlaneHangar.cs
new file mode 100644
index 0000000..d485324
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/PlaneHangar.cs
@@ -0,0 +1,59 @@
+using ProjectAirFighter.Drawnings;
+
+namespace ProjectAirFighter.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - Ангар для самолетов
+///
+public class PlaneHangar : AbstractCompany
+{
+ public PlaneHangar(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 2);
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ for(int i = 0; i < width; i++)
+ {
+ for(int j = 0; j < height; j++)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 210, i * _placeSizeWidth + 10, j * _placeSizeHeight + 40);
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 40, i * _placeSizeWidth + 95, j * _placeSizeHeight + 10);
+ g.DrawLine(pen, i * _placeSizeWidth + 95, j * _placeSizeHeight + 10, i * _placeSizeWidth + 180, j * _placeSizeHeight + 40);
+ g.DrawLine(pen, i * _placeSizeWidth + 180, j * _placeSizeHeight + 40, i * _placeSizeWidth + 180, j * _placeSizeHeight + 210);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = 0;
+ int curHeight = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (_collection.Get(i) != null)
+ {
+ _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 50);
+ }
+ if (curHeight < height - 1)
+ curHeight++;
+ else
+ {
+ curHeight = 0;
+ curWidth++;
+ }
+ if (curWidth > width)
+ {
+ return;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs
index 9504882..ed7b5f4 100644
--- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs
+++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxAirFighter = new PictureBox();
- buttonCreateAirFighter = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonDown = new Button();
- buttonCreateWarPlane = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit();
@@ -44,33 +42,19 @@
//
pictureBoxAirFighter.Dock = DockStyle.Fill;
pictureBoxAirFighter.Location = new Point(0, 0);
- pictureBoxAirFighter.Margin = new Padding(3, 4, 3, 4);
pictureBoxAirFighter.Name = "pictureBoxAirFighter";
- pictureBoxAirFighter.Size = new Size(882, 673);
+ pictureBoxAirFighter.Size = new Size(772, 505);
pictureBoxAirFighter.TabIndex = 0;
pictureBoxAirFighter.TabStop = false;
//
- // buttonCreateAirFighter
- //
- buttonCreateAirFighter.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateAirFighter.Location = new Point(14, 626);
- buttonCreateAirFighter.Margin = new Padding(3, 4, 3, 4);
- buttonCreateAirFighter.Name = "buttonCreateAirFighter";
- buttonCreateAirFighter.Size = new Size(228, 31);
- buttonCreateAirFighter.TabIndex = 1;
- buttonCreateAirFighter.Text = "Создать истребитель";
- buttonCreateAirFighter.UseVisualStyleBackColor = true;
- buttonCreateAirFighter.Click += ButtonCreateAirFighter_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(735, 610);
- buttonLeft.Margin = new Padding(3, 4, 3, 4);
+ buttonLeft.Location = new Point(643, 458);
buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(40, 47);
+ buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
@@ -80,10 +64,9 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(782, 556);
- buttonUp.Margin = new Padding(3, 4, 3, 4);
+ buttonUp.Location = new Point(684, 417);
buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(40, 47);
+ buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
@@ -93,10 +76,9 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(829, 610);
- buttonRight.Margin = new Padding(3, 4, 3, 4);
+ buttonRight.Location = new Point(725, 458);
buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(40, 47);
+ buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 4;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
@@ -106,41 +88,30 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(782, 610);
- buttonDown.Margin = new Padding(3, 4, 3, 4);
+ buttonDown.Location = new Point(684, 458);
buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(40, 47);
+ buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
- // buttonCreateWarPlane
- //
- buttonCreateWarPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateWarPlane.Location = new Point(248, 626);
- buttonCreateWarPlane.Margin = new Padding(3, 4, 3, 4);
- buttonCreateWarPlane.Name = "buttonCreateWarPlane";
- buttonCreateWarPlane.Size = new Size(228, 31);
- buttonCreateWarPlane.TabIndex = 6;
- buttonCreateWarPlane.Text = "Создать военный самолет";
- buttonCreateWarPlane.UseVisualStyleBackColor = true;
- buttonCreateWarPlane.Click += ButtonCreateWarPlane_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
- comboBoxStrategy.Location = new Point(719, 12);
+ comboBoxStrategy.Location = new Point(629, 9);
+ comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
comboBoxStrategy.Name = "comboBoxStrategy";
- comboBoxStrategy.Size = new Size(151, 28);
+ comboBoxStrategy.Size = new Size(133, 23);
comboBoxStrategy.TabIndex = 7;
//
// buttonStrategyStep
//
- buttonStrategyStep.Location = new Point(775, 46);
+ buttonStrategyStep.Location = new Point(678, 34);
+ buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
buttonStrategyStep.Name = "buttonStrategyStep";
- buttonStrategyStep.Size = new Size(94, 29);
+ buttonStrategyStep.Size = new Size(82, 22);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
@@ -148,19 +119,16 @@
//
// FormAirFighter
//
- AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(882, 673);
+ ClientSize = new Size(772, 505);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateWarPlane);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateAirFighter);
Controls.Add(pictureBoxAirFighter);
- Margin = new Padding(3, 4, 3, 4);
Name = "FormAirFighter";
Text = "Истребитель";
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).EndInit();
@@ -170,12 +138,10 @@
#endregion
private PictureBox pictureBoxAirFighter;
- private Button buttonCreateAirFighter;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
- private Button buttonCreateWarPlane;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs
index 216be7d..387c637 100644
--- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs
+++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs
@@ -13,6 +13,21 @@ public partial class FormAirFighter : Form
///
private DrawningWarPlane? _drawningWarPlane;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningWarPlane SetPlane
+ {
+ set
+ {
+ _drawningWarPlane = value;
+ _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Стратегия перемещения
///
@@ -43,45 +58,6 @@ public partial class FormAirFighter : Form
pictureBoxAirFighter.Image = bmp;
}
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningWarPlane):
- _drawningWarPlane = new DrawningWarPlane(random.Next(300, 600), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
- break;
- case nameof(DrawningAirFighter):
- _drawningWarPlane = new DrawningAirFighter(random.Next(300, 600), 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;
- }
- _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
- _drawningWarPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать истребитель"
- ///
- ///
- ///
- private void ButtonCreateAirFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirFighter));
-
- ///
- /// Обработка нажатия кнопки "Создать военный самолет"
- ///
- ///
- ///
- private void ButtonCreateWarPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane));
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
diff --git a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.Designer.cs
new file mode 100644
index 0000000..3fe5aef
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectAirFighter
+{
+ partial class FormPlaneCollection
+ {
+ ///
+ /// 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();
+ buttonRemovePlane = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddAirFighter = new Button();
+ buttonAddWarPlane = 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(buttonRemovePlane);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddAirFighter);
+ groupBoxTools.Controls.Add(buttonAddWarPlane);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(867, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(208, 621);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(15, 563);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(181, 46);
+ 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(15, 398);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(181, 46);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemovePlane
+ //
+ buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemovePlane.Location = new Point(15, 282);
+ buttonRemovePlane.Name = "buttonRemovePlane";
+ buttonRemovePlane.Size = new Size(181, 46);
+ buttonRemovePlane.TabIndex = 4;
+ buttonRemovePlane.Text = "Удалить самолет";
+ buttonRemovePlane.UseVisualStyleBackColor = true;
+ buttonRemovePlane.Click += ButtonRemovePlane_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(15, 253);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(181, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddAirFighter
+ //
+ buttonAddAirFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddAirFighter.Location = new Point(15, 158);
+ buttonAddAirFighter.Name = "buttonAddAirFighter";
+ buttonAddAirFighter.Size = new Size(181, 46);
+ buttonAddAirFighter.TabIndex = 2;
+ buttonAddAirFighter.Text = "Добавление истребителя";
+ buttonAddAirFighter.UseVisualStyleBackColor = true;
+ buttonAddAirFighter.Click += ButtonAddAirFighter_Click;
+ //
+ // buttonAddWarPlane
+ //
+ buttonAddWarPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddWarPlane.Location = new Point(15, 106);
+ buttonAddWarPlane.Name = "buttonAddWarPlane";
+ buttonAddWarPlane.Size = new Size(181, 46);
+ buttonAddWarPlane.TabIndex = 1;
+ buttonAddWarPlane.Text = "Добавление военного самолета";
+ buttonAddWarPlane.UseVisualStyleBackColor = true;
+ buttonAddWarPlane.Click += ButtonAddWarPlane_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(15, 22);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(181, 23);
+ 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(867, 621);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormPlaneCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1075, 621);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormPlaneCollection";
+ Text = "Коллекция самолетов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddWarPlane;
+ private Button buttonAddAirFighter;
+ private Button buttonRemovePlane;
+ private MaskedTextBox maskedTextBoxPosition;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs
new file mode 100644
index 0000000..f966912
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs
@@ -0,0 +1,135 @@
+using ProjectAirFighter.CollectionGenericObjects;
+using ProjectAirFighter.Drawnings;
+
+namespace ProjectAirFighter
+{
+ ///
+ /// Форма работы с компанией и ее коллекцией
+ ///
+ public partial class FormPlaneCollection : Form
+ {
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormPlaneCollection()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор комапнии
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new PlaneHangar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null) return;
+ DrawningWarPlane drawingWarPlane;
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningWarPlane):
+ drawingWarPlane = new DrawningWarPlane(random.Next(300, 600), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningAirFighter):
+ drawingWarPlane = new DrawningAirFighter(random.Next(300, 600), 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 + drawingWarPlane) != -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 ButtonAddWarPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane));
+ ///
+ /// Добавление теплохода
+ ///
+ ///
+ ///
+ private void ButtonAddAirFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirFighter));
+
+ private void ButtonRemovePlane_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) return;
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) 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;
+ DrawningWarPlane? plane = null;
+ int counter = 100;
+ while (plane == null)
+ {
+ plane = _company.GetRandomObjects();
+ counter--;
+ if (counter <= 0) break;
+ }
+ if (plane == null) return;
+ FormAirFighter form = new FormAirFighter();
+ form.SetPlane = plane;
+ form.ShowDialog();
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null) return;
+ pictureBox.Image = _company.Show();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.resx b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.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/ProjectAirFighter/ProjectAirFighter/Program.cs b/ProjectAirFighter/ProjectAirFighter/Program.cs
index fc87305..edac9cc 100644
--- a/ProjectAirFighter/ProjectAirFighter/Program.cs
+++ b/ProjectAirFighter/ProjectAirFighter/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectAirFighter
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormAirFighter());
+ Application.Run(new FormPlaneCollection());
}
}
}
\ No newline at end of file