diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..77409f4
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,123 @@
+using ProjectSeaplane.Drawnings;
+
+namespace ProjectSeaplane.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию самолётов
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 140;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 60;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningPlane plane)
+ {
+ if (company._collection == null)
+ {
+ return -1;
+ }
+ return company._collection.Insert(plane);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningPlane operator -(AbstractCompany company, int position)
+ {
+ if (company._collection == null)
+ {
+ return null;
+ }
+ return company._collection.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningPlane? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackgound(graphics);
+
+ SetObjectsPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningPlane? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs
index 034dbfa..63be330 100644
--- a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -22,7 +22,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -30,14 +30,14 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта по позиции
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs
index e970588..405596c 100644
--- a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,17 +1,21 @@
-namespace ProjectSeaplane.CollectionGenericObjects;
+using ProjectSeaplane.Drawnings;
+
+namespace ProjectSeaplane.CollectionGenericObjects;
///
/// Параметризованный набор объектов
///
/// Параметр: ограничение - ссылочный тип
public class MassiveGenericObjects : ICollectionGenericObjects
-where T : class
+ where T : class
{
///
/// Массив объектов, которые храним
///
private T?[] _collection;
+
public int Count => _collection.Length;
+
public int SetMaxCount
{
set
@@ -50,7 +54,7 @@ where T : class
}
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
for (int i = 0; i < Count; ++i)
{
@@ -63,7 +67,7 @@ where T : class
return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
for (int i = position; i < Count; i++)
{
@@ -84,9 +88,12 @@ where T : class
return -1;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
- if (position < 0 || position >= _collection.Count()) return null;
+ if (position < 0 || position >= _collection.Count())
+ {
+ return null;
+ }
if (_collection[position] != null)
{
T obj = _collection[position];
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlaneSharingService.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlaneSharingService.cs
new file mode 100644
index 0000000..6e80060
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlaneSharingService.cs
@@ -0,0 +1,66 @@
+using ProjectSeaplane.Drawnings;
+
+namespace ProjectSeaplane.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - плейншеринг
+///
+public class PlaneSharingService : AbstractCompany
+{
+ private List> locCoord = new List>();
+ private int countInRow;
+ private int countRow;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public PlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects? collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new Pen(Color.Brown);
+ int x = 1, y = 0;
+ while (y + _placeSizeHeight <= _pictureHeight)
+ {
+ int count = 0;
+ while (x + _placeSizeWidth <= _pictureWidth)
+ {
+ count++;
+ g.DrawLine(pen, x, y, x + _placeSizeWidth, y);
+ g.DrawLine(pen, x, y, x, y + _placeSizeHeight);
+ g.DrawLine(pen, x, y + _placeSizeHeight, x + _placeSizeWidth, y + _placeSizeHeight);
+ g.DrawLine(pen, x + _placeSizeWidth, y + _placeSizeHeight, x + _placeSizeWidth, y);
+ locCoord.Add(new Tuple(x, y));
+ x += _placeSizeWidth + 2;
+ }
+ countInRow = count;
+ x = 1;
+ y += _placeSizeHeight + 5;
+ countRow++;
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ if (locCoord == null || _collection == null)
+ {
+ return;
+ }
+ int row = countRow, col = 1;
+ for (int i = 0; i < _collection?.Count; i++, col++)
+ {
+ _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection?.Get(i)?.SetPosition(locCoord[row * countInRow - col].Item1 + 5, locCoord[row * countInRow - col].Item2 + 5);
+ if (col == countInRow)
+ {
+ col = 0;
+ row--;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
new file mode 100644
index 0000000..c25addc
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectSeaplane
+{
+ 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();
+ buttonAddSeaplane = new Button();
+ buttonAddPlane = 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(buttonAddSeaplane);
+ groupBoxTools.Controls.Add(buttonAddPlane);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(710, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(144, 529);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 429);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(126, 44);
+ 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, 346);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(126, 44);
+ 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(6, 265);
+ buttonRemovePlane.Name = "buttonRemovePlane";
+ buttonRemovePlane.Size = new Size(126, 44);
+ buttonRemovePlane.TabIndex = 4;
+ buttonRemovePlane.Text = "Удалить самолёт";
+ buttonRemovePlane.UseVisualStyleBackColor = true;
+ buttonRemovePlane.Click += ButtonRemovePlane_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(6, 208);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(126, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddSeaplane
+ //
+ buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddSeaplane.Location = new Point(6, 126);
+ buttonAddSeaplane.Name = "buttonAddSeaplane";
+ buttonAddSeaplane.Size = new Size(126, 44);
+ buttonAddSeaplane.TabIndex = 2;
+ buttonAddSeaplane.Text = "Добавление гидросамолёта";
+ buttonAddSeaplane.UseVisualStyleBackColor = true;
+ buttonAddSeaplane.Click += ButtonAddSeaplane_Click;
+ //
+ // buttonAddPlane
+ //
+ buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddPlane.Location = new Point(6, 78);
+ buttonAddPlane.Name = "buttonAddPlane";
+ buttonAddPlane.Size = new Size(126, 42);
+ buttonAddPlane.TabIndex = 1;
+ buttonAddPlane.Text = "Добавление самолёта";
+ buttonAddPlane.UseVisualStyleBackColor = true;
+ buttonAddPlane.Click += ButtonAddPlane_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, 22);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(126, 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(710, 529);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormPlaneCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(854, 529);
+ 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 buttonAddPlane;
+ private Button buttonAddSeaplane;
+ private Button buttonRemovePlane;
+ private MaskedTextBox maskedTextBoxPosition;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
new file mode 100644
index 0000000..d6367d8
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
@@ -0,0 +1,186 @@
+using ProjectSeaplane.CollectionGenericObjects;
+using ProjectSeaplane.Drawnings;
+
+namespace ProjectSeaplane;
+
+///
+/// Форма работы с компанией и её коллекцией
+///
+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 PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Добавление обычного самолёта
+ ///
+ ///
+ ///
+ private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
+
+ ///
+ /// Добавление гидросамолёта
+ ///
+ ///
+ ///
+ private void ButtonAddSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaplane));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningPlane _drawningPlane;
+ switch (type)
+ {
+ case nameof(DrawningPlane):
+ _drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningSeaplane):
+ _drawningPlane = new DrawningSeaplane(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 + _drawningPlane) != -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 ButtonRemovePlane_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;
+ }
+
+ DrawningPlane? plane = null;
+ int counter = 100;
+ while (plane == null)
+ {
+ plane = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (plane == null)
+ {
+ return;
+ }
+
+ FormSeaplane form = new FormSeaplane();
+ form.SetPlane = plane;
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+}
diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/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/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs
index e8589d4..0015250 100644
--- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs
+++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxSeaplane = new PictureBox();
- buttonCreateSeaplane = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
- buttonCreatePlane = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
@@ -45,27 +43,16 @@
pictureBoxSeaplane.Dock = DockStyle.Fill;
pictureBoxSeaplane.Location = new Point(0, 0);
pictureBoxSeaplane.Name = "pictureBoxSeaplane";
- pictureBoxSeaplane.Size = new Size(900, 500);
+ pictureBoxSeaplane.Size = new Size(900, 517);
pictureBoxSeaplane.TabIndex = 0;
pictureBoxSeaplane.TabStop = false;
//
- // buttonCreateSeaplane
- //
- buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateSeaplane.Location = new Point(12, 465);
- buttonCreateSeaplane.Name = "buttonCreateSeaplane";
- buttonCreateSeaplane.Size = new Size(196, 23);
- buttonCreateSeaplane.TabIndex = 1;
- buttonCreateSeaplane.Text = "Создать гидросамолёт";
- buttonCreateSeaplane.UseVisualStyleBackColor = true;
- buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrow_left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(768, 451);
+ buttonLeft.Location = new Point(768, 468);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
@@ -77,7 +64,7 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrow_up;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(808, 411);
+ buttonUp.Location = new Point(808, 428);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
@@ -89,7 +76,7 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrow_down;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(808, 451);
+ buttonDown.Location = new Point(808, 468);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4;
@@ -101,24 +88,13 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrow_right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(849, 451);
+ buttonRight.Location = new Point(849, 468);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreatePlane
- //
- buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreatePlane.Location = new Point(214, 465);
- buttonCreatePlane.Name = "buttonCreatePlane";
- buttonCreatePlane.Size = new Size(196, 23);
- buttonCreatePlane.TabIndex = 6;
- buttonCreatePlane.Text = "Создать самолёт";
- buttonCreatePlane.UseVisualStyleBackColor = true;
- buttonCreatePlane.Click += ButtonCreatePlane_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -143,15 +119,13 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(900, 500);
+ ClientSize = new Size(900, 517);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreatePlane);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateSeaplane);
Controls.Add(pictureBoxSeaplane);
Name = "FormSeaplane";
Text = "Гидросамолёт";
@@ -162,12 +136,10 @@
#endregion
private PictureBox pictureBoxSeaplane;
- private Button buttonCreateSeaplane;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
- private Button buttonCreatePlane;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs
index 566db95..ff242e0 100644
--- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs
+++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs
@@ -2,6 +2,7 @@
using ProjectSeaplane.MovementStrategy;
namespace ProjectSeaplane;
+
///
/// Форма работы с объектом "Спортивный автомобиль"
///
@@ -17,6 +18,21 @@ public partial class FormSeaplane : Form
///
private AbstractStrategy? _strategy;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningPlane SetPlane
+ {
+ set
+ {
+ _drawningPlane = value;
+ _drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Конструктор формы
///
@@ -27,7 +43,7 @@ public partial class FormSeaplane : Form
}
///
- /// Метод прорисовки машины
+ /// Метод прорисовки самолёта
///
private void Draw()
{
@@ -41,51 +57,6 @@ public partial class FormSeaplane : Form
pictureBoxSeaplane.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningPlane):
- _drawningPlane = new DrawningPlane(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(DrawningSeaplane):
- _drawningPlane = new DrawningSeaplane(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)));
- break;
- default:
- return;
- }
- _drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
- _drawningPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
-
- Draw();
- }
-
-
- ///
- /// Обработка нажатия кнопки "Создать гидросамолёт"
- ///
- ///
- ///
- private void ButtonCreateSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaplane));
-
- ///
- /// Обработка нажатия кнопки "Создать самолёт"
- ///
- ///
- ///
- private void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
@@ -131,6 +102,7 @@ public partial class FormSeaplane : Form
{
return;
}
+
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
@@ -145,6 +117,7 @@ public partial class FormSeaplane : Form
}
_strategy.SetData(new MoveablePlane(_drawningPlane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
}
+
if (_strategy == null)
{
return;
diff --git a/ProjectSeaplane/ProjectSeaplane/Program.cs b/ProjectSeaplane/ProjectSeaplane/Program.cs
index 4e58da8..0b08fb7 100644
--- a/ProjectSeaplane/ProjectSeaplane/Program.cs
+++ b/ProjectSeaplane/ProjectSeaplane/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectSeaplane
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormSeaplane());
+ Application.Run(new FormPlaneCollection());
}
}
}
\ No newline at end of file