159 lines
4.7 KiB
C#
159 lines
4.7 KiB
C#
using ProjectStormtrooper.CollectionGenericObjects;
|
||
using ProjectStormtrooper.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 ProjectStormtrooper;
|
||
|
||
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 ButtonAddAirplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirplane));
|
||
|
||
/// <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();
|
||
DrawningAirplane drawningAirplane;
|
||
switch (type)
|
||
{
|
||
case nameof(DrawningAirplane):
|
||
drawningAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||
break;
|
||
case nameof(DrawningStormtrooper):
|
||
drawningAirplane = new DrawningStormtrooper(random.Next(100, 300), random.Next(1000, 3000),
|
||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||
break;
|
||
default:
|
||
return;
|
||
}
|
||
|
||
if (_company + drawningAirplane)
|
||
{
|
||
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 ButtonRemoveCar_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)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBox.Image = _company.Show();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
|
||
private void groupBoxTools_Enter(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void pictureBox_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void buttonAddAirplane_Click_1(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|