diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..1cca3fd --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,117 @@ +using ProjectAirFighter.Drawnings; + +namespace ProjectAirFighter.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию самолётов +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 100; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 86; + + /// + /// Ширина окна + /// + 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, DrawningAirCraft aircraft) + { + return company._collection.Insert(aircraft); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningAirCraft? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningAirCraft? 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) + { + DrawningAirCraft? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} + diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs new file mode 100644 index 0000000..a2c59ad --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs @@ -0,0 +1,64 @@ +using ProjectAirFighter.Drawnings; + +namespace ProjectAirFighter.CollectionGenericObjects; + +/// +/// Реализация абстрактной компании - СимбирФлот +/// +public class AirCraftAngar : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public AirCraftAngar(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + /// + /// Отрисовка хранилища + /// + /// Графика + int pamat_i = 0; + int pamat_j = 0; + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black, 4); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + pamat_i = i; + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + pamat_j = j; + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j)); + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1))); + } + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight))); + } + + + } + /// + /// Установка объекта в Ангар + /// + protected override void SetObjectsPosition() + { + int currentIndex = -1; + for (int j = pamat_j; j >= 0; j--) + { + for (int i = pamat_i; i >= 0; i--) + { + currentIndex++; + if (_collection?.Get(currentIndex) == null) continue; + + _collection.Get(currentIndex)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(currentIndex)?.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); + } + } + } +} + + + + diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..e5c620d --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,53 @@ +namespace ProjectAirFighter.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/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..db6fef0 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,116 @@ +namespace ProjectAirFighter.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } + + /// + /// Конструктор + /// + + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + if (position >= 0 && position < Count) + { + return _collection[position]; + } + + return null; + } + + public int Insert(T obj) + { + return Insert(obj, 0); + } + + public int Insert(T obj, int position) + { + + if (position < 0 || position >= Count) + { + return -1; + } + + if (_collection[position] != null) + { + bool pushed = false; + for (int index = position + 1; index < Count; index++) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + + if (!pushed) + { + for (int index = position - 1; index >= 0; index--) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + } + + if (!pushed) + { + return position; + } + } + + _collection[position] = obj; + return position; + } + + public T? Remove(int position) + { + if (position < 0 || position >= Count) + { + return null; + } + + if (_collection[position] == null) return null; + + T? temp = _collection[position]; + _collection[position] = null; + return temp; + } +} diff --git a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs index 745fcff..c082092 100644 --- a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs @@ -16,7 +16,7 @@ public class DrawningAirFighter : DrawningAirCraft /// Дополнительный цвет /// Признак наличия ПГО /// Признак наличия ракет - public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool pgo, bool rockets) : base(76, 80) + public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool pgo, bool rockets) : base(66, 74) { EntityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets); } diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs new file mode 100644 index 0000000..0df1b57 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectAirFighter +{ + partial class FormAirCraftCollection + { + /// + /// 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(); + buttonRemoveAirCraft = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddAirFighter = new Button(); + buttonAddAirCraft = 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(buttonRemoveAirCraft); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddAirFighter); + groupBoxTools.Controls.Add(buttonAddAirCraft); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(828, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(215, 622); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(17, 536); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(186, 49); + 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(17, 381); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(186, 49); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveAirCraft + // + buttonRemoveAirCraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveAirCraft.Location = new Point(17, 287); + buttonRemoveAirCraft.Name = "buttonRemoveAirCraft"; + buttonRemoveAirCraft.Size = new Size(186, 49); + buttonRemoveAirCraft.TabIndex = 4; + buttonRemoveAirCraft.Text = "Удаление самолёта"; + buttonRemoveAirCraft.UseVisualStyleBackColor = true; + buttonRemoveAirCraft.Click += ButtonRemoveAirCraft_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(17, 222); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(186, 27); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddAirFighter + // + buttonAddAirFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirFighter.Location = new Point(17, 147); + buttonAddAirFighter.Name = "buttonAddAirFighter"; + buttonAddAirFighter.Size = new Size(186, 49); + buttonAddAirFighter.TabIndex = 2; + buttonAddAirFighter.Text = "Добавление истребителя"; + buttonAddAirFighter.UseVisualStyleBackColor = true; + buttonAddAirFighter.Click += ButtonAddAirFighter_Click; + // + // buttonAddAirCraft + // + buttonAddAirCraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirCraft.Location = new Point(17, 92); + buttonAddAirCraft.Name = "buttonAddAirCraft"; + buttonAddAirCraft.Size = new Size(186, 49); + buttonAddAirCraft.TabIndex = 1; + buttonAddAirCraft.Text = "Добавление военного самолёта"; + buttonAddAirCraft.UseVisualStyleBackColor = true; + buttonAddAirCraft.Click += ButtonAddAirCraft_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(17, 26); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(186, 28); + 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(828, 622); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormAirCraftCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1043, 622); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormAirCraftCollection"; + Text = "Коллекция самолётов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddAirCraft; + private Button buttonAddAirFighter; + private PictureBox pictureBox; + private Button buttonRemoveAirCraft; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs new file mode 100644 index 0000000..6906aa9 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs @@ -0,0 +1,189 @@ +using ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Drawnings; + +namespace ProjectAirFighter; + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormAirCraftCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormAirCraftCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Ангар": + _company = new AirCraftAngar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Добавление самолёта + /// + /// + /// + private void ButtonAddAirCraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirCraft)); + + /// + /// Добавление истебителя + /// + /// + /// + private void ButtonAddAirFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirFighter)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningAirCraft drawningAirCraft; + switch (type) + { + case nameof(DrawningAirCraft): + drawningAirCraft = new DrawningAirCraft(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningAirFighter): + // TODO вызов диалогового окна для выбора цвета + drawningAirCraft = new DrawningAirFighter(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 + drawningAirCraft != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + _ = MessageBox.Show(drawningAirCraft.ToString()); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + 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 ButtonRemoveAirCraft_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; + } + + DrawningAirCraft? aircraft = null; + int counter = 100; + while (aircraft == null) + { + aircraft = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (aircraft == null) + { + return; + } + + FormAirFighter form = new() + { + SetAirCraft = aircraft + }; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.resx b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.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/FormAirFighter.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs index 92391be..23d8a4a 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(); - buttonСreateAirCraft = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxAirFighter.TabIndex = 0; pictureBoxAirFighter.TabStop = false; // - // buttonCreateAirFighter - // - buttonCreateAirFighter.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateAirFighter.Location = new Point(31, 470); - buttonCreateAirFighter.Name = "buttonCreateAirFighter"; - buttonCreateAirFighter.Size = new Size(174, 39); - buttonCreateAirFighter.TabIndex = 1; - buttonCreateAirFighter.Text = "Создать истребить\r\n"; - buttonCreateAirFighter.UseVisualStyleBackColor = true; - buttonCreateAirFighter.Click += ButtonCreateAirFighter_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonСreateAirCraft - // - buttonСreateAirCraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonСreateAirCraft.Location = new Point(242, 470); - buttonСreateAirCraft.Name = "buttonСreateAirCraft"; - buttonСreateAirCraft.Size = new Size(174, 39); - buttonСreateAirCraft.TabIndex = 6; - buttonСreateAirCraft.Text = "Создать самолёт"; - buttonСreateAirCraft.UseVisualStyleBackColor = true; - buttonСreateAirCraft.Click += buttonСreateAirCraft_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(800, 521); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonСreateAirCraft); Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreateAirFighter); Controls.Add(pictureBoxAirFighter); Name = "FormAirFighter"; Text = "Истребитель"; @@ -163,12 +137,10 @@ #endregion private PictureBox pictureBoxAirFighter; - private Button buttonCreateAirFighter; private Button buttonLeft; private Button buttonUp; private Button buttonRight; private Button buttonDown; - private Button buttonСreateAirCraft; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs index 233fa64..dec64cf 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs @@ -18,6 +18,21 @@ public partial class FormAirFighter : Form /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawningAirCraft SetAirCraft + { + set + { + _drawningAirCraft = value; + _drawningAirCraft.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -43,50 +58,6 @@ public partial class FormAirFighter : Form pictureBoxAirFighter.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningAirCraft): - _drawningAirCraft = new DrawningAirCraft(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(DrawningAirFighter): - _drawningAirCraft = new DrawningAirFighter(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; - } - _drawningAirCraft.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); - _drawningAirCraft.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 buttonСreateAirCraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirCraft)); - - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/ProjectAirFighter/ProjectAirFighter/Program.cs b/ProjectAirFighter/ProjectAirFighter/Program.cs index fc87305..7addb2e 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 FormAirCraftCollection()); } } } \ No newline at end of file