namespace Hydroplane
{
public partial class Form1 : Form
{
///
/// Поле-объект для прорисовки объекта
///
private DrawningHydroplane? _drawningHydroplane;
public Form1()
{
InitializeComponent();
}
///
/// Метод прорисовки машины
///
private void Draw()
{
if (_drawningHydroplane == null)
{
return;
}
Bitmap bmp = new(pictureBoxHydroplane.Width,
pictureBoxHydroplane.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningHydroplane.DrawTransport(gr);
pictureBoxHydroplane.Image = bmp;
}
///
/// Обработка нажатия кнопки "Создать"
///
///
///
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningHydroplane = new DrawningHydroplane();
_drawningHydroplane.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)),
pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
_drawningHydroplane.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
///
/// Изменение размеров формы
///
///
///
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningHydroplane == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningHydroplane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningHydroplane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningHydroplane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningHydroplane.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}
}