From a56656054b5987c0a0a3164d12159af2b3248be0 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Fri, 1 Mar 2024 19:55:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => Drawnings}/DirectionType.cs | 3 +- .../Drawnings/DrawingAirplaneWithRadar.cs | 75 ++++++++++++ .../DrawningAirplane.cs} | 115 ++++++++---------- .../Entities/EntityAirplane.cs | 45 +++++++ .../{ => Entities}/EntityAirplaneWithRadar.cs | 28 +---- .../FormAirplaneWithRadar.Designer.cs | 49 ++++---- .../FormAirplaneWithRadar.cs | 65 +++++++--- 7 files changed, 248 insertions(+), 132 deletions(-) rename AirplaneWithRadar/ProjectAirplaneWithRadar/{ => Drawnings}/DirectionType.cs (90%) create mode 100644 AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs rename AirplaneWithRadar/ProjectAirplaneWithRadar/{DrawingAirplaneWithRadar.cs => Drawnings/DrawningAirplane.cs} (65%) create mode 100644 AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs rename AirplaneWithRadar/ProjectAirplaneWithRadar/{ => Entities}/EntityAirplaneWithRadar.cs (64%) diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/DirectionType.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DirectionType.cs similarity index 90% rename from AirplaneWithRadar/ProjectAirplaneWithRadar/DirectionType.cs rename to AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DirectionType.cs index 46519a9..65cc84f 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/DirectionType.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DirectionType.cs @@ -1,5 +1,4 @@ - -namespace ProjectAirplaneWithRadar +namespace ProjectAirplaneWithRadar.Drawnings { /// /// Направление перемещения diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs new file mode 100644 index 0000000..05b052c --- /dev/null +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs @@ -0,0 +1,75 @@ +using ProjectAirplaneWithRadar.Entities; + +namespace ProjectAirplaneWithRadar.Drawnings +{ + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawingAirplaneWithRadar : DrawningAirplane + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Шасси + /// Ракета + public DrawingAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) : base(150, 85) + { + EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, wheels, rocket); + } + + public override void DrawTransport(Graphics g) + { + if (EntityAirplane == null || EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(airplaneWithRadar.AdditionalColor); + + if (airplaneWithRadar.Wheels) + { + //Задняя стойка + g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); + g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); + + g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); + + g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); + + //Передняя стойка + g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); + g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); + + g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); + } + + //_startPosY += 10; + base.DrawTransport(g); + //_startPosY -= 10; + + + //Ракета воздух-воздух + if (airplaneWithRadar.Rocket) + { + g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5); + g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5); + + g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5); + g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5); + + g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5); + g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5); + } + + + } + } +} diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplane.cs similarity index 65% rename from AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs rename to AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplane.cs index e06df66..a551108 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplane.cs @@ -1,14 +1,16 @@ -namespace ProjectAirplaneWithRadar +using System; +using ProjectAirplaneWithRadar.Entities; + + +namespace ProjectAirplaneWithRadar.Drawnings { - /// - /// Класс, отвечающий за прорисовку и перемещение объекта-сущности - /// - public class DrawingAirplaneWithRadar + public class DrawningAirplane { + /// /// Класс-сущность /// - public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; } + public EntityAirplane? EntityAirplane { get; protected set; } /// /// Ширина окна @@ -23,12 +25,12 @@ /// /// Левая координата прорисовки /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя кооридната прорисовки /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки самолета @@ -38,28 +40,41 @@ /// /// Высота прорисовки самолета /// - public readonly int PlaneHeight = 95; - + public readonly int PlaneHeight = 85; /// - /// Инициализация свойств + /// Пустой конструктор /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Шасси - /// Ракета - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) + private DrawningAirplane() { - EntityAirplaneWithRadar = new EntityAirplaneWithRadar(); - EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, wheels, rocket); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningAirplane(int speed, double weight, Color bodyColor) : this() + { + EntityAirplane = new EntityAirplane(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки самолета + /// Высота прорисовки самолета + protected DrawningAirplane(int planeWidth, int planeHeight) : this() + { + PlaneWidth = planeWidth; + PlaneHeight = planeHeight; + } + /// /// Установка границ поля /// @@ -72,18 +87,18 @@ { _pictureWidth = width; _pictureHeight = height; - if(_startPosX != null && _startPosY != null) + if (_startPosX != null && _startPosY != null) { - if(_startPosX.Value < 0) + if (_startPosX.Value < 0) { _startPosX = 0; } - if(_startPosY.Value < 0) + if (_startPosY.Value < 0) { _startPosY = 0; } - if(_startPosX.Value + PlaneWidth > _pictureWidth) + if (_startPosX.Value + PlaneWidth > _pictureWidth) { _startPosX = _pictureWidth - PlaneWidth; } @@ -116,7 +131,7 @@ { _startPosX = 0; } - if(_startPosY.Value < 0) + if (_startPosY.Value < 0) { _startPosY = 0; } @@ -138,12 +153,12 @@ /// true - перемещене выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } - int step = (int)EntityAirplaneWithRadar.Step; + int step = (int)EntityAirplane.Step; switch (direction) { //влево @@ -162,7 +177,7 @@ break; // вправо case DirectionType.Right: - if (_startPosX.Value + step < _pictureWidth - PlaneWidth) + if (_startPosX.Value + step < _pictureWidth - PlaneWidth) { _startPosX += step; } @@ -184,54 +199,19 @@ /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor); - - //Шасси - if (EntityAirplaneWithRadar.Wheels) - { - //Задняя стойка - g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); - g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); - - g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); - - g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); - - //Передняя стойка - g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); - g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); - - g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); - } - - //Ракета воздух-воздух - if (EntityAirplaneWithRadar.Rocket) - { - g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5); - g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5); - - g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5); - g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5); - - g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5); - g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5); - } //Корпус - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50,100,30); - + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50, 100, 30); + //Хвост Point[] points = { new Point(_startPosX.Value + 10, _startPosY.Value + 10), @@ -266,3 +246,4 @@ } } } + diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs new file mode 100644 index 0000000..3103cb9 --- /dev/null +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs @@ -0,0 +1,45 @@ +using System; +using System.Net.Sockets; + + +namespace ProjectAirplaneWithRadar.Entities +{ + /// + /// Класс-сущность "Самолет" + /// + public class EntityAirplane + { + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Шаг перемещения автомобиля + /// + public double Step => Speed * 100 / Weight; + + /// + /// Конструктор сущности + /// + /// Скорость + /// Вес + /// Основной цвет + public EntityAirplane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } +} diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/EntityAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs similarity index 64% rename from AirplaneWithRadar/ProjectAirplaneWithRadar/EntityAirplaneWithRadar.cs rename to AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs index 655fa44..e6d802a 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/EntityAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs @@ -1,25 +1,10 @@ -namespace ProjectAirplaneWithRadar +namespace ProjectAirplaneWithRadar.Entities { /// /// Класс-сущность "Самолет с радаром" /// - public class EntityAirplaneWithRadar + public class EntityAirplaneWithRadar : EntityAirplane { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет (для опциональных элементов) /// @@ -33,7 +18,7 @@ /// /// Признак (опция) наличия ракеты /// - public bool Rocket { get; private set; } + public bool Rocket { get; private set; } /// /// Шаг перемещения автомобиля @@ -49,14 +34,11 @@ /// Дополнительный цвет /// Шасси /// Ракета - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) + public EntityAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Wheels = wheels; - Rocket = rocket; + Rocket = rocket; } } } diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs index 2ed78dd..3f66348 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs @@ -34,6 +34,7 @@ buttonRight = new Button(); buttonDown = new Button(); buttonUp = new Button(); + ButtonCreateAirplane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit(); SuspendLayout(); // @@ -41,21 +42,19 @@ // pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill; pictureBoxAirplaneWithRadar.Location = new Point(0, 0); - pictureBoxAirplaneWithRadar.Margin = new Padding(3, 4, 3, 4); pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar"; - pictureBoxAirplaneWithRadar.Size = new Size(1128, 636); + pictureBoxAirplaneWithRadar.Size = new Size(987, 477); pictureBoxAirplaneWithRadar.TabIndex = 0; pictureBoxAirplaneWithRadar.TabStop = false; // // buttonCreate // buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(14, 589); - buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Location = new Point(12, 442); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(86, 31); + buttonCreate.Size = new Size(225, 23); buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; + buttonCreate.Text = "Создать Самолет с радаром"; buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += ButtonCreate_Click; // @@ -64,10 +63,9 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(981, 573); - buttonLeft.Margin = new Padding(3, 4, 3, 4); + buttonLeft.Location = new Point(858, 430); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(40, 47); + buttonLeft.Size = new Size(35, 35); buttonLeft.TabIndex = 2; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += ButtonMove_Click; @@ -77,10 +75,9 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(1074, 573); - buttonRight.Margin = new Padding(3, 4, 3, 4); + buttonRight.Location = new Point(940, 430); buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(40, 47); + buttonRight.Size = new Size(35, 35); buttonRight.TabIndex = 3; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; @@ -90,10 +87,9 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(1027, 573); - buttonDown.Margin = new Padding(3, 4, 3, 4); + buttonDown.Location = new Point(899, 430); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(40, 47); + buttonDown.Size = new Size(35, 35); buttonDown.TabIndex = 4; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; @@ -103,26 +99,36 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(1027, 519); - buttonUp.Margin = new Padding(3, 4, 3, 4); + buttonUp.Location = new Point(899, 389); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(40, 47); + buttonUp.Size = new Size(35, 35); buttonUp.TabIndex = 5; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // + // ButtonCreateAirplane + // + ButtonCreateAirplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + ButtonCreateAirplane.Location = new Point(268, 442); + ButtonCreateAirplane.Name = "ButtonCreateAirplane"; + ButtonCreateAirplane.Size = new Size(225, 23); + ButtonCreateAirplane.TabIndex = 6; + ButtonCreateAirplane.Text = "Создать Самолет"; + ButtonCreateAirplane.UseVisualStyleBackColor = true; + ButtonCreateAirplane.Click += ButtonCreateAirplane_Click; + // // FormAirplaneWithRadar // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1128, 636); + ClientSize = new Size(987, 477); + Controls.Add(ButtonCreateAirplane); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonCreate); Controls.Add(pictureBoxAirplaneWithRadar); - Margin = new Padding(3, 4, 3, 4); Name = "FormAirplaneWithRadar"; Text = "Самолет с радаром"; ((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit(); @@ -137,5 +143,6 @@ private Button buttonRight; private Button buttonDown; private Button buttonUp; + private Button ButtonCreateAirplane; } } \ No newline at end of file diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs index 7ec64fb..4cfb2b0 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs @@ -1,4 +1,6 @@ -namespace ProjectAirplaneWithRadar +using ProjectAirplaneWithRadar.Drawnings; + +namespace ProjectAirplaneWithRadar { /// /// Форма работы с объектом "Самолет с радаром" @@ -8,7 +10,7 @@ /// /// Поле-объект для происовки объект /// - private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar; + private DrawningAirplane? _drawingAirplane; /// /// Конструктор формы @@ -19,38 +21,63 @@ } /// - /// Обработка нажатия кнопки "Создать" + /// Создание объекта класса-перемещения /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) + /// Тип создаваемого объекта + private void CreateObject(string type) { 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)); + 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 (_drawingAirplaneWithRadar == null) + if (_drawingAirplane == null) { return; } Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height); Graphics gr = Graphics.FromImage(bmp); - _drawingAirplaneWithRadar?.DrawTransport(gr); + _drawingAirplane?.DrawTransport(gr); pictureBoxAirplaneWithRadar.Image = bmp; - } + } /// /// Перемещение объекта по форме (нажатие кнопок навигации) @@ -59,7 +86,7 @@ /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawingAirplaneWithRadar == null) + if (_drawingAirplane == null) { return; } @@ -87,10 +114,10 @@ return; } - _drawingAirplaneWithRadar.MoveTransport(result); + _drawingAirplane.MoveTransport(result); UpdatePlane(); } - } + } } }