namespace AirBomber { public partial class FormAirBomber : Form { private DrawningAirBomber _drawingAirBomber; public FormAirBomber() { InitializeComponent(); } private void Draw() { Bitmap bpm = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Graphics gr = Graphics.FromImage(bpm); _drawingAirBomber.DrawAirBomber(gr); pictureBoxAirBomber.Image = bpm; } private void buttonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawingAirBomber = new DrawningAirBomber(); _drawingAirBomber.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))); _drawingAirBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); _drawingAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) { if (_drawingAirBomber == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; bool result = false; switch (name) { case "ButtonUp": result = _drawingAirBomber.MoveAirBomber(DirectionType.Up); break; case "ButtonDown": result = _drawingAirBomber.MoveAirBomber(DirectionType.Down); break; case "ButtonLeft": result = _drawingAirBomber.MoveAirBomber(DirectionType.Left); break; case "ButtonRight": result = _drawingAirBomber.MoveAirBomber(DirectionType.Right); break; } if (result) { Draw(); } } private void PictureBoxResize(object sender, EventArgs e) { _drawingAirBomber?.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Draw(); } } }