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