using ProjectCruiser.CollectionGenericObjects; using ProjectCruiser.Drawnings; namespace ProjectCruiser { public partial class FormCruisersCollection : Form { /// /// Компания /// private AbstractCompany? _company = null; /// /// Конструктор /// public FormCruisersCollection() { InitializeComponent(); } /// /// /// /// /// private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { case "хранилище": _company = new CruiserDockingService(pictureBoxCruiser.Width, pictureBoxCruiser.Height, new MassiveGenericObjects()); break; } } /// /// Создание объекта класса-перемещения /// /// Тип создаваемого объекта private void CreateObject(string type) { if (_company == null) { return; } Random random = new(); DrawningCruiser drawningCruiser; switch (type) { case nameof(DrawningCruiser): drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningMilitaryCruiser): drawningCruiser = new DrawningMilitaryCruiser(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } if (_company + drawningCruiser != -1) { MessageBox.Show("объект добавлен"); pictureBoxCruiser.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 ButtonAddCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCruiser)); //private void ButtonAddMilitaryCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryCruiser)); private void ButtonAddCruiser_Click(object sender, EventArgs e) { CreateObject(nameof(DrawningCruiser)); } private void ButtonAddMilitaryCruiser_Click(object sender, EventArgs e) { CreateObject(nameof(DrawningMilitaryCruiser)); } private void ButtonRemoveCruiser_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null) { return; } if (MessageBox.Show("удалить объект?", "удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } int pos = Convert.ToInt32(maskedTextBoxPosision.Text); if (_company - pos != null) { MessageBox.Show("объект удален"); pictureBoxCruiser.Image = _company.Show(); } else { MessageBox.Show("не удалось удалить объект"); } } private void ButtonGetToTest_Click(object sender, EventArgs e) { if (_company == null) { return; } DrawningCruiser? cruiser = null; int counter = 100; while (cruiser == null) { cruiser = _company.GetRandomObject(); counter--; if (counter <= 0) { break; } } if (cruiser == null) { return; } FormCruiser form = new() { SetCruiser = cruiser }; form.ShowDialog(); } private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) { return; } pictureBoxCruiser.Image = _company.Show(); } } }