diff --git a/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs b/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..27ff7f5 --- /dev/null +++ b/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,102 @@ +using ProjectStormtrooper.Drawnings; + +namespace ProjectStormtrooper.CollectionGenericObjects; +/// +/// Абстракция компании, хранящий коллекцию штурмовика +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 155; + /// + /// Ширина окна + /// + 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, DrawningStormtrooperBase stormtrooper) + { + return company._collection.Insert(stormtrooper); + } + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningStormtrooperBase operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningStormtrooperBase? 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) + { + DrawningStormtrooperBase? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics graphics); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectStormtrooper/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectStormtrooper/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..46edeb4 --- /dev/null +++ b/ProjectStormtrooper/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper.CollectionGenericObjects; +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + /// + /// Добавление объекта в коллекцию + /// + /// Добавление объекта + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавление объекта + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно,false - удаление не удалось + T? Remove(int position); + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); + +} diff --git a/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..21093ee --- /dev/null +++ b/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper.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 >= _collection.Length || position < 0) return null; + return _collection[position]; + } + + public int Insert(T obj) + { + // TODO вставка в свободное место набора + int index = 0; + while ( index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + index++; + } + return -1; + } + + public int Insert(T obj, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + // TODO вставка + if (position >= _collection.Length || position < 0) return -1; + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + int index = position + 1; + while(index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + index++; + } + index = position - 1; + while ( index >= 0) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + index--; + } + return -1; + } + + public T? Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if(position >= _collection.Length || position < 0) return null; + T temp = _collection[position]; + _collection[position] = null; + return temp; + } +} diff --git a/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs b/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs new file mode 100644 index 0000000..4fed574 --- /dev/null +++ b/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs @@ -0,0 +1,66 @@ +using ProjectStormtrooper.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper.CollectionGenericObjects; +/// +/// Реализация абстрактной компании +/// + +public class StormtrooperSharingService : AbstractCompany +{ + public StormtrooperSharingService(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 + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15 + _placeSizeWidth - 55, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15, j * _placeSizeHeight - _placeSizeHeight); + } + } + } + /// + /// Расстановка объектов + /// + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + int curWidth = width - 1; + int curHeight = 0; + 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 + 15, curHeight * _placeSizeHeight + 3); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } + } +} + diff --git a/ProjectStormtrooper/FormStormtrooper.Designer.cs b/ProjectStormtrooper/FormStormtrooper.Designer.cs index b755050..55d4552 100644 --- a/ProjectStormtrooper/FormStormtrooper.Designer.cs +++ b/ProjectStormtrooper/FormStormtrooper.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxStormtrooper = new PictureBox(); - buttonCreateStormtrooper = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreateStormtrooperBase = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxStormtrooper.TabIndex = 0; pictureBoxStormtrooper.TabStop = false; // - // buttonCreateStormtrooper - // - buttonCreateStormtrooper.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateStormtrooper.Location = new Point(12, 562); - buttonCreateStormtrooper.Name = "buttonCreateStormtrooper"; - buttonCreateStormtrooper.Size = new Size(162, 23); - buttonCreateStormtrooper.TabIndex = 1; - buttonCreateStormtrooper.Text = "Создать штурмовик"; - buttonCreateStormtrooper.UseVisualStyleBackColor = true; - buttonCreateStormtrooper.Click += ButtonCreateStormtrooper_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateStormtrooperBase - // - buttonCreateStormtrooperBase.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateStormtrooperBase.Location = new Point(198, 562); - buttonCreateStormtrooperBase.Name = "buttonCreateStormtrooperBase"; - buttonCreateStormtrooperBase.Size = new Size(180, 23); - buttonCreateStormtrooperBase.TabIndex = 6; - buttonCreateStormtrooperBase.Text = "Создать штурмовик базовый"; - buttonCreateStormtrooperBase.UseVisualStyleBackColor = true; - buttonCreateStormtrooperBase.Click += ButtonCreateStormtrooperBase_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(925, 597); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateStormtrooperBase); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreateStormtrooper); Controls.Add(pictureBoxStormtrooper); Name = "FormStormtrooper"; Text = "Штурмовик"; @@ -162,12 +136,10 @@ #endregion private PictureBox pictureBoxStormtrooper; - private Button buttonCreateStormtrooper; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button buttonCreateStormtrooperBase; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectStormtrooper/FormStormtrooper.cs b/ProjectStormtrooper/FormStormtrooper.cs index f329f41..6963f15 100644 --- a/ProjectStormtrooper/FormStormtrooper.cs +++ b/ProjectStormtrooper/FormStormtrooper.cs @@ -10,13 +10,24 @@ public partial class FormStormtrooper : Form /// Поле-объект для прорисовки объекта /// private DrawningStormtrooperBase? _drawningStormtrooperBase; - /// - /// Стратегия перемещения - /// + /// + /// Стратегия перемещения + /// private AbstractStrategy? _strategy; /// /// Конструктор формы /// + public DrawningStormtrooperBase SetStormtrooper + { + set + { + _drawningStormtrooperBase = value; + _drawningStormtrooperBase.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormStormtrooper() { InitializeComponent(); @@ -39,49 +50,6 @@ public partial class FormStormtrooper : Form _drawningStormtrooperBase.DrawTransport(gr); pictureBoxStormtrooper.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawingStormtrooper): - _drawningStormtrooperBase = new DrawingStormtrooper(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; - case nameof(DrawningStormtrooperBase): - _drawningStormtrooperBase = new DrawningStormtrooperBase(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - default: - return; - - } - _drawningStormtrooperBase.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); - _drawningStormtrooperBase.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - - } - /// - /// Обработка нажатия кнопки "Создать штурмовик" - /// - /// - /// - private void ButtonCreateStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingStormtrooper)); - /// - /// Обработка нажатия кнопки "Создать базовый штурмовик" - /// - /// - /// - private void ButtonCreateStormtrooperBase_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooperBase)); - /// /// Перемещение объкта по форме(нажатие кнопок навигации) @@ -157,4 +125,4 @@ public partial class FormStormtrooper : Form } } } - + diff --git a/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs b/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs new file mode 100644 index 0000000..3a733a3 --- /dev/null +++ b/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectStormtrooper +{ + partial class FormStormtrooperCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveStormtrooper = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddStormtrooper = new Button(); + buttonAddStormtrooperBase = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveStormtrooper); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddStormtrooper); + groupBoxTools.Controls.Add(buttonAddStormtrooperBase); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(919, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(165, 861); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 381); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(153, 32); + 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(6, 309); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(153, 36); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveStormtrooper + // + buttonRemoveStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveStormtrooper.Location = new Point(6, 248); + buttonRemoveStormtrooper.Name = "buttonRemoveStormtrooper"; + buttonRemoveStormtrooper.Size = new Size(153, 33); + buttonRemoveStormtrooper.TabIndex = 4; + buttonRemoveStormtrooper.Text = "Удалить Штурмовик"; + buttonRemoveStormtrooper.UseVisualStyleBackColor = true; + buttonRemoveStormtrooper.Click += ButtonRemoveStormtrooper_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 208); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(153, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddStormtrooper + // + buttonAddStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddStormtrooper.Location = new Point(6, 139); + buttonAddStormtrooper.Name = "buttonAddStormtrooper"; + buttonAddStormtrooper.Size = new Size(153, 45); + buttonAddStormtrooper.TabIndex = 2; + buttonAddStormtrooper.Text = "Добавление Штурмовика"; + buttonAddStormtrooper.UseVisualStyleBackColor = true; + buttonAddStormtrooper.Click += ButtonAddStormtrooper_Click; + // + // buttonAddStormtrooperBase + // + buttonAddStormtrooperBase.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddStormtrooperBase.Location = new Point(6, 78); + buttonAddStormtrooperBase.Name = "buttonAddStormtrooperBase"; + buttonAddStormtrooperBase.Size = new Size(153, 39); + buttonAddStormtrooperBase.TabIndex = 1; + buttonAddStormtrooperBase.Text = "Добавление базового Штурмовика"; + buttonAddStormtrooperBase.UseVisualStyleBackColor = true; + buttonAddStormtrooperBase.Click += ButtonAddStormtrooperBase_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(159, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(919, 861); + pictureBox.TabIndex = 3; + pictureBox.TabStop = false; + // + // FormStormtrooperCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1084, 861); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormStormtrooperCollection"; + Text = "Коллекция штурмовиков"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddStormtrooperBase; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddStormtrooper; + private PictureBox pictureBox; + private Button buttonRemoveStormtrooper; + private MaskedTextBox maskedTextBox; + private Button buttonGoToCheck; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectStormtrooper/FormStormtrooperCollection.cs b/ProjectStormtrooper/FormStormtrooperCollection.cs new file mode 100644 index 0000000..5d99278 --- /dev/null +++ b/ProjectStormtrooper/FormStormtrooperCollection.cs @@ -0,0 +1,189 @@ +using ProjectStormtrooper.CollectionGenericObjects; +using ProjectStormtrooper.Drawnings; +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 ProjectStormtrooper; +/// +/// Форма работы с компанией и ее коллекцией +/// + +public partial class FormStormtrooperCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company; + /// + /// Конструктор + /// + public FormStormtrooperCollection() + { + InitializeComponent(); + } + + + /// + /// Выбор компании + /// + /// + /// + private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new StormtrooperSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + /// + /// Создание объекта класса-перемещения + /// + /// + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningStormtrooperBase drawningStormtrooperBase; + switch (type) + { + case nameof(DrawingStormtrooper): + drawningStormtrooperBase = new DrawingStormtrooper(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; + case nameof(DrawningStormtrooperBase): + drawningStormtrooperBase = new DrawningStormtrooperBase(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + default: + return; + + } + if (_company + drawningStormtrooperBase != -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 ButtonAddStormtrooperBase_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooperBase)); + /// + /// Добавление штурмовика + /// + /// + /// + private void ButtonAddStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingStormtrooper)); + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + 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; + } + DrawningStormtrooperBase? stormtrooper = null; + int counter = 100; + while (stormtrooper == null) + { + stormtrooper = _company.GetRandomObject(); + counter--; + if (counter < -0) + { + break; + } + } + if (stormtrooper == null) + { + return; + } + FormStormtrooper form = new() + { + SetStormtrooper = stormtrooper + }; + form.ShowDialog(); + } + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectStormtrooper/FormStormtrooperCollection.resx b/ProjectStormtrooper/FormStormtrooperCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectStormtrooper/FormStormtrooperCollection.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/ProjectStormtrooper/Program.cs b/ProjectStormtrooper/Program.cs index 3db6e41..41063d3 100644 --- a/ProjectStormtrooper/Program.cs +++ b/ProjectStormtrooper/Program.cs @@ -11,7 +11,7 @@ namespace ProjectStormtrooper // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormStormtrooper()); + Application.Run(new FormStormtrooperCollection()); } } } \ No newline at end of file