65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
namespace AirPlaneWithRadar
|
|
{
|
|
|
|
public partial class FormPlain : Form
|
|
{
|
|
private DrawingPlain _plain;
|
|
|
|
public FormPlain()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
Bitmap bmp = new(pictureBoxPlain.Width, pictureBoxPlain.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_plain?.DrawTransoprt(gr);
|
|
pictureBoxPlain.Image = bmp;
|
|
}
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new();
|
|
_plain = new DrawingPlain();
|
|
|
|
_plain.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
_plain.setPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxPlain.Width, pictureBoxPlain.Height);
|
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_plain.Plain.Speed}";
|
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_plain.Plain.Weight}";
|
|
toolStripStatusLabelColor.Text = $"Öâåò: {_plain.Plain.BodyColor.Name}";
|
|
Draw();
|
|
}
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_plain?.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_plain?.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_plain?.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_plain?.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
private void PictureBoxPlain_Resize(object sender, EventArgs e)
|
|
{
|
|
_plain?.ChangeBorders(pictureBoxPlain.Width, pictureBoxPlain.Height);
|
|
Draw();
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|