namespace ProjectAirplaneWithRadar { /// /// Форма работы с объектом "Самолет с радаром" /// public partial class FormAirplaneWithRadar : Form { /// /// Поле-объект для происовки объект /// private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar; /// /// Конструктор формы /// public FormAirplaneWithRadar() { InitializeComponent(); } /// /// Обработка нажатия кнопки "Создать" /// /// /// private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawingAirplaneWithRadar = new DrawingAirplaneWithRadar(); _drawingAirplaneWithRadar.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))); _drawingAirplaneWithRadar.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height); _drawingAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100)); UpdatePlane(); } /// /// Метод прорисовки самолета /// private void UpdatePlane() { if (_drawingAirplaneWithRadar == null) { return; } Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height); Graphics gr = Graphics.FromImage(bmp); _drawingAirplaneWithRadar?.DrawTransport(gr); pictureBoxAirplaneWithRadar.Image = bmp; } /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// /// /// private void ButtonMove_Click(object sender, EventArgs e) { if (_drawingAirplaneWithRadar == null) { return; } if (sender is Button button) { string name = button.Name; DirectionType result; switch (name) { case "buttonUp": result = DirectionType.Up; break; case "buttonDown": result = DirectionType.Down; break; case "buttonLeft": result = DirectionType.Left; break; case "buttonRight": result = DirectionType.Right; break; default: return; } _drawingAirplaneWithRadar.MoveTransport(result); UpdatePlane(); } } } }