namespace DumpTruck { public partial class FormDumpTruck : Form { public FormDumpTruck() { InitializeComponent(); } private DrawingDumpTruck? _drawingDumpTruck; private void Draw() { if (_drawingDumpTruck == null) { return; } Bitmap bmp = new(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); Graphics gr = Graphics.FromImage(bmp); _drawingDumpTruck.DrawTransport(gr); pictureBoxDumpTruck.Image = bmp; } private void Create_Click(object sender, EventArgs e) { Random random = new(); _drawingDumpTruck = new DrawingDumpTruck(); _drawingDumpTruck.Init(random.Next(100, 300), random.Next(1000, 3000), 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)), 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)), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); _drawingDumpTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) { if (_drawingDumpTruck == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawingDumpTruck.MoveTransport(Direction.Up); break; case "buttonDown": _drawingDumpTruck.MoveTransport(Direction.Down); break; case "buttonLeft": _drawingDumpTruck.MoveTransport(Direction.Left); break; case "buttonRight": _drawingDumpTruck.MoveTransport(Direction.Right); break; } Draw(); } } }