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