180 lines
5.5 KiB
C#
180 lines
5.5 KiB
C#
|
using ProjectFighterJet.CollectionGenericObjects;
|
|||
|
using ProjectFighterJet.Drawnings;
|
|||
|
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;
|
|||
|
|
|||
|
namespace ProjectFighterJet;
|
|||
|
|
|||
|
public partial class FormJetCollection : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Компания
|
|||
|
/// </summary>
|
|||
|
private AbstractCompany? _company;
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
public FormJetCollection()
|
|||
|
{
|
|||
|
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 FighterJetSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningJet>());
|
|||
|
break;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Создание объекта класса-перемещения
|
|||
|
/// </summary>
|
|||
|
/// <param name="Тип создаваемого объекта"></param>
|
|||
|
private void CreateObject(string type)
|
|||
|
{
|
|||
|
if (_company == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Random random = new();
|
|||
|
DrawningJet drawningJet;
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case nameof(DrawningJet):
|
|||
|
drawningJet = new DrawningJet(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
|||
|
break;
|
|||
|
case nameof(DrawningFighterJet):
|
|||
|
drawningJet = new DrawningFighterJet(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;
|
|||
|
}
|
|||
|
int tempSize = FighterJetSharingService.getAmountOfObjects();
|
|||
|
if (_company + drawningJet != -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 buttonAddJet_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningJet));
|
|||
|
/// <summary>
|
|||
|
/// Добавление базового бомбардировщика
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void buttonAddFighterJet_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningFighterJet));
|
|||
|
/// <summary>
|
|||
|
/// Удаление объекта
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void buttonRemoveJet_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
|||
|
int tempSize = FighterJetSharingService.getAmountOfObjects();
|
|||
|
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;
|
|||
|
}
|
|||
|
DrawningJet? jet = null;
|
|||
|
int counter = 100;
|
|||
|
while (jet == null)
|
|||
|
{
|
|||
|
jet = _company.GetRandomObject();
|
|||
|
counter--;
|
|||
|
if (counter <= 0)
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (jet == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
FormFighterJet form = new()
|
|||
|
{
|
|||
|
Setjet = jet
|
|||
|
};
|
|||
|
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();
|
|||
|
}
|
|||
|
}
|