using AirBomber.CollectionGenericObjects;
using AirBomber.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 AirBomber
{
public partial class FormAirPlaneCollection : Form
{
///
/// Компания
///
private AbstractCompany? _company;
///
/// Конструктор
///
public FormAirPlaneCollection()
{
InitializeComponent();
}
///
/// Выбор компании
///
///
///
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new AirPlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
break;
}
}
///
/// Создание объекта класса-перемещения
///
/// Тип создаваемого объекта
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
DrawningAirPlane _drawningAirPlane;
Random random = new();
switch (type)
{
case nameof(DrawningAirPlane):
_drawningAirPlane = new DrawningAirPlane(random.Next(30, 70), random.Next(100, 500),
GetColor(random));
break;
case nameof(DrawningAirBomber):
_drawningAirPlane = new DrawningAirBomber(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 + _drawningAirPlane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
///
/// Добавление обычного автомобиля
///
///
///
private void buttonAddAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane));
///
/// Добавление спортивного автомобиля
///
///
///
private void buttonAddAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber));
///
/// Получение цвета
///
/// Генератор случайных чисел
///
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 ButtonRemoveAirPlane_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
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;
}
DrawningAirPlane? airplane = null;
int counter = 100;
while (airplane == null)
{
airplane = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (airplane == null)
{
return;
}
FormAirBomber form = new FormAirBomber();
form.SetAirPlane = airplane;
form.ShowDialog();
}
///
/// Перерисовка коллекции
///
///
///
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
private void FormAirPlaneCollection_Load(object sender, EventArgs e)
{
}
}
}