PIBD-13_Fomichev_V.S._Simple_/AntiAircraftGun/FormAntiAircraftGun.cs

104 lines
4.1 KiB
C#
Raw Normal View History

using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun
2024-02-21 19:44:26 +04:00
{
public partial class FormAntiAircraftGun : Form
{
/// <summary>
/// Поле объект для прорисовки объекта
/// </summary>
private DrawningAircraftGun? _drawningAircraftGun;
2024-02-21 19:44:26 +04:00
/// <summary>
/// конструктор формы
/// </summary>
public FormAntiAircraftGun()
{
InitializeComponent();
}
/// <summary>
/// Метод прорисовки транспорта
/// </summary>
private void Draw()
{
if (_drawningAircraftGun == null)
2024-02-21 19:44:26 +04:00
{
return;
}
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningAircraftGun.DrawTransport(gr);
2024-02-21 19:44:26 +04:00
pictureBoxAntiAircraftGun.Image = bmp;
}
private void CreateObject(string type)
2024-02-21 19:44:26 +04:00
{
Random random = new();
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
_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();
}
/// <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)
{
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":
result = _drawningAircraftGun.MoveTransport(DirectionType.Up);
2024-02-21 19:44:26 +04:00
break;
case "buttonDown":
result = _drawningAircraftGun.MoveTransport(DirectionType.Down);
2024-02-21 19:44:26 +04:00
break;
case "buttonRight":
result = _drawningAircraftGun.MoveTransport(DirectionType.Right);
2024-02-21 19:44:26 +04:00
break;
case "buttonLeft":
result = _drawningAircraftGun.MoveTransport(DirectionType.Left);
2024-02-21 19:44:26 +04:00
break;
}
if (result)
{
Draw();
}
}
2024-02-21 19:44:26 +04:00
}
}