diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..dd825a6 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,113 @@ +using SelfPropelledArtilleryUnit.Drawnings; + +namespace SelfPropelledArtilleryUnit.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 190; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 100; + + /// + /// Ширина окна + /// + 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, DrawningTank tank) + { + return company._collection.Insert(tank); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningTank? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningTank? 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) + { + DrawningTank? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs index 38d2d77..5e6d93b 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -28,7 +28,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -43,7 +43,7 @@ public interface ICollectionGenericObjects /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - bool Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs index 124d931..6f73281 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs @@ -16,8 +16,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } - + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } /// /// Конструктор @@ -29,30 +44,59 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - // TODO проверка позиции + if (position < 0 || position >= _collection.Length) + return null; return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { - // TODO вставка в свободное место набора - return false; + for (int i = 0; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + return -1; } public bool Insert(T obj, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до - // TODO вставка + if (position < 0 || position >= _collection.Length) + return false; + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + for (int i = position; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + for (int i = 0; i < position; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } return false; } - public bool Remove(int position) + public T? Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - return true; + if (position < 0 || position >= _collection.Length || _collection[position] == null) // проверка позиции и наличия объекта + return null; + T? temp = _collection[position]; + _collection[position] = null; + + return temp; } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs new file mode 100644 index 0000000..a49855e --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs @@ -0,0 +1,63 @@ +using SelfPropelledArtilleryUnit.Drawnings; +using SelfPropelledArtilleryUnit.CollectionGenericObjects; + +namespace SelfPropelledArtilleryUnit.CollectionGenericObjects; + +public class TankSharingService : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public TankSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + Pen pen = new(Color.Black, 2); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 45, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, j * _placeSizeHeight - _placeSizeHeight); + } + } + } + + protected override void SetObjectsPosition() + { + + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int locomotiveWidth = 0; + int locomotiveHeight = 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 * locomotiveWidth + 20, locomotiveHeight * _placeSizeHeight + 20); + } + + if (locomotiveWidth < width - 1) + locomotiveWidth++; + else + { + locomotiveWidth = 0; + locomotiveHeight--; + } + if (locomotiveHeight < 0) + { + return; + } + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs index 272f29b..e19f35f 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs @@ -30,12 +30,10 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormArtillery)); pictureBoxArtillery = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreateTank = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxArtillery).BeginInit(); @@ -50,17 +48,6 @@ pictureBoxArtillery.TabIndex = 0; pictureBoxArtillery.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 417); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(90, 23); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать САУ"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -109,17 +96,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateTank - // - buttonCreateTank.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTank.Location = new Point(117, 417); - buttonCreateTank.Name = "buttonCreateTank"; - buttonCreateTank.Size = new Size(138, 23); - buttonCreateTank.TabIndex = 6; - buttonCreateTank.Text = "Создать самоходку"; - buttonCreateTank.UseVisualStyleBackColor = true; - buttonCreateTank.Click += ButtonCreateTank_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -147,12 +123,10 @@ ClientSize = new Size(800, 461); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateTank); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxArtillery); Name = "FormArtillery"; Text = "Самоходка"; @@ -163,12 +137,10 @@ #endregion private PictureBox pictureBoxArtillery; - private Button buttonCreate; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button buttonCreateTank; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.cs index dba5af8..4ba36c9 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -22,6 +22,17 @@ namespace SelfPropelledArtilleryUnit /// Стратегия перемещения /// private AbstractStrategy? _strategy; + public DrawningTank SetTank + { + set + { + _drawningTank = value; + _drawningTank.SetPictureSize(pictureBoxArtillery.Width, pictureBoxArtillery.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormArtillery() { InitializeComponent(); @@ -41,44 +52,7 @@ namespace SelfPropelledArtilleryUnit _drawningTank.DrawTransport(gr); pictureBoxArtillery.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningTank): - _drawningTank = new DrawningTank(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(DrawningArtillery): - _drawningTank = new DrawningArtillery(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; - } - _drawningTank.SetPictureSize(pictureBoxArtillery.Width, pictureBoxArtillery.Height); - _drawningTank.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(DrawningArtillery)); - /// - /// Обработка нажатия кнопки "Создать самоходку" - /// - /// - /// - private void ButtonCreateTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank)); private void ButtonMove_Click(object sender, EventArgs e) { diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs new file mode 100644 index 0000000..ddefb7d --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace SelfPropelledArtilleryUnit +{ + partial class FormTankCollection + { + /// + /// 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(); + buttonGoToCheak = new Button(); + buttonRemoveTank = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddTank = new Button(); + buttonAddArtillery = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheak); + groupBoxTools.Controls.Add(buttonRemoveTank); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddTank); + groupBoxTools.Controls.Add(buttonAddArtillery); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(715, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(200, 508); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(12, 423); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(176, 41); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheak + // + buttonGoToCheak.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheak.Location = new Point(12, 337); + buttonGoToCheak.Name = "buttonGoToCheak"; + buttonGoToCheak.Size = new Size(176, 41); + buttonGoToCheak.TabIndex = 5; + buttonGoToCheak.Text = "Передать на тесты"; + buttonGoToCheak.UseVisualStyleBackColor = true; + buttonGoToCheak.Click += ButtonGoToCheak_Click; + // + // buttonRemoveTank + // + buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTank.Location = new Point(12, 215); + buttonRemoveTank.Name = "buttonRemoveTank"; + buttonRemoveTank.Size = new Size(176, 41); + buttonRemoveTank.TabIndex = 4; + buttonRemoveTank.Text = "Удалить танк"; + buttonRemoveTank.UseVisualStyleBackColor = true; + buttonRemoveTank.Click += ButtonRemoveTank_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(12, 186); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(176, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddTank + // + buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTank.Location = new Point(12, 82); + buttonAddTank.Name = "buttonAddTank"; + buttonAddTank.Size = new Size(176, 41); + buttonAddTank.TabIndex = 2; + buttonAddTank.Text = "Добавление танка"; + buttonAddTank.UseVisualStyleBackColor = true; + buttonAddTank.Click += ButtonAddTank_Click; + // + // buttonAddArtillery + // + buttonAddArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddArtillery.Location = new Point(12, 129); + buttonAddArtillery.Name = "buttonAddArtillery"; + buttonAddArtillery.Size = new Size(176, 41); + buttonAddArtillery.TabIndex = 1; + buttonAddArtillery.Text = "Добавление сау"; + buttonAddArtillery.UseVisualStyleBackColor = true; + buttonAddArtillery.Click += ButtonAddArtillery_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(12, 33); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(182, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(715, 508); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormTankCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(915, 508); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormTankCollection"; + Text = "Коллекция сау"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddTank; + private Button buttonAddArtillery; + private MaskedTextBox maskedTextBoxPosition; + private PictureBox pictureBox; + private Button buttonRemoveTank; + private Button buttonRefresh; + private Button buttonGoToCheak; + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs new file mode 100644 index 0000000..32f052a --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs @@ -0,0 +1,164 @@ + + +using SelfPropelledArtilleryUnit.CollectionGenericObjects; +using SelfPropelledArtilleryUnit.Drawnings; + +namespace SelfPropelledArtilleryUnit; + +public partial class FormTankCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormTankCollection() + { + InitializeComponent(); + } + /// + /// Выбор компании + /// + /// + /// + + + private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new TankSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningTank drawningTank; + switch (type) + { + case nameof(DrawningTank): + drawningTank = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningArtillery): + // TODO вызов диалогового окна для выбора цвета + drawningTank = new DrawningArtillery(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 + drawningTank !=-1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + private void ButtonAddTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank)); + + private void ButtonAddArtillery_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningArtillery)); + + + + private void ButtonRemoveTank_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 ButtonGoToCheak_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningTank? tank = null; + int counter = 100; + while (tank == null) + { + tank = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (tank == null) + { + return; + } + + FormArtillery form = new() + { + SetTank = tank + }; + form.ShowDialog(); + + + + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs index a4ffd66..25a66f7 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs @@ -11,7 +11,7 @@ namespace SelfPropelledArtilleryUnit // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormArtillery()); + Application.Run(new FormTankCollection()); } } } \ No newline at end of file