PIbd-22_Isaeva_A.I._Airbus_.../AirBus/Form1.cs
2023-10-08 18:18:23 +03:00

95 lines
2.7 KiB
C#

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 PictureBoxAirBus_Resize(object sender, EventArgs e)
{
_drawningAirBus.ChangeBorders(pictureAirBus.Width, pictureAirBus.Height);
Draw();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void buttonDown_Click(object sender, EventArgs e)
{
}
private void buttonUp_Click(object sender, EventArgs e)
{
}
private void buttonRight_Click(object sender, EventArgs e)
{
}
private void buttonLeft_Click(object sender, EventArgs e)
{
}
// êíîïêà "Ñîçäàòü"
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)), 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();
}
}
}