2024-04-10 11:50:51 +04:00
|
|
|
|
using ProjectStormtrooper.CollectionGenericObjects;
|
|
|
|
|
using ProjectStormtrooper.Drawnings;
|
|
|
|
|
|
|
|
|
|
namespace ProjectStormtrooper;
|
|
|
|
|
|
2024-05-07 01:50:39 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
2024-04-10 11:50:51 +04:00
|
|
|
|
public partial class FormAirplaneCollection : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormAirplaneCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new AirplaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAirplane>());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление самолета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void CreateObject(string type)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Random random = new();
|
|
|
|
|
DrawningAirplane drawningAirplane;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(DrawningAirplane):
|
2024-05-07 01:50:39 +04:00
|
|
|
|
drawningAirplane = new DrawningAirplane(random.Next(100, 300),
|
|
|
|
|
random.Next(1000, 3000), GetColor(random));
|
2024-04-10 11:50:51 +04:00
|
|
|
|
break;
|
|
|
|
|
case nameof(DrawningStormtrooper):
|
2024-05-07 01:50:39 +04:00
|
|
|
|
// TODO вызов диалогового окна для выбора цвета (made)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
drawningAirplane = new DrawningStormtrooper(random.Next(100, 300), random.Next(1000, 3000),
|
2024-05-07 01:50:39 +04:00
|
|
|
|
GetColor(random), GetColor(random),
|
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
2024-04-10 11:50:51 +04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (_company + drawningAirplane != -1)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
private void buttonAddAirplane_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateObject(nameof(DrawningAirplane));
|
|
|
|
|
}
|
|
|
|
|
private void buttonAddStormtrooper_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateObject(nameof(DrawningStormtrooper));
|
|
|
|
|
}
|
|
|
|
|
private void buttonRemoveAirplane_Click(object sender, EventArgs e)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
|
|
|
|
if (_company - pos != null)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
FormStormtrooper form = new()
|
|
|
|
|
{
|
|
|
|
|
SetAirplane = airplane
|
|
|
|
|
};
|
|
|
|
|
form.ShowDialog();
|
2024-04-10 11:50:51 +04:00
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
2024-04-11 09:34:16 +04:00
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBox.Image = _company.Show();
|
2024-04-11 09:34:16 +04:00
|
|
|
|
}
|
2024-04-10 11:50:51 +04:00
|
|
|
|
}
|