PIbd-22_Isaeva_A.I._Airbus_.../Airbus/FormPlane.cs

144 lines
4.9 KiB
C#
Raw Normal View History

2023-11-18 10:00:43 +04:00
using ProjectAirbus.Drawnings;
using ProjectAirbus.MovementStrategy;
using ProjectAirbus.Entities;
namespace ProjectAirbus
{
2023-11-18 10:47:46 +04:00
public partial class FormPlane : Form
{
private DrawningAirbus? _drawningAirbus;
2023-11-18 10:00:43 +04:00
private AbstractStrategy? _abstractStrategy;
2023-11-18 10:47:46 +04:00
// Выбранный автомобиль
public DrawningAirbus? SelectedAirbus { get; private set; }
public FormPlane()
{
InitializeComponent();
2023-11-18 10:47:46 +04:00
_abstractStrategy = null;
SelectedAirbus = null;
}
2023-11-18 10:00:43 +04:00
// прорисовка самолёта
private void Draw()
{
if (_drawningAirbus == null)
{
return;
}
2023-11-18 10:00:43 +04:00
Bitmap bmp = new(pictureAirBus.Width, pictureAirBus.Height);
Graphics g = Graphics.FromImage(bmp);
_drawningAirbus.DrawTransport(g);
2023-11-18 10:00:43 +04:00
pictureAirBus.Image = bmp;
}
// кнопка "Создать самолёт"
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
2023-11-18 10:47:46 +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;
}
_drawningAirbus = new DrawningAirbus(random.Next(100, 300), random.Next(1000, 3000),
color, pictureAirBus.Width, pictureAirBus.Height);
2023-11-18 10:00:43 +04:00
_drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200));
Draw();
}
// кнопка "Создать суперсамолёт"
private void buttonCreateSuperAirbus_Click(object sender, EventArgs e)
{
Random random = new Random();
2023-11-18 10:47:46 +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;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO дополнительного цвета
if (dialog.ShowDialog() == DialogResult.OK)
{
dopColor = dialog.Color;
}
2023-11-18 10:00:43 +04:00
_drawningAirbus = new DrawningPlane(random.Next(200, 400), random.Next(1000, 3000),
2023-11-18 10:47:46 +04:00
color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
2023-11-18 10:00:43 +04:00
pictureAirBus.Width, pictureAirBus.Height);
2023-11-18 10:00:43 +04:00
_drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningAirbus == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
2023-11-18 10:00:43 +04:00
_drawningAirbus.MoveTransport(DirectionType.Up); break;
case "buttonDown":
2023-11-18 10:00:43 +04:00
_drawningAirbus.MoveTransport(DirectionType.Down); break;
case "buttonLeft":
2023-11-18 10:00:43 +04:00
_drawningAirbus.MoveTransport(DirectionType.Left); break;
case "buttonRight":
2023-11-18 10:00:43 +04:00
_drawningAirbus.MoveTransport(DirectionType.Right); break;
}
Draw();
}
// Кнопка "Шаг"
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawningAirbus == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawningObjectAirbus(_drawningAirbus), pictureAirBus.Width, pictureAirBus.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
2023-11-18 10:00:43 +04:00
_abstractStrategy.MakeStep();
Draw();
2023-11-18 10:00:43 +04:00
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
2023-11-18 10:00:43 +04:00
2023-11-18 10:47:46 +04:00
private void buttonSelectedAirbus_Click(object sender, EventArgs e)
{
SelectedAirbus = _drawningAirbus;
DialogResult = DialogResult.OK;
}
}
}