2024-03-17 14:18:19 +04:00
|
|
|
|
using AntiAircraftGun.CollectionGenereticObject;
|
|
|
|
|
using AntiAircraftGun.CollectionGenereticObjects;
|
|
|
|
|
using AntiAircraftGun.Drawnings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace AntiAircraftGun;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormArmoredCarCollection : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormArmoredCarCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-18 14:23:34 +04:00
|
|
|
|
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
2024-03-17 14:18:19 +04:00
|
|
|
|
{
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new CarBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningArmoredCar>());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление бронерованной машины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-18 14:23:34 +04:00
|
|
|
|
private void buttonAddArmoredCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningArmoredCar));
|
2024-03-17 14:18:19 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление зенитной установки
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-18 14:23:34 +04:00
|
|
|
|
private void buttonAddAntiAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun));
|
2024-03-17 14:18:19 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание объекта класса-перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">Тип создаваемого объекта</param>
|
|
|
|
|
private void CreateObject(string type)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Random random = new();
|
|
|
|
|
DrawningArmoredCar drawningArmoredCar;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(DrawningArmoredCar):
|
|
|
|
|
drawningArmoredCar = new DrawningArmoredCar(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
|
|
|
|
break;
|
|
|
|
|
case nameof(DrawningAntiAircraftGun):
|
|
|
|
|
// вызов диалогового окна для выбора цвета
|
|
|
|
|
drawningArmoredCar = new DrawningAntiAircraftGun(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 + drawningArmoredCar != -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_ = MessageBox.Show(drawningArmoredCar.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="random">Генератор случайных чисел</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-18 14:23:34 +04:00
|
|
|
|
private void buttonRemoveArmoredCar_Click(object sender, EventArgs e)
|
2024-03-17 14:18:19 +04:00
|
|
|
|
{
|
|
|
|
|
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("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-18 14:23:34 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перерисовка коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 14:18:19 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача объекта в другую форму
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-18 14:23:34 +04:00
|
|
|
|
private void buttonGoToChek_Click(object sender, EventArgs e)
|
2024-03-17 14:18:19 +04:00
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawningArmoredCar? armoredcar = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (armoredcar == null)
|
|
|
|
|
{
|
|
|
|
|
armoredcar = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (armoredcar == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormAntiAircraftGun form = new()
|
|
|
|
|
{
|
|
|
|
|
SetArmoredCar = armoredcar
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-18 14:23:34 +04:00
|
|
|
|
|
2024-03-17 14:18:19 +04:00
|
|
|
|
}
|