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

135 lines
4.4 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
{
public partial class FormAirbus : Form
{
private DrawningAirbus? _drawningAirbus;
2023-11-18 10:00:43 +04:00
private AbstractStrategy? _abstractStrategy;
public FormAirbus()
{
InitializeComponent();
}
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 buttonDown_Click(object sender, EventArgs e)
{
buttonMove_Click(sender, e);
}
private void buttonUp_Click(object sender, EventArgs e)
{
buttonMove_Click(sender, e);
}
private void buttonRight_Click(object sender, EventArgs e)
{
buttonMove_Click(sender, e);
}
private void buttonLeft_Click(object sender, EventArgs e)
{
buttonMove_Click(sender, e);
}
2023-11-18 10:00:43 +04:00
// кнопка "Создать самолёт"
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
2023-11-18 10:00:43 +04:00
_drawningAirbus = new DrawningAirbus(random.Next(200, 400), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
pictureAirBus.Width, pictureAirBus.Height);
_drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200));
Draw();
}
// кнопка "Создать суперсамолёт"
private void buttonCreateSuperAirbus_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawningAirbus = new DrawningPlane(random.Next(200, 400), 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)),
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
}
}