From 5ac86cbb430b8289f4164046d5acf04076186fff Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sat, 15 Oct 2022 22:40:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=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 --- Airbus/Airbus/DrawningAirbus.cs | 83 +++++++++++++++++++++++++++++ Airbus/Airbus/DrawningPlane.cs | 14 +++-- Airbus/Airbus/EntityAirbus.cs | 46 ++++++++++++++++ Airbus/Airbus/FormPlane.Designer.cs | 17 +++++- Airbus/Airbus/FormPlane.cs | 23 +++++--- 5 files changed, 171 insertions(+), 12 deletions(-) create mode 100644 Airbus/Airbus/DrawningAirbus.cs create mode 100644 Airbus/Airbus/EntityAirbus.cs diff --git a/Airbus/Airbus/DrawningAirbus.cs b/Airbus/Airbus/DrawningAirbus.cs new file mode 100644 index 0000000..6392333 --- /dev/null +++ b/Airbus/Airbus/DrawningAirbus.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class DrawningAirbus : DrawningPlane + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public DrawningAirbus(int speed, float weight, Color bodyColor, Color + dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor, 140, 70) + { + Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + public override void DrawTransport(Graphics g) + { + if (Plane is not EntityAirbus Airbus) + { + return; + } + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(Airbus.DopColor); + Brush fireBrush = new SolidBrush(Color.Red); + Brush WindowBrush = new SolidBrush(Color.Blue); + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + if (Airbus.BodyKit) + { + //1 реактор + g.DrawRectangle(pen, _startPosX + 70, _startPosY + 50, 22, 16); + g.FillRectangle(dopBrush, _startPosX + 70, _startPosY + 50, 22, 16); + + g.FillEllipse(dopBrush, _startPosX + 84, _startPosY + 50, 16, 16); + + g.DrawEllipse(pen, _startPosX + 62, _startPosY + 50, 16, 16); + g.FillEllipse(fireBrush, _startPosX + 62, _startPosY + 50, 16, 16); + + //2 реактор + + g.DrawRectangle(pen, _startPosX + 8, _startPosY + 18, 22, 16); + g.FillRectangle(dopBrush, _startPosX + 8, _startPosY + 18, 22, 16); + + g.FillEllipse(dopBrush, _startPosX + 24, _startPosY + 18, 16, 16); + + g.DrawEllipse(pen, _startPosX, _startPosY + 18, 16, 16); + g.FillEllipse(fireBrush, _startPosX, _startPosY + 18, 16, 16); + + + } + if (Airbus.Wing) + { + + g.DrawLine(pen, _startPosX + 70, _startPosY + 20, _startPosX + 70, _startPosY + 35); + g.DrawLine(pen, _startPosX + 70, _startPosY + 20, _startPosX + 90, _startPosY + 35); + } + if (Airbus.SportLine) + { + g.DrawEllipse(pen, _startPosX + 110, _startPosY + 40, 9, 9); + g.FillEllipse(WindowBrush, _startPosX + 110, _startPosY + 40, 9, 9); + + } + + + } + + } +} diff --git a/Airbus/Airbus/DrawningPlane.cs b/Airbus/Airbus/DrawningPlane.cs index 4736f21..98175ae 100644 --- a/Airbus/Airbus/DrawningPlane.cs +++ b/Airbus/Airbus/DrawningPlane.cs @@ -11,16 +11,16 @@ namespace Airbus /// /// Класс-сущность /// - public EntityPlane Plane { get; private set; } + public EntityPlane Plane { get; protected set; } /// /// Левая координата отрисовки самолета /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки самолета /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -114,7 +114,13 @@ namespace Airbus /// Отрисовка самолета /// /// - public void DrawTransport(Graphics g) + /// + protected DrawningPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight) : this(speed, weight, bodyColor) + { + _PlaneWidth = planeWidth; + _PlaneHeight = planeHeight; + } + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/Airbus/Airbus/EntityAirbus.cs b/Airbus/Airbus/EntityAirbus.cs new file mode 100644 index 0000000..22d0bb4 --- /dev/null +++ b/Airbus/Airbus/EntityAirbus.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class EntityAirbus : EntityPlane + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool BodyKit { get; private set; } + /// + /// Признак наличия антикрыла + /// + public bool Wing { get; private set; } + /// + /// Признак наличия гоночной полосы + /// + public bool SportLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public EntityAirbus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } + + } +} diff --git a/Airbus/Airbus/FormPlane.Designer.cs b/Airbus/Airbus/FormPlane.Designer.cs index e2c6f80..693b54d 100644 --- a/Airbus/Airbus/FormPlane.Designer.cs +++ b/Airbus/Airbus/FormPlane.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -149,11 +150,22 @@ this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // - // FormAirbus + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(98, 285); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(99, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // + // FormPlane // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonLeft); @@ -162,7 +174,7 @@ this.Controls.Add(this.statusStrip1); this.Controls.Add(this.pictureBoxAirbus); this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.Name = "FormAirbus"; + this.Name = "FormPlane"; this.Text = "Самолет"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).EndInit(); this.statusStrip1.ResumeLayout(false); @@ -184,5 +196,6 @@ private Button buttonLeft; private Button buttonUp; private Button buttonDown; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormPlane.cs b/Airbus/Airbus/FormPlane.cs index 5a38b1c..a2aa505 100644 --- a/Airbus/Airbus/FormPlane.cs +++ b/Airbus/Airbus/FormPlane.cs @@ -28,6 +28,15 @@ namespace Airbus _plane?.DrawTransport(gr); pictureBoxAirbus.Image = bmp; } + + private void SetData() + { + Random rnd = new(); + _plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height); + toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}"; + } /// /// Обработка нажатия кнопки "Создать" /// @@ -35,13 +44,9 @@ namespace Airbus /// private void ButtonCreate_Click(object sender, EventArgs e) { - Random rnd = new(); _plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height); - toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}"; + SetData(); Draw(); } /// @@ -81,7 +86,13 @@ namespace Airbus Draw(); } - + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _plane = new DrawningAirbus(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)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } } }