using lab1.CollectionGenericObjects; using lab1.Drawnings; namespace lab1; /// ///Форма работы с компанией и её коллекцией /// public partial class FormTrackedVehicleCollection : Form { /// /// Компания /// private AbstractCompany? _company = null; /// /// Конструктор /// public FormTrackedVehicleCollection() { InitializeComponent(); } /// /// Выбор компании /// /// /// private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { case "Хранилище": _company = new TrackedVehicleSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } } /// /// Добавление гусеничной машины /// /// /// private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); /// /// Добавление истребителя /// /// /// private void ButtonAddEntityFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter)); /// /// Создание объекта класса-перемещения /// /// private void CreateObject(string type) { if (_company == null) { return; } Random random = new(); DrawningTrackedVehicle drawningTrackedVehicle; switch (type) { case nameof(DrawningTrackedVehicle): drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningEntityFighter): drawningTrackedVehicle = new DrawningEntityFighter(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 + drawningTrackedVehicle != -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 ButtonRemoveTrackedVehicle_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 button1_Click(object sender, EventArgs e) { if (_company == null) { return; } DrawningTrackedVehicle? fighter = null; int counter = 100; while (fighter == null) { fighter = _company.GetRandomObject(); counter--; if (counter <= 0) { break; } } if (fighter == null) { return; } FormFighter form = new() { SetTrackedVehicle = fighter }; form.ShowDialog(); } /// /// Перерисовка коллекции /// /// /// private void ButtonRefresh_Click_1(object sender, EventArgs e) { if (_company == null) { return; } pictureBox.Image = _company.Show(); } private void pictureBox1_Click(object sender, EventArgs e) { } private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) { } private void FormTrackedVehicleCollection_Load(object sender, EventArgs e) { } }