From 3d664c461e3ae0407704947b8a64d5a0df7f5b97 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Mon, 11 Mar 2024 13:38:15 +0300 Subject: [PATCH] LabWork3 --- .../AbstractCompany.cs | 102 +++++++++++ .../GunSharingService.cs | 61 ++++++ .../ICollectionGenericObjects.cs | 14 +- .../MassiveGenericObjects.cs | 55 ++++-- .../Drawnings/DrawningAntiAircrfatGun.cs | 4 + .../FormAntiAircraftGun.Designer.cs | 28 --- .../AntiAircraftGun/FormAntiAircraftGun.cs | 73 +++----- .../FormGunCollections.Designer.cs | 173 ++++++++++++++++++ .../AntiAircraftGun/FormGunCollections.cs | 160 ++++++++++++++++ .../AntiAircraftGun/FormGunCollections.resx | 120 ++++++++++++ AntiAircraftGun/AntiAircraftGun/Program.cs | 2 +- 11 files changed, 690 insertions(+), 102 deletions(-) create mode 100644 AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/FormGunCollections.resx diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..39cd4bf --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,102 @@ +using AntiAircraftGun.Drawnings; + +namespace AntiAircraftGun.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 130; + /// + /// Ширина окна + /// + 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, DrawningGun gun) + { + return company._collection.Insert(gun); + } + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningGun? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningGun? 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) + { + DrawningGun? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); + +} diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs new file mode 100644 index 0000000..8ae8bd0 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs @@ -0,0 +1,61 @@ +using AntiAircraftGun.Drawnings; + + +namespace AntiAircraftGun.CollectionGenericObjects; +/// +/// Класс, отвечающий за базу +/// +public class GunSharingService : AbstractCompany +{ + public GunSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + private int offsetX = 30; + /// + /// Отрисовка базы + /// + /// Графика + protected override void DrawBackgound(Graphics g) + { + Pen pen = new Pen(Color.Black, 4); + + int maxCountX = (_pictureWidth / _placeSizeWidth); + int maxCountY = (_pictureHeight / _placeSizeHeight); + + + for (int i = 0; i < maxCountX; i++) + { + for (int j = 0; j < maxCountY; j++) + { + g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth + i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight); + g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight, i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight); + g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight, _placeSizeWidth + i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight); + } + } + } + /// + /// Установка объекта в базу + /// + protected override void SetObjectsPosition() + { + int maxCountX = _pictureWidth / _placeSizeWidth; + int maxCountY = _pictureHeight / _placeSizeHeight; + + int boarderOffsetX = 10; + int boarderOffsetY = 10; + + int currentIndex = -1; + + for (int j = 0; j < maxCountY; j++) + { + for (int i = 0; i < maxCountX; i++) + { + currentIndex++; + if (_collection.Get(currentIndex) == null) continue; + + _collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight); + } + } + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs index a5a8ee6..1823d76 100644 --- a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntiAircraftGun.CollectionGenericObjects; +namespace AntiAircraftGun.CollectionGenericObjects; /// /// Интерфейс описания действий для набора хранимых объектов @@ -27,20 +21,20 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию /// /// Добавляемый объект /// Позиция /// 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/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs index 79e3b5e..9968009 100644 --- a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics; namespace AntiAircraftGun.CollectionGenericObjects; /// @@ -44,27 +40,64 @@ internal class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { // TODO проверка позиции + if (_collection[position] == null) + return null; return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { // TODO вставка в свободное место набора - return false; + for (int i = 0; i < Count; i++) + { + if (InsertingElementCollection(i, obj)) return i; + } + + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то // ищется свободное место после этой позиции и идет вставка туда // если нет после, ищем до // TODO вставка - return false; + if (InsertingElementCollection(position, obj)) return position; + + for (int i = position + 1; i < Count; i++) + { + if (InsertingElementCollection(i, obj)) return position; + } + + for (int i = position - 1; i >= 0; i--) + { + if (InsertingElementCollection(i, obj)) return position; + } + + return -1; } - public bool Remove(int position) + public T? Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null - return true; + if (_collection[position] == null) return null; + + T? temp = _collection[position]; + _collection[position] = null; + return temp; } + + /// + /// Если элемент массива пустой, то вставляем новый элемент + /// + /// Индекс элемента + /// Элемент + /// false - элемент массива != null, true - = null + private bool InsertingElementCollection(int index, T obj) + { + if (_collection[index] != null) return false; + + _collection[index] = obj; + return true; + } } diff --git a/AntiAircraftGun/AntiAircraftGun/Drawnings/DrawningAntiAircrfatGun.cs b/AntiAircraftGun/AntiAircraftGun/Drawnings/DrawningAntiAircrfatGun.cs index a0e45f8..fe4a7c5 100644 --- a/AntiAircraftGun/AntiAircraftGun/Drawnings/DrawningAntiAircrfatGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/Drawnings/DrawningAntiAircrfatGun.cs @@ -19,6 +19,10 @@ public class DrawningAntiAircraftGun:DrawningGun { EntityGun = new EntityAntiAircraftGun(speed,weight,bodyColor,optionalElementsColor,barrelLenth,hatchHeight,radar); } + /// + /// Прорисовка объекта + /// + /// public override void DrawTransport(Graphics g) { diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs index 54ca8fe..77be91a 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxAntiAircraftGun = new PictureBox(); - buttonCreate = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonRight = new Button(); - buttonCreateGun = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxAntiAircraftGun.TabIndex = 8; pictureBoxAntiAircraftGun.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 352); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(261, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать зенитную установку"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonDown // buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateGun - // - buttonCreateGun.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateGun.Location = new Point(288, 352); - buttonCreateGun.Name = "buttonCreateGun"; - buttonCreateGun.Size = new Size(203, 29); - buttonCreateGun.TabIndex = 7; - buttonCreateGun.Text = "Создать установку"; - buttonCreateGun.UseVisualStyleBackColor = true; - buttonCreateGun.Click += buttonCreateGun_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -147,12 +123,10 @@ ClientSize = new Size(939, 393); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateGun); Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonLeft); Controls.Add(buttonDown); - Controls.Add(buttonCreate); Controls.Add(pictureBoxAntiAircraftGun); Name = "FormAntiAircraftGun"; Text = "Зенитная установка"; @@ -163,12 +137,10 @@ #endregion private PictureBox pictureBoxAntiAircraftGun; - private Button buttonCreate; private Button buttonDown; private Button buttonLeft; private Button buttonUp; private Button buttonRight; - private Button buttonCreateGun; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs index 5f7fc0e..d878ced 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs @@ -9,15 +9,33 @@ namespace AntiAircraftGun /// Стратегия перемещения /// private AbstractStrategy? _abstractStrategy; - - + /// + /// Поле-объект для прорисовки объекта + /// private DrawningGun? _drawningGun; - + /// + /// Конуструктор формы + /// public FormAntiAircraftGun() { InitializeComponent(); _abstractStrategy = null; } + /// + /// Получение объекта + /// + public DrawningGun SetGun + { + set + { + _drawningGun = value; + _drawningGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + Draw(); + } + } + /// /// Метод рисования машины /// @@ -33,55 +51,6 @@ namespace AntiAircraftGun pictureBoxAntiAircraftGun.Image = bmp; _drawningGun.DrawTransport(gr); } - - private void CreateObj(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningGun): - _drawningGun = new DrawningGun(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): - _drawningGun = 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)), - random.Next(10, 100), - Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2))); - break; - } - _drawningGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); - _drawningGun.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _abstractStrategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - /// - /// Обработка нажатия "Создать зенитную установку" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - CreateObj(nameof(DrawningAntiAircraftGun)); - } - /// - /// Обработка нажатия "Создать установку" - /// - /// - /// - private void buttonCreateGun_Click(object sender, EventArgs e) - { - CreateObj(nameof(DrawningGun)); - } private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningGun == null) diff --git a/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs new file mode 100644 index 0000000..670dd83 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs @@ -0,0 +1,173 @@ +namespace AntiAircraftGun +{ + partial class FormGunCollections + { + /// + /// 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(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveGun = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAntiAircraftGun = new Button(); + buttonAddGun = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRefresh); + groupBox1.Controls.Add(buttonGoToCheck); + groupBox1.Controls.Add(buttonRemoveGun); + groupBox1.Controls.Add(maskedTextBox); + groupBox1.Controls.Add(buttonAddAntiAircraftGun); + groupBox1.Controls.Add(buttonAddGun); + groupBox1.Controls.Add(comboBoxSelectorCompany); + groupBox1.Dock = DockStyle.Right; + groupBox1.Location = new Point(940, 0); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(235, 669); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(32, 578); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(171, 70); + 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(32, 465); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(171, 70); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveGun + // + buttonRemoveGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveGun.Location = new Point(32, 364); + buttonRemoveGun.Name = "buttonRemoveGun"; + buttonRemoveGun.Size = new Size(171, 70); + buttonRemoveGun.TabIndex = 4; + buttonRemoveGun.Text = "Удалить установку"; + buttonRemoveGun.UseVisualStyleBackColor = true; + buttonRemoveGun.Click += ButtonRemoveGun_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(32, 292); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(171, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddAntiAircraftGun + // + buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAntiAircraftGun.Location = new Point(33, 191); + buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun"; + buttonAddAntiAircraftGun.Size = new Size(171, 70); + buttonAddAntiAircraftGun.TabIndex = 2; + buttonAddAntiAircraftGun.Text = "Добавление зенитной установки"; + buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; + buttonAddAntiAircraftGun.Click += ButtonAddAntiAircraftGun_Click; + // + // buttonAddGun + // + buttonAddGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddGun.Location = new Point(32, 106); + buttonAddGun.Name = "buttonAddGun"; + buttonAddGun.Size = new Size(171, 70); + buttonAddGun.TabIndex = 1; + buttonAddGun.Text = "Добавление установки"; + buttonAddGun.UseVisualStyleBackColor = true; + buttonAddGun.Click += ButtonAddGun_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(33, 43); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(171, 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(940, 669); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormGunCollections + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1175, 669); + Controls.Add(pictureBox); + Controls.Add(groupBox1); + Name = "FormGunCollections"; + Text = "Коллекция установок"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private Button buttonAddGun; + private ComboBox comboBoxSelectorCompany; + private MaskedTextBox maskedTextBox; + private Button buttonAddAntiAircraftGun; + private PictureBox pictureBox; + private Button buttonRemoveGun; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs new file mode 100644 index 0000000..df0e401 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs @@ -0,0 +1,160 @@ +using AntiAircraftGun.CollectionGenericObjects; +using AntiAircraftGun.Drawnings; + +namespace AntiAircraftGun; + +public partial class FormGunCollections : Form +{ + /// + /// + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormGunCollections() + { + InitializeComponent(); + } + /// + /// + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "База": + _company = new GunSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + /// + /// Создание объекта класса перемещения + /// + /// Тип создаваемого объекта + private void CreateObj(string type) + { + if (_company == null) + { + return; + } + + DrawningGun _drawningGun; + Random random = new(); + switch (type) + { + case nameof(DrawningGun): + _drawningGun = new DrawningGun(random.Next(100, 300), + random.Next(1000, 3000), SetColor(random)); + break; + case nameof(DrawningAntiAircraftGun): + _drawningGun = new DrawningAntiAircraftGun(random.Next(100, 300), + random.Next(1000, 3000), + SetColor(random), + SetColor(random), + random.Next(10, 100), + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + if (_company + _drawningGun!=-1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + /// + /// Получение цвета + /// + /// Случайные числа + /// + private static Color SetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) { color = dialog.Color; } + return color; + } + + private void ButtonAddGun_Click(object sender, EventArgs e) + { + CreateObj(nameof(DrawningGun)); + } + + private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) + { + CreateObj(nameof(DrawningAntiAircraftGun)); + } + + private void ButtonRemoveGun_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + if (string.IsNullOrEmpty(maskedTextBox.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos is DrawningGun) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningGun? gun = null; + int counter = 100; + while (gun == null) + { + gun = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (gun == null) + { + return; + } + + FormAntiAircraftGun form = new() + { + SetGun = gun, + }; + form.ShowDialog(); + + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/FormGunCollections.resx b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.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/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index 5abc523..948a487 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -11,7 +11,7 @@ namespace AntiAircraftGun // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAntiAircraftGun()); + Application.Run(new FormGunCollections()); } } } \ No newline at end of file -- 2.25.1