diff --git a/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs b/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..94d28b4 --- /dev/null +++ b/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,118 @@ +using AntiAircraftGun.CollectionGenereticObject; +using AntiAircraftGun.Drawnings; + + +namespace AntiAircraftGun.CollectionGenereticObjects; + +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 80; + + /// + /// Ширина окна + /// + protected readonly int _pictureWidth; + + /// + /// Высота окна + /// + protected readonly int _pictureHeight; + + /// + /// Коллекция поездов + /// + protected ICollectionGenericObjects? _collection = null; + + /// + /// Вычисление максимального количества элементов, который можно разместить в окне + /// + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + + /// + /// Конструктор + /// + /// Ширина окна + /// Высота окна + /// Коллекция поездов + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + /// + /// Перегрузка оператора сложения для класса + /// + /// Компания + /// Добавляемый объект + /// + public static int operator +(AbstractCompany company, DrawningArmoredCar car) + { + return company._collection.Insert(car); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningArmoredCar? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningArmoredCar? 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) + { + DrawningArmoredCar? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/AntiAircraftGun/CollectionGenericObjects/CarBase.cs b/AntiAircraftGun/CollectionGenericObjects/CarBase.cs new file mode 100644 index 0000000..019daf9 --- /dev/null +++ b/AntiAircraftGun/CollectionGenericObjects/CarBase.cs @@ -0,0 +1,54 @@ +using AntiAircraftGun.CollectionGenereticObject; +using AntiAircraftGun.Drawnings; + + +namespace AntiAircraftGun.CollectionGenereticObjects; +/// +/// Реализация абстрактной компании - база бронемашин +/// +public class CarBase : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public CarBase(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; 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 n = 0; + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + DrawningArmoredCar? drawingTrans = _collection?.Get(n); + n++; + if (drawingTrans != null) + { + drawingTrans.SetPictureSize(_pictureWidth, _pictureHeight); + drawingTrans.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); + } + } + } + } +} diff --git a/AntiAircraftGun/CollectionGenereticObjects/ICollectionGenericObjects.cs b/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs similarity index 100% rename from AntiAircraftGun/CollectionGenereticObjects/ICollectionGenericObjects.cs rename to AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs diff --git a/AntiAircraftGun/CollectionGenereticObjects/MassiveGenereticObjects.cs b/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs similarity index 96% rename from AntiAircraftGun/CollectionGenereticObjects/MassiveGenereticObjects.cs rename to AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs index 1412e89..febd359 100644 --- a/AntiAircraftGun/CollectionGenereticObjects/MassiveGenereticObjects.cs +++ b/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - +using AntiAircraftGun.Drawnings; namespace AntiAircraftGun.CollectionGenereticObject; /// diff --git a/AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs b/AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs index ffe3fd0..c55e767 100644 --- a/AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs +++ b/AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs @@ -4,7 +4,7 @@ namespace AntiAircraftGun.Drawnings; /// /// Класс отвечающий за прорисовку и перемещение объекта - сущности /// -public class DrawningAntiAircraftGun : DrawningAircraftGun +public class DrawningAntiAircraftGun : DrawningArmoredCar { /// /// Конструктор diff --git a/AntiAircraftGun/Drawnings/DrawningAircraftGun.cs b/AntiAircraftGun/Drawnings/DrawningArmoredCar.cs similarity index 95% rename from AntiAircraftGun/Drawnings/DrawningAircraftGun.cs rename to AntiAircraftGun/Drawnings/DrawningArmoredCar.cs index 097115b..a629544 100644 --- a/AntiAircraftGun/Drawnings/DrawningAircraftGun.cs +++ b/AntiAircraftGun/Drawnings/DrawningArmoredCar.cs @@ -2,12 +2,12 @@ namespace AntiAircraftGun.Drawnings; -public class DrawningAircraftGun +public class DrawningArmoredCar { /// /// Класс-сущность /// - public EntityAircraftGun? EntityAircraftGun { get; protected set; } + public EntityArmoredCar? EntityAircraftGun { get; protected set; } /// /// Ширина @@ -62,7 +62,7 @@ public class DrawningAircraftGun /// /// Пустой конструктор /// - private DrawningAircraftGun() + private DrawningArmoredCar() { _pictureWidth = null; _pictureHeight = null; @@ -76,9 +76,9 @@ public class DrawningAircraftGun /// Скорость /// Вес /// Основной цвет - public DrawningAircraftGun(int speed, double weight, Color bodyColor) : this() + public DrawningArmoredCar(int speed, double weight, Color bodyColor) : this() { - EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor); + EntityAircraftGun = new EntityArmoredCar(speed, weight, bodyColor); } /// @@ -86,7 +86,7 @@ public class DrawningAircraftGun /// /// Ширина прорисовки зенитной установки /// Высота прорисовки зенитной установки - protected DrawningAircraftGun(int drawningGunWidth, int drawningGunHeight) : this() + protected DrawningArmoredCar(int drawningGunWidth, int drawningGunHeight) : this() { _drawningGunWidth = drawningGunWidth; _drawningGunHeight = drawningGunHeight; diff --git a/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs b/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs index 404ba48..f19de8a 100644 --- a/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs +++ b/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs @@ -2,7 +2,7 @@ /// /// Класс-сущность Зенитная установка /// -public class EntityAntiAircraftGun : EntityAircraftGun +public class EntityAntiAircraftGun : EntityArmoredCar { /// /// Дополниетльный цвет diff --git a/AntiAircraftGun/Entities/EntityAircraftGun.cs b/AntiAircraftGun/Entities/EntityArmoredCar.cs similarity index 89% rename from AntiAircraftGun/Entities/EntityAircraftGun.cs rename to AntiAircraftGun/Entities/EntityArmoredCar.cs index 03e77b0..9de4ea7 100644 --- a/AntiAircraftGun/Entities/EntityAircraftGun.cs +++ b/AntiAircraftGun/Entities/EntityArmoredCar.cs @@ -2,7 +2,7 @@ /// /// Класс - сущность Бронированная машина /// -public class EntityAircraftGun +public class EntityArmoredCar { /// /// Скорость @@ -27,7 +27,7 @@ public class EntityAircraftGun /// /// /// - public EntityAircraftGun(int speed, double weight, Color bodyColor) + public EntityArmoredCar(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; diff --git a/AntiAircraftGun/FormAntiAircraftGun.Designer.cs b/AntiAircraftGun/FormAntiAircraftGun.Designer.cs index 5f13f5f..02da2ee 100644 --- a/AntiAircraftGun/FormAntiAircraftGun.Designer.cs +++ b/AntiAircraftGun/FormAntiAircraftGun.Designer.cs @@ -33,8 +33,6 @@ buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); - buttonCreate = new Button(); - buttonCreatAircraftGun = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit(); @@ -97,28 +95,6 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 406); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(215, 32); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать зенитную установку"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // - // buttonCreatAircraftGun - // - buttonCreatAircraftGun.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreatAircraftGun.Location = new Point(233, 406); - buttonCreatAircraftGun.Name = "buttonCreatAircraftGun"; - buttonCreatAircraftGun.Size = new Size(215, 32); - buttonCreatAircraftGun.TabIndex = 6; - buttonCreatAircraftGun.Text = "Создать бронированную машину"; - buttonCreatAircraftGun.UseVisualStyleBackColor = true; - buttonCreatAircraftGun.Click += buttonCreatAircraftGun_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(800, 450); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreatAircraftGun); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxAntiAircraftGun); Name = "FormAntiAircraftGun"; Text = "Зенитная установка"; @@ -166,8 +140,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; - private Button buttonCreate; - private Button buttonCreatAircraftGun; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/AntiAircraftGun/FormAntiAircraftGun.cs b/AntiAircraftGun/FormAntiAircraftGun.cs index db4b09f..054de55 100644 --- a/AntiAircraftGun/FormAntiAircraftGun.cs +++ b/AntiAircraftGun/FormAntiAircraftGun.cs @@ -8,12 +8,26 @@ public partial class FormAntiAircraftGun : Form /// /// Поле объект для прорисовки объекта /// - private DrawningAircraftGun? _drawningAircraftGun; + private DrawningArmoredCar? _drawningAircraftGun; /// /// Стратегия перемещения /// private AbstractStrategy? _strategy; /// + /// Получение объекта + /// + public DrawningArmoredCar SetArmoredCar + { + set + { + _drawningAircraftGun = value; + _drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// конструктор формы /// public FormAntiAircraftGun() @@ -35,48 +49,6 @@ public partial class FormAntiAircraftGun : Form _drawningAircraftGun.DrawTransport(gr); pictureBoxAntiAircraftGun.Image = bmp; } - /// - /// Метод создания объекта - /// - /// - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningAircraftGun): - _drawningAircraftGun = new DrawningAircraftGun(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(DrawningAntiAircraftGun): - _drawningAircraftGun = new DrawningAntiAircraftGun(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; - } - - _drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); - _drawningAircraftGun.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(DrawningAntiAircraftGun)); - /// - /// Обработка кнопик Создать установку - /// - /// - /// - private void buttonCreatAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftGun)); - /// /// Перемещение объекта по форме /// diff --git a/AntiAircraftGun/FormArmoredCarCollection.Designer.cs b/AntiAircraftGun/FormArmoredCarCollection.Designer.cs new file mode 100644 index 0000000..5412d6c --- /dev/null +++ b/AntiAircraftGun/FormArmoredCarCollection.Designer.cs @@ -0,0 +1,167 @@ +namespace AntiAircraftGun +{ + partial class FormArmoredCarCollection + { + /// + /// 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() + { + groupBoxToools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToChek = new Button(); + buttonRemoveArmoredCar = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAntiAircraftGun = new Button(); + buttonAddArmoredCar = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxToools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxToools + // + groupBoxToools.Controls.Add(buttonRefresh); + groupBoxToools.Controls.Add(buttonGoToChek); + groupBoxToools.Controls.Add(buttonRemoveArmoredCar); + groupBoxToools.Controls.Add(maskedTextBox); + groupBoxToools.Controls.Add(buttonAddAntiAircraftGun); + groupBoxToools.Controls.Add(buttonAddArmoredCar); + groupBoxToools.Controls.Add(comboBoxSelectorCompany); + groupBoxToools.Dock = DockStyle.Right; + groupBoxToools.Location = new Point(1057, 0); + groupBoxToools.Name = "groupBoxToools"; + groupBoxToools.Size = new Size(210, 615); + groupBoxToools.TabIndex = 0; + groupBoxToools.TabStop = false; + groupBoxToools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 527); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(198, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + // + // buttonGoToChek + // + buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToChek.Location = new Point(6, 482); + buttonGoToChek.Name = "buttonGoToChek"; + buttonGoToChek.Size = new Size(198, 39); + buttonGoToChek.TabIndex = 5; + buttonGoToChek.Text = "Передать на тесты"; + buttonGoToChek.UseVisualStyleBackColor = true; + // + // buttonRemoveArmoredCar + // + buttonRemoveArmoredCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveArmoredCar.Location = new Point(6, 302); + buttonRemoveArmoredCar.Name = "buttonRemoveArmoredCar"; + buttonRemoveArmoredCar.Size = new Size(198, 60); + buttonRemoveArmoredCar.TabIndex = 4; + buttonRemoveArmoredCar.Text = "Удалить бронемашину"; + buttonRemoveArmoredCar.UseVisualStyleBackColor = true; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 249); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(198, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddAntiAircraftGun + // + buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAntiAircraftGun.Location = new Point(6, 164); + buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun"; + buttonAddAntiAircraftGun.Size = new Size(198, 60); + buttonAddAntiAircraftGun.TabIndex = 2; + buttonAddAntiAircraftGun.Text = "Добавление зениитной установки"; + buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; + // + // buttonAddArmoredCar + // + buttonAddArmoredCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddArmoredCar.Location = new Point(6, 86); + buttonAddArmoredCar.Name = "buttonAddArmoredCar"; + buttonAddArmoredCar.Size = new Size(198, 60); + buttonAddArmoredCar.TabIndex = 1; + buttonAddArmoredCar.Text = "Добавление бронемашины"; + buttonAddArmoredCar.UseVisualStyleBackColor = true; + // + // 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(198, 23); + comboBoxSelectorCompany.TabIndex = 0; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(1057, 615); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormArmoredCarCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1267, 615); + Controls.Add(pictureBox); + Controls.Add(groupBoxToools); + Name = "FormArmoredCarCollection"; + Text = "Коллекция бронемашин"; + groupBoxToools.ResumeLayout(false); + groupBoxToools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxToools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddArmoredCar; + private Button buttonAddAntiAircraftGun; + private PictureBox pictureBox; + private Button buttonRemoveArmoredCar; + private MaskedTextBox maskedTextBox; + private Button buttonRefresh; + private Button buttonGoToChek; + } +} \ No newline at end of file diff --git a/AntiAircraftGun/FormArmoredCarCollection.cs b/AntiAircraftGun/FormArmoredCarCollection.cs new file mode 100644 index 0000000..02ed2e9 --- /dev/null +++ b/AntiAircraftGun/FormArmoredCarCollection.cs @@ -0,0 +1,191 @@ +using AntiAircraftGun.CollectionGenereticObject; +using AntiAircraftGun.CollectionGenereticObjects; +using AntiAircraftGun.Drawnings; + + +namespace AntiAircraftGun; +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormArmoredCarCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormArmoredCarCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new CarBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Добавление бронерованной машины + /// + /// + /// + private void ButtonAddArmoredCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningArmoredCar)); + + /// + /// Добавление зенитной установки + /// + /// + /// + private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningArmoredCar drawningArmoredCar; + switch (type) + { + case nameof(DrawningArmoredCar): + drawningArmoredCar = new DrawningArmoredCar(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningAntiAircraftGun): + // вызов диалогового окна для выбора цвета + drawningArmoredCar = new DrawningAntiAircraftGun(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 + drawningArmoredCar != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + _ = MessageBox.Show(drawningArmoredCar.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 ButtonRemoveArmoredCar_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox.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; + } + + DrawningArmoredCar? armoredcar = null; + int counter = 100; + while (armoredcar == null) + { + armoredcar = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (armoredcar == null) + { + return; + } + + FormAntiAircraftGun form = new() + { + SetArmoredCar = armoredcar + }; + + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/AntiAircraftGun/FormArmoredCarCollection.resx b/AntiAircraftGun/FormArmoredCarCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AntiAircraftGun/FormArmoredCarCollection.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/AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs b/AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs index 94b93bb..762d4dd 100644 --- a/AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs +++ b/AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs @@ -7,12 +7,12 @@ public class MoveableAircraftGun: IMoveableObject /// /// Поле-объект класса DrawningAircraftGun или его наследника /// - private readonly DrawningAircraftGun? _drawningAircraftGun = null; + private readonly DrawningArmoredCar? _drawningAircraftGun = null; /// /// Конструктор /// /// Объект класса DrawningTrans - public MoveableAircraftGun(DrawningAircraftGun trans) + public MoveableAircraftGun(DrawningArmoredCar trans) { _drawningAircraftGun = trans; }