From 307b802e237caa80ebd189f0e5ce592fc51bd71f 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:56:17 +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=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83=D1=82?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/DrawingAirplane.cs | 32 +++++++++---- .../DrawningAirplaneWithRadar.cs | 48 +++++++++++++++++++ .../EntityAirplaneWithRadar.cs | 41 ++++++++++++++++ .../FormAirplane.Designer.cs | 13 +++++ .../AirplaneWithRadar/FormAirplane.cs | 35 ++++++++++++++ 5 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs index 595109c..984ced5 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs @@ -9,32 +9,32 @@ namespace AirplaneWithRadar /// /// Класс-сущность /// - public EntityAirplane Airplane { private set; get; } + public EntityAirplane Airplane { protected set; get; } public IAirplanePortholes DrawningPortholes { get; private set; } /// /// Левая координата отрисовки самолёта /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки самолёта /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// - private int? _pictureWidth = null; + protected int? _pictureWidth = null; /// /// Высота окна отрисовки /// - private int? _pictureHeight = null; + protected int? _pictureHeight = null; /// /// Ширина отрисовки /// - private readonly int _airplaneWidth = 100; + protected readonly int _airplaneWidth = 100; /// /// Высота отрисовки самолёта /// - private readonly int _airplaneHeight = 20; + protected readonly int _airplaneHeight = 20; /// /// Инициализация свойств /// @@ -46,6 +46,22 @@ namespace AirplaneWithRadar Airplane = new EntityAirplane(speed, weight, bodyColor); DrawningPortholes = typeAirplanePortholes; } + + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Ширина отрисовки самолёта + /// Высота отрисовки самолёта + protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight, IAirplanePortholes typeAirplanePortholes) : + this(speed, weight, bodyColor, typeAirplanePortholes) + { + _airplaneWidth = airplaneWidth; + _airplaneHeight = airplaneHeight; + } + /// /// Установка позиции /// @@ -112,7 +128,7 @@ namespace AirplaneWithRadar /// Отрисовка самолёта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs new file mode 100644 index 0000000..8cb45f9 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace AirplaneWithRadar +{ + internal class DrawningAirplaneWithRadar : DrawningAirplane + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия радара + /// Признак наличия дополнительных топливных баков + public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool fuelTanks, IAirplanePortholes typeAirplanePortholes) : + base(speed, weight, bodyColor, 100, 20, typeAirplanePortholes) + { + Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, fuelTanks); + } + + public override void DrawTransport(Graphics g) + { + if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar) + { + return; + } + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor); + if (airplaneWithRadar.Radar) + { + g.FillEllipse(dopBrush, _startPosX + 30, _startPosY, 20, 5); + g.DrawLine(pen, _startPosX + 33, _startPosY + 4, _startPosX + 33, _startPosY + 7); + g.DrawLine(pen, _startPosX + 47, _startPosY + 4, _startPosX + 47, _startPosY + 7); + } + base.DrawTransport(g); + if (airplaneWithRadar.FuelTanks) + { + g.FillEllipse(dopBrush, _startPosX + 25, _startPosY + 15, 30, 5); + } + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs new file mode 100644 index 0000000..f05927b --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class EntityAirplaneWithRadar : EntityAirplane + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия радара + /// + public bool Radar { get; private set; } + /// + /// Признак наличия дополнительного топливного бака + /// + public bool FuelTanks { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия радара + /// Признак наличия дополнительных топливных баков + public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color + dopColor, bool radar, bool fuelTanks) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Radar = radar; + FuelTanks = fuelTanks; + } + } +} \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs index 18ba5a1..7fe2dba 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs @@ -41,6 +41,7 @@ this.labelPortholes = new System.Windows.Forms.Label(); this.comboBoxPortholes = new System.Windows.Forms.ComboBox(); this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox(); + this.buttonCreateModif = new System.Windows.Forms.Button(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.SuspendLayout(); @@ -180,11 +181,22 @@ this.comboBoxTypePortholes.TabIndex = 9; this.comboBoxTypePortholes.Text = "Квадратные"; // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 395); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(115, 23); + this.buttonCreateModif.TabIndex = 10; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // 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.buttonCreateModif); this.Controls.Add(this.comboBoxTypePortholes); this.Controls.Add(this.comboBoxPortholes); this.Controls.Add(this.labelPortholes); @@ -220,5 +232,6 @@ private Label labelPortholes; private ComboBox comboBoxPortholes; private ComboBox comboBoxTypePortholes; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs index f505933..94c2502 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs @@ -20,6 +20,18 @@ namespace AirplaneWithRadar _airplane?.DrawTransport(gr); pictureBoxAirplane.Image = bmp; } + + /// + /// + /// + private void SetData() + { + Random rnd = new(); + _airplane.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height); + toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}"; + toolStripStatusLabelWeight.Text = $": {_airplane.Airplane.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_airplane.Airplane.BodyColor.Name}"; + } /// /// "" /// @@ -86,5 +98,28 @@ namespace AirplaneWithRadar Draw(); } + private void ButtonCreateModif_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 DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2)), + typeAirplanePortholes); + _airplane.DrawningPortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text); + SetData(); + Draw(); + } } } \ No newline at end of file