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