using AirBomber.CollectionGenericObjects; 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 AirBomber; public partial class FormBoatCollection : Form { /// /// Компания /// private AbstractCompany? _company; /// /// Конструктор /// public FormBoatCollection() { InitializeComponent(); } /// /// Выбор компании /// /// /// private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { case "Хранилище": _company = new BoatSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } } /// /// Создание объекта класса-перемещения /// /// Тип создаваемого объекта private void CreateObject(string type) { if (_company == null) { return; } DrawningBoat _drawningBoat; Random random = new(); switch (type) { case nameof(DrawningBoat): _drawningBoat = new DrawningBoat(random.Next(30, 70), random.Next(100, 500), GetColor(random)); break; case nameof(DrawningCatamaran): _drawningBoat = new DrawningCatamaran(random.Next(30, 70), random.Next(100, 500), GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } if (_company + _drawningBoat != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); } else { MessageBox.Show("Не удалось добавить объект"); } } /// /// Добавление обычного автомобиля /// /// /// private void buttonAddBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat)); /// /// Добавление спортивного автомобиля /// /// /// private void buttonAddCatamaran_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCatamaran)); /// /// Получение цвета /// /// Генератор случайных чисел /// 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 ButtonRemoveBoat_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) { return; } if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show(); } else { MessageBox.Show("Не удалось удалить объект"); } } /// /// Передача объекта в другую форму /// /// /// private void ButtonGoToCheck_Click(object sender, EventArgs e) { if (_company == null) { return; } DrawningBoat? airplane = null; int counter = 100; while (airplane == null) { airplane = _company.GetRandomObject(); counter--; if (counter <= 0) { break; } } if (airplane == null) { return; } FormCatamaran form = new FormCatamaran(); form.SetBoat = airplane; form.ShowDialog(); } /// /// Перерисовка коллекции /// /// /// private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) { return; } pictureBox.Image = _company.Show(); } }