88 lines
2.9 KiB
C#
88 lines
2.9 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 SetData()
|
|
{
|
|
Random rnd = new Random();
|
|
|
|
_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}";
|
|
}
|
|
|
|
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new Random();
|
|
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
SetData();
|
|
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();
|
|
}
|
|
|
|
private void buttonCreateModification_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new Random();
|
|
_aircraft = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
|
Convert.ToBoolean(rnd.Next(0,2)),Convert.ToBoolean(rnd.Next(0,2)));
|
|
|
|
SetData();
|
|
Draw();
|
|
}
|
|
}
|
|
} |