using System.Windows.Forms; using ProjectCruiser.DrawningSamples; namespace ProjectCruiser; public partial class ServiceForm2 : Form { // Компания private AbstractCompany? _company; public ServiceForm2() { InitializeComponent(); _company = null; } // Выбор компании private void SelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxArrList.Text) { case "Storage": _company = new ShipSharingService(pictureBox.Width, pictureBox.Height, new ArrayGenObj()); break; } } // Color picker private static Color pickColor(Random r) { Color cl = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256)); ColorDialog dialog = new(); if (dialog.ShowDialog() == DialogResult.OK) { cl = dialog.Color; } return cl; } // Добавление обычного корабля private void btnAddBase_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBase)); // Добавление продвинутого private void btnAddAdvanced_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCruiser)); // Создание объекта класса-перемещения private void CreateObject(string type) { if (_company == null) { return; } Random random = new(); DrawningBase drawningCar; switch (type) { case nameof(DrawningBase): drawningCar = new DrawningBase(random.Next(100, 300), random.Next(1000, 3000), pickColor(random)); break; case nameof(DrawningCruiser): // (TODO) вызов диалогового окна для выбора цвета >>> drawningCar = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), pickColor(random), pickColor(random), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } if (_company + drawningCar != -1) { MessageBox.Show("> Object was added"); pictureBox.Image = _company.Show(); } else { MessageBox.Show("[!] Failed to add object"); } } // Удаление объекта private void btnRemoveCar_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) return; if (MessageBox.Show("[*] Remove object: Are you sure?", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return; int pos = Convert.ToInt32(maskedTextBoxPosition.Text); if (_company - Convert.ToInt32(maskedTextBoxPosition.Text) != null) { MessageBox.Show("> Object was removed"); pictureBox.Image = _company.Show(); } else MessageBox.Show("[!] Failed to remove object"); } // Передача объекта в другую форму private void btnChooseforTest_Click(object sender, EventArgs e) { if (_company == null) { return; } DrawningBase? car = null; int counter = 100; while (car == null) { car = _company.GetRandomObject(); counter--; if (counter <= 0) { break; } } if (car == null) { return; } OceanForm1 form = new() { SetShip = car }; form.ShowDialog(); } // Перерисовка коллекции private void btnRefresh_Click(object sender, EventArgs e) { if (_company == null) { return; } pictureBox.Image = _company.Show(); } }