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