2024-02-21 19:44:26 +04:00
|
|
|
|
namespace AntiAircraftGun
|
|
|
|
|
{
|
|
|
|
|
public partial class FormAntiAircraftGun : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле объект для прорисовки объекта
|
|
|
|
|
/// </summary>
|
2024-02-22 15:22:05 +04:00
|
|
|
|
private DrawningAntiAircraftGun? _drawningAntiAircraftGun;
|
2024-02-21 19:44:26 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// конструктор формы
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormAntiAircraftGun()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод прорисовки транспорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
if (_drawningAntiAircraftGun == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningAntiAircraftGun.DrawTransport(gr);
|
|
|
|
|
pictureBoxAntiAircraftGun.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка кнопик Создать
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
2024-02-22 15:22:05 +04:00
|
|
|
|
_drawningAntiAircraftGun = new DrawningAntiAircraftGun();
|
2024-02-21 19:44:26 +04:00
|
|
|
|
_drawningAntiAircraftGun.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 255),
|
|
|
|
|
random.Next(0, 255), random.Next(0, 255)), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
|
|
|
_drawningAntiAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
|
|
|
|
_drawningAntiAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
|
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перемещение объекта по форме
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningAntiAircraftGun == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Up);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Down);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Right);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Left);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|