178 lines
5.8 KiB
C#
178 lines
5.8 KiB
C#
using ProjectStormTrooper.CollectionGenericObjects;
|
||
using ProjectStormTrooper.Drawnings;
|
||
|
||
|
||
namespace ProjectStormTrooper
|
||
{
|
||
public partial class FormWarPlaneCollection : Form
|
||
{
|
||
private AbstractCompany? _company = null;
|
||
|
||
public FormWarPlaneCollection()
|
||
{
|
||
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 Hangar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningWarPlane>());
|
||
break;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Добавление обычного автомобиля
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonAddWarPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane));
|
||
|
||
/// <summary>
|
||
/// Добавление спортивного автомобиля
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonAddStormTrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormTrooper));
|
||
|
||
/// <summary>
|
||
/// Создание объекта класса-перемещения
|
||
/// </summary>
|
||
/// <param name="type">Тип создаваемого объекта</param>
|
||
private void CreateObject(string type)
|
||
{
|
||
if (_company == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
Random random = new();
|
||
DrawningWarPlane drawningWarPlane;
|
||
switch (type)
|
||
{
|
||
case nameof(DrawningWarPlane):
|
||
|
||
drawningWarPlane = new DrawningWarPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random));
|
||
break;
|
||
case nameof(DrawningStormTrooper):
|
||
|
||
drawningWarPlane = new DrawningStormTrooper(random.Next(100, 300), random.Next(1000, 3000),
|
||
GetColor(random), GetColor(random), GetColor(random),
|
||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||
break;
|
||
default:
|
||
return;
|
||
}
|
||
|
||
if (_company + drawningWarPlane == 1)
|
||
{
|
||
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;
|
||
}
|
||
/// <summary>
|
||
/// Удаление объекта
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonRemoveWarPlane_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||
{
|
||
return;
|
||
}
|
||
|
||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||
if (_company - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBox.Image = _company.Show();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Передача объекта в другую форму
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||
{
|
||
if (_company == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DrawningWarPlane? warPlane = null;
|
||
int counter = 100;
|
||
while (warPlane == null)
|
||
{
|
||
warPlane = _company.GetRandomObject();
|
||
counter--;
|
||
if (counter <= 0)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (warPlane == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
FormStormTrooper form = new()
|
||
{
|
||
SetWarPlane = warPlane
|
||
};
|
||
form.ShowDialog();
|
||
}
|
||
|
||
/// <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();
|
||
}
|
||
}
|
||
}
|