63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
namespace ProjectAirplaneWithRadar
|
|
{
|
|
public partial class FormAirplaneWithRadar : Form
|
|
{
|
|
private DrawningAirplaneWithRadar? _drawningAirplaneWithRadar;
|
|
private void Draw()
|
|
{
|
|
if (_drawningAirplaneWithRadar == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new Bitmap(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningAirplaneWithRadar.DrawTransport(gr);
|
|
pictureBoxAirplaneWithRadar.Image = bmp;
|
|
}
|
|
public FormAirplaneWithRadar()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningAirplaneWithRadar == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningAirplaneWithRadar.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawningAirplaneWithRadar.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawningAirplaneWithRadar.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawningAirplaneWithRadar.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new Random();
|
|
_drawningAirplaneWithRadar = new DrawningAirplaneWithRadar();
|
|
if (_drawningAirplaneWithRadar.Init
|
|
(random.Next(100, 300), // speed
|
|
random.Next(1000, 3000),// weight
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),// bodycolor
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), //additionalColor
|
|
Convert.ToBoolean(random.Next(0, 2)), // radar
|
|
Convert.ToBoolean(random.Next(0, 2)), //dopbak
|
|
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height))
|
|
{
|
|
_drawningAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
}
|
|
}
|
|
} |