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

63 lines
2.4 KiB
C#
Raw Normal View History

namespace Airbus
{
public partial class FormAirbus : Form
{
// поле-объект для прористовки самолёта
private DrawningAirbus? _drawningAirbus;
public FormAirbus()
{
InitializeComponent();
}
// прорисовка самолёта
private void Draw()
{
if (_drawningAirbus == null)
{
return;
}
Bitmap bmp = new(pictureAirbus.Width, pictureAirbus.Height);
Graphics g = Graphics.FromImage(bmp);
_drawningAirbus.DrawTransport(g);
pictureAirbus.Image = bmp;
}
// кнопка "Создать"
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawningAirbus = new DrawningAirbus();
_drawningAirbus.Init(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)),
pictureAirbus.Width, pictureAirbus.Height);
_drawningAirbus.SetPosition(random.Next(10,100), random.Next(10,100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningAirbus == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningAirbus.MoveTransport(Direction.Up); break;
case "buttonDown":
_drawningAirbus.MoveTransport(Direction.Down); break;
case "buttonLeft":
_drawningAirbus.MoveTransport(Direction.Left); break;
case "buttonRight":
_drawningAirbus.MoveTransport(Direction.Right); break;
}
Draw();
}
}
}