From d3ef8ea0e22f05a8b7926cca47846629e1d86d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Sat, 12 Nov 2022 21:22: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=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=B8=D0=BB=D0=BB=D1=8E=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2=20=D1=80=D0=B0=D0=B7=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/DrawingAirplane.cs | 10 ++++----- .../DrawningAirplanePortholes.cs | 4 ++-- .../DrawningDeltaPortholes.cs | 22 +++++++++++++++++++ .../DrawningRhombusPortholes.cs | 22 +++++++++++++++++++ .../AirplaneWithRadar/EntityAirplane.cs | 2 +- .../FormAirplane.Designer.cs | 18 ++++++++++++++- .../AirplaneWithRadar/FormAirplane.cs | 16 +++++++++++--- .../AirplaneWithRadar/IAirplanePortholes.cs | 14 ++++++++++++ 8 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/DrawningDeltaPortholes.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/DrawningRhombusPortholes.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs index ebfa28c..595109c 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs @@ -10,7 +10,7 @@ namespace AirplaneWithRadar /// Класс-сущность /// public EntityAirplane Airplane { private set; get; } - public DrawningAirplanePortholes DrawningPortholes { get; private set; } + public IAirplanePortholes DrawningPortholes { get; private set; } /// /// Левая координата отрисовки самолёта /// @@ -41,12 +41,10 @@ namespace AirplaneWithRadar /// Скорость /// Вес /// Цвет - public void Init(int speed, float weight, Color bodyColor) + public DrawningAirplane(int speed, float weight, Color bodyColor, IAirplanePortholes typeAirplanePortholes) { - Airplane = new EntityAirplane(); - Airplane.Init(speed, weight, bodyColor); - DrawningPortholes = new(); - DrawningPortholes.CountPortholes = 10; + Airplane = new EntityAirplane(speed, weight, bodyColor); + DrawningPortholes = typeAirplanePortholes; } /// /// Установка позиции diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplanePortholes.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplanePortholes.cs index 2c94173..dab8f7f 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplanePortholes.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplanePortholes.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirplaneWithRadar { - internal class DrawningAirplanePortholes + internal class DrawningAirplanePortholes : IAirplanePortholes { private CountPortholes _countPortholes; @@ -33,7 +33,7 @@ namespace AirplaneWithRadar } } - private void DrawPorthole(Graphics g, int _startPosX, int _startPosY) + protected virtual void DrawPorthole(Graphics g, int _startPosX, int _startPosY) { Pen pen = new(Color.Black); g.DrawRectangle(pen, _startPosX, _startPosY, 2, 2); diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningDeltaPortholes.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningDeltaPortholes.cs new file mode 100644 index 0000000..08f62aa --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningDeltaPortholes.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class DrawningDeltaPortholes : DrawningAirplanePortholes + { + protected override void DrawPorthole(Graphics g, int _startPosX, int _startPosY) + { + Pen pen = new (Color.Black); + PointF[] point = new PointF[3]; + point[0] = new PointF(_startPosX, _startPosY); + point[1] = new PointF(_startPosX-2, _startPosY+2); + point[2] = new PointF(_startPosX + 2, _startPosY + 2); + g.DrawPolygon(pen, point); + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningRhombusPortholes.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningRhombusPortholes.cs new file mode 100644 index 0000000..0ba844c --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningRhombusPortholes.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class DrawningRhombusPortholes : DrawningAirplanePortholes + { + protected override void DrawPorthole(Graphics g, int _startPosX, int _startPosY) + { + Pen pen = new(Color.Black); + PointF[] point = new PointF[4]; + point[0] = new PointF(_startPosX, _startPosY); + point[1] = new PointF(_startPosX - 2, _startPosY + 2); + point[2] = new PointF(_startPosX, _startPosY + 4); + point[3] = new PointF(_startPosX + 2, _startPosY + 2); + g.DrawPolygon(pen, point); + } + } +} \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs index ef80d96..4682efc 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs @@ -29,7 +29,7 @@ namespace AirplaneWithRadar /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityAirplane(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs index d8cf5c7..18ba5a1 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs @@ -40,6 +40,7 @@ this.buttonRight = new System.Windows.Forms.Button(); this.labelPortholes = new System.Windows.Forms.Label(); this.comboBoxPortholes = new System.Windows.Forms.ComboBox(); + this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.SuspendLayout(); @@ -94,7 +95,7 @@ this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Создать"; this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); // // buttonUp // @@ -166,11 +167,25 @@ this.comboBoxPortholes.TabIndex = 8; this.comboBoxPortholes.Text = "10"; // + // comboBoxTypePortholes + // + this.comboBoxTypePortholes.FormattingEnabled = true; + this.comboBoxTypePortholes.Items.AddRange(new object[] { + "Квадратные", + "Треугольные", + "Ромбовидные"}); + this.comboBoxTypePortholes.Location = new System.Drawing.Point(12, 338); + this.comboBoxTypePortholes.Name = "comboBoxTypePortholes"; + this.comboBoxTypePortholes.Size = new System.Drawing.Size(121, 23); + this.comboBoxTypePortholes.TabIndex = 9; + this.comboBoxTypePortholes.Text = "Квадратные"; + // // FormAirplane // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboBoxTypePortholes); this.Controls.Add(this.comboBoxPortholes); this.Controls.Add(this.labelPortholes); this.Controls.Add(this.buttonRight); @@ -204,5 +219,6 @@ private Button buttonRight; private Label labelPortholes; private ComboBox comboBoxPortholes; + private ComboBox comboBoxTypePortholes; } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs index f980d42..f505933 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs @@ -27,11 +27,20 @@ namespace AirplaneWithRadar /// /// - private void buttonCreate_Click(object sender, EventArgs e) + private void ButtonCreate_Click(object sender, EventArgs e) { + IAirplanePortholes typeAirplanePortholes = new DrawningAirplanePortholes(); + switch (comboBoxTypePortholes.Text) + { + case "": + typeAirplanePortholes = new DrawningDeltaPortholes(); + break; + case "": + typeAirplanePortholes = new DrawningRhombusPortholes(); + break; + } Random rnd = new(); - _airplane = new DrawningAirplane(); - _airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), typeAirplanePortholes); _airplane.DrawningPortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text); _airplane.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height); toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}"; @@ -76,5 +85,6 @@ namespace AirplaneWithRadar _airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height); Draw(); } + } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs b/AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs new file mode 100644 index 0000000..d41a5d3 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal interface IAirplanePortholes + { + int CountPortholes { set; } + public void DrawPortholes(Graphics g, int _startPosX, int _startPosY, int _airplaneWidth); + } +}