namespace Lab1 { public partial class Form1 : Form { /// /// Поле-объект для прорисовки объекта /// private DrawingElectroTrans _drawningElectroTrans; public Form1() { InitializeComponent(); _drawningElectroTrans = new DrawingElectroTrans(); } /// /// Метод прорисовки машины /// private void Draw() { if (_drawningElectroTrans == null) { return; } Bitmap bmp = new(pictureBoxSportCar.Width, pictureBoxSportCar.Height); Graphics gr = Graphics.FromImage(bmp); _drawningElectroTrans.DrawTransport(gr); pictureBoxSportCar.Image = bmp; } private void ButtonCreateElectroTrans_Click(object sender, EventArgs e) { Random random = new(); _drawningElectroTrans.Init(random.Next(500, 1500), 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)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2))); _drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Size.Width, pictureBoxSportCar.Size.Height); _drawningElectroTrans.SetPosition(random.Next(0, 5), random.Next(0, 5)); Draw(); } /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// /// /// private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningElectroTrans == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; bool result = false; switch (name) { case "buttonUp": result = _drawningElectroTrans.MoveTransport(DirectionType.Up); break; case "buttonDown": result = _drawningElectroTrans.MoveTransport(DirectionType.Down); break; case "buttonLeft": result = _drawningElectroTrans.MoveTransport(DirectionType.Left); break; case "buttonRight": result = _drawningElectroTrans.MoveTransport(DirectionType.Right); break; } if (result) { Draw(); } } } }