diff --git a/ProjectAirFighter/ProjectAirFighter/AdNum.cs b/ProjectAirFighter/ProjectAirFighter/AdNum.cs new file mode 100644 index 0000000..fb0c08c --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/AdNum.cs @@ -0,0 +1,16 @@ +using ProjectAirFighter.Drawning; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter; + +public class AdNum + where T : DrawningAirFighter +{ + public void Nothing(){ + } +} diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..a703a8e --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,116 @@ +using ProjectAirFighter.CollectionGenericObject; +using ProjectAirFighter.Drawning; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места(ширина) + /// + public readonly int _placeSizeWidth = 140; + /// + /// Размер места(высота) + /// + public readonly int _placeSizeHeight = 160; + + /// + /// Ширина окна + /// + 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 - 3; + } + + /// + /// Перегрузка оператора сложения для класса + /// + /// + /// + /// + public static int operator +(AbstractCompany company, DrawningWarPlane warPlane) + { + return company._collection.Insert(warPlane); + } + + /// + /// Перегрузка оператора удаление для класса + /// + /// + /// + /// + public static DrawningWarPlane operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningWarPlane? 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) + { + DrawningWarPlane? 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/ICollectionGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..df1b6ce --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.CollectionGenericObject; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// +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..b398a65 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,106 @@ +using ProjectAirFighter.CollectionGenericObject; +using ProjectAirFighter.CollectionGenericObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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) { _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) + { + 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) + { + if (position < 0 || position >= Count) + return -1; + + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + + int temp = position + 1; + while (temp < Count) + { + if (_collection[temp] == null) + { + _collection[temp] = obj; + return temp; + } + temp++; + } + + temp = position - 1; + while (temp > 0) + { + if (_collection[temp] == null) + { + _collection[temp] = obj; + return temp; + } + temp--; + } + + return -1; + } + + 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/CollectionGenericObjects/WarPlaneBase.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/WarPlaneBase.cs new file mode 100644 index 0000000..adec8a4 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/WarPlaneBase.cs @@ -0,0 +1,62 @@ +using ProjectAirFighter.CollectionGenericObject; +using ProjectAirFighter.Drawning; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.CollectionGenericObjects; + +public class WarPlaneBase : AbstractCompany +{ + public WarPlaneBase(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = width - 1; + int curHeight = height - 1; + + 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 + 10, curHeight * _placeSizeHeight + 5); + } + + if (curWidth > 0) + curWidth--; + else + { + curHeight--; + curWidth = width - 1; + } + if (curHeight < 0) + { + return; + + } + } + } +} + + diff --git a/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs b/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs index 23ec6f1..61248ee 100644 --- a/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs +++ b/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs @@ -42,7 +42,7 @@ public class DrawningWarPlane /// /// Высота прорисовки самолета /// - private readonly int _drawningWarPlaneHeight = 140; + private readonly int _drawningWarPlaneHeight = 140; /// /// Координаты X объекта @@ -63,7 +63,8 @@ public class DrawningWarPlane /// Ширина объекта /// public int GetWigdth => _drawningWarPlaneWidth; - private DrawningWarPlane() { + private DrawningWarPlane() + { _pictureHeight = null; _pictureWidth = null; _startPosX = null; @@ -78,18 +79,18 @@ public class DrawningWarPlane public DrawningWarPlane(int speed, double weight, Color bodyColor) : this() { EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor); - + } /// /// Конструктор для наслдеников /// /// Высота прорисовки самолета /// Ширина прорисовки самолета - public DrawningWarPlane(int drawningWarPlaneWidth,int drawningWarPlaneHeight) : this() + public DrawningWarPlane(int drawningWarPlaneWidth, int drawningWarPlaneHeight) : this() { _drawningWarPlaneWidth = drawningWarPlaneWidth; _drawningWarPlaneHeight = drawningWarPlaneHeight; - + } @@ -174,7 +175,7 @@ public class DrawningWarPlane /// /// Направление /// true - перемещение выполнено, false - перемещение невозможно - public bool MoveTransport(DirectionType direction) + public virtual bool MoveTransport(DirectionType direction) { if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { @@ -263,6 +264,6 @@ public class DrawningWarPlane g.FillPolygon(br, rearWingUpper); g.FillPolygon(br, rearWingLower); - + } } diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs index 71347d9..bcda91a 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxAirFighter = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreateWarPlane = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxAirFighter.TabIndex = 0; pictureBoxAirFighter.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(0, 522); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(232, 23); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать истребитель"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -112,17 +99,6 @@ buttonRight.ClientSizeChanged += FormAirFighter_SizeChanged; buttonRight.Click += ButtonMove_Click; // - // buttonCreateWarPlane - // - buttonCreateWarPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateWarPlane.Location = new Point(238, 522); - buttonCreateWarPlane.Name = "buttonCreateWarPlane"; - buttonCreateWarPlane.Size = new Size(232, 23); - buttonCreateWarPlane.TabIndex = 6; - buttonCreateWarPlane.Text = "Создать военный самолет"; - buttonCreateWarPlane.UseVisualStyleBackColor = true; - buttonCreateWarPlane.Click += buttonCreateWarPlane_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -150,12 +126,10 @@ ClientSize = new Size(924, 557); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateWarPlane); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxAirFighter); Name = "FormAirFighter"; Text = "Истребитель"; @@ -167,12 +141,10 @@ #endregion private PictureBox pictureBoxAirFighter; - private Button buttonCreate; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button buttonCreateWarPlane; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs index 6a77d56..86c1867 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs @@ -26,6 +26,17 @@ namespace ProjectAirFighter /// /// Конструктор формы /// + + public DrawningWarPlane SetWarPlane{ + set + { + _drawningWarPlane = value; + _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormAirFighter() { InitializeComponent(); @@ -43,45 +54,7 @@ namespace ProjectAirFighter _drawningWarPlane.DrawTransport(gr); pictureBoxAirFighter.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningWarPlane): - _drawningWarPlane = new DrawningWarPlane(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): - _drawningWarPlane = 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; - } - _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, - pictureBoxAirFighter.Height); - _drawningWarPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - private void ButtonCreate_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningAirFighter)); - } - private void buttonCreateWarPlane_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningWarPlane)); - } + private void ButtonMove_Click(object sender, EventArgs e) { diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs new file mode 100644 index 0000000..fe4b41d --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs @@ -0,0 +1,168 @@ +namespace ProjectAirFighter +{ + partial class FormWarPlaneCollection + { + /// + /// 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() + { + groupBox1 = new GroupBox(); + button1 = new Button(); + buttonGoToCheck = new Button(); + buttonRemove = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddAirFighter = new Button(); + buttonAddWarPlane = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(button1); + groupBox1.Controls.Add(buttonGoToCheck); + groupBox1.Controls.Add(buttonRemove); + groupBox1.Controls.Add(maskedTextBoxPosition); + groupBox1.Controls.Add(buttonAddAirFighter); + groupBox1.Controls.Add(buttonAddWarPlane); + groupBox1.Controls.Add(comboBoxSelectorCompany); + groupBox1.Dock = DockStyle.Right; + groupBox1.Location = new Point(626, 0); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(174, 450); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Инструменты"; + // + // button1 + // + button1.Location = new Point(6, 400); + button1.Name = "button1"; + button1.Size = new Size(162, 44); + button1.TabIndex = 6; + button1.Text = "Обновить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(6, 326); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(162, 44); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тест"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemove + // + buttonRemove.Location = new Point(6, 249); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(162, 44); + buttonRemove.TabIndex = 4; + buttonRemove.Text = "Удалить самолет"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += ButtonRemove_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(6, 220); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(162, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddAirFighter + // + buttonAddAirFighter.Location = new Point(6, 130); + buttonAddAirFighter.Name = "buttonAddAirFighter"; + buttonAddAirFighter.Size = new Size(162, 44); + buttonAddAirFighter.TabIndex = 2; + buttonAddAirFighter.Text = "Добавление истребителя"; + buttonAddAirFighter.UseVisualStyleBackColor = true; + buttonAddAirFighter.Click += ButtonAddAirFighter_Click; + // + // buttonAddWarPlane + // + buttonAddWarPlane.Location = new Point(6, 72); + buttonAddWarPlane.Name = "buttonAddWarPlane"; + buttonAddWarPlane.Size = new Size(162, 52); + 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(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(162, 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(626, 450); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormWarPlaneCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBox); + Controls.Add(groupBox1); + Name = "FormWarPlaneCollection"; + Text = "Коллекция военных самолетов"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private ComboBox comboBoxSelectorCompany; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddAirFighter; + private Button buttonAddWarPlane; + private PictureBox pictureBox; + private Button buttonRemove; + private Button buttonGoToCheck; + private Button button1; + } +} \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs new file mode 100644 index 0000000..aa641ff --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs @@ -0,0 +1,153 @@ +using ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Drawning; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectAirFighter; + +public partial class FormWarPlaneCollection : Form +{ + private AbstractCompany? _company; + public FormWarPlaneCollection() + { + InitializeComponent(); + } + + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new WarPlaneBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningWarPlane drawningWarPlane; + switch (type) + { + case nameof(DrawningWarPlane): + drawningWarPlane = new DrawningWarPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningAirFighter): + drawningWarPlane = 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 + drawningWarPlane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + + } + + private void ButtonAddWarPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane)); + + private void ButtonAddAirFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirFighter)); + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + 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 ButtonRemove_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; + } + + DrawningWarPlane? warPlane = null; + + int counter = 100; + while(warPlane == null) + { + warPlane = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (warPlane == null) { + return; + } + + FormAirFighter form = new() + { + SetWarPlane = warPlane + }; + form.ShowDialog(); + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} + + diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.resx b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.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..9361ddf 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 FormWarPlaneCollection()); } } } \ No newline at end of file