ISEbd-12_Sinelnikova_A.V._S.../ProjectCruiser/FormCruisersCollection.cs
2024-03-21 10:52:11 +04:00

170 lines
5.4 KiB
C#

using ProjectCruiser.CollectionGenericObjects;
using ProjectCruiser.Drawnings;
namespace ProjectCruiser
{
public partial class FormCruisersCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormCruisersCollection()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "хранилище":
_company = new CruiserDockingService(pictureBoxCruiser.Width,
pictureBoxCruiser.Height, new MassiveGenericObjects<DrawningCruiser>());
break;
}
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
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("не удалось добавить объект");
}
}
/// <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;
}
//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();
}
}
}