69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
namespace AirFighter
|
|
{
|
|
public partial class AirFighterForm : Form
|
|
{
|
|
private DrawingAircraft _aircraft;
|
|
|
|
public AirFighterForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_aircraft?.DrawTransport(gr);
|
|
pictureBoxAirFighter.Image = bmp;
|
|
}
|
|
|
|
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new Random();
|
|
_aircraft = new DrawingAircraft();
|
|
_aircraft.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
_aircraft.SetPosition(rnd.Next(10,100),rnd.Next(10,100),pictureBoxAirFighter.Width,pictureBoxAirFighter.Height);
|
|
toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
|
|
toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
|
|
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
|
|
Draw();
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Up);
|
|
}
|
|
break;
|
|
case "buttonDown":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Down);
|
|
}
|
|
break;
|
|
case "buttonLeft":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Left);
|
|
}
|
|
break;
|
|
case "buttonRight":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Right);
|
|
}
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
private void pictureBoxAirFighter_Resize(object sender, EventArgs e)
|
|
{
|
|
_aircraft?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
Draw();
|
|
}
|
|
}
|
|
} |