From f5f9486ec06cf0918b22e65915f3fb93b37db98c Mon Sep 17 00:00:00 2001 From: Andrey_Abazov Date: Tue, 20 Sep 2022 13:00:14 +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?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawingAirBomber.cs | 23 +++++-- AirBomber/AirBomber/DrawingHeavyAirBomber.cs | 63 +++++++++++++++++++ AirBomber/AirBomber/EntityHeavyAirBomber.cs | 49 +++++++++++++++ AirBomber/AirBomber/FormAirBomber.Designer.cs | 13 ++++ AirBomber/AirBomber/FormAirBomber.cs | 28 +++++++++ 5 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 AirBomber/AirBomber/DrawingHeavyAirBomber.cs create mode 100644 AirBomber/AirBomber/EntityHeavyAirBomber.cs diff --git a/AirBomber/AirBomber/DrawingAirBomber.cs b/AirBomber/AirBomber/DrawingAirBomber.cs index 74e8b6f..efa3cca 100644 --- a/AirBomber/AirBomber/DrawingAirBomber.cs +++ b/AirBomber/AirBomber/DrawingAirBomber.cs @@ -11,15 +11,15 @@ namespace AirBomber /// /// Класс-сущность /// - public EntityAirBomber AirBomber { private set; get; } + public EntityAirBomber AirBomber { protected set; get; } /// /// Левая координата отрисовки бомбардировщика /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки бомбардировщика /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -47,6 +47,21 @@ namespace AirBomber AirBomber = new EntityAirBomber(speed, weight, bodyColor); } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес бомбардировщика + /// Цвет корпуса + /// Ширина отрисовки бомбардировщика + /// Высота отрисовки бомбардировщика + protected DrawingAirBomber(int speed, float weight, Color bodyColor, int carWidth, int carHeight) : + this(speed, weight, bodyColor) + { + _airBomberWidth = carWidth; + _airBomberHeight = carHeight; + } + /// /// Установка позиции омбардировщика /// @@ -112,7 +127,7 @@ namespace AirBomber /// Отрисовка бомбардировщика /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/AirBomber/AirBomber/DrawingHeavyAirBomber.cs b/AirBomber/AirBomber/DrawingHeavyAirBomber.cs new file mode 100644 index 0000000..0520f97 --- /dev/null +++ b/AirBomber/AirBomber/DrawingHeavyAirBomber.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawingHeavyAirBomber : DrawingAirBomber + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public DrawingHeavyAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor, 110, 100) + { + AirBomber = new EntityHeavyAirBomber(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + public override void DrawTransport(Graphics g) + { + if (AirBomber is not EntityHeavyAirBomber heavyAirBomber) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(heavyAirBomber.DopColor); + + if (heavyAirBomber.Bombs) + { + g.FillEllipse(dopBrush, _startPosX + 45, _startPosY, 20, 10); + g.FillEllipse(dopBrush, _startPosX + 45, _startPosY + 90, 20, 10); + g.DrawEllipse(pen, _startPosX + 45, _startPosY, 20, 10); + g.DrawEllipse(pen, _startPosX + 45, _startPosY + 90, 20, 10); + } + + base.DrawTransport(g); + + if (heavyAirBomber.TailLine) //TODO отрисовка полоски на хвосте + { + g.FillRectangle(dopBrush, _startPosX + 95, _startPosY + 30, 15, 5); + g.FillRectangle(dopBrush, _startPosX + 95, _startPosY + 65, 15, 5); + } + + if (heavyAirBomber.FuelTank) //TODO отрисовка топливных баков + { + g.FillEllipse(dopBrush, _startPosX + 23, _startPosY + 42, 25, 15); + g.FillEllipse(dopBrush, _startPosX + 53, _startPosY + 42, 25, 15); + g.FillEllipse(dopBrush, _startPosX + 83, _startPosY + 42, 25, 15); + g.DrawEllipse(pen, _startPosX + 23, _startPosY + 42, 25, 15); + g.DrawEllipse(pen, _startPosX + 53, _startPosY + 42, 25, 15); + g.DrawEllipse(pen, _startPosX + 83, _startPosY + 42, 25, 15); + } + } + } +} diff --git a/AirBomber/AirBomber/EntityHeavyAirBomber.cs b/AirBomber/AirBomber/EntityHeavyAirBomber.cs new file mode 100644 index 0000000..4f15db4 --- /dev/null +++ b/AirBomber/AirBomber/EntityHeavyAirBomber.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + /// + /// Класс-сущность "Тяжелый бомбардировщик" + /// + internal class EntityHeavyAirBomber : EntityAirBomber + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия бомб + /// + public bool Bombs { get; private set; } + /// + /// Признак наличия топливных баков + /// + public bool FuelTank { get; private set; } + /// + /// Признак наличия полосы на хвосте + /// + public bool TailLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес бомбардировщика + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public EntityHeavyAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool fuelTank, bool tailLine) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Bombs = bombs; + FuelTank = fuelTank; + TailLine = tailLine; + } + } +} diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index cac5394..d3661f3 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -143,11 +144,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(112, 395); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(120, 29); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // // FormAirBomber // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(882, 453); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonCreateAirBomber); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -177,5 +189,6 @@ private Button buttonLeft; private Button buttonDown; private Button buttonRight; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 3f41ac3..968caa2 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -67,5 +67,33 @@ namespace AirBomber _airBomber?.ChangeBorders(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Draw(); } + + /// + /// + /// + private void SetData() + { + Random rnd = new(); + _airBomber.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + toolStripStatusLabelSpeed.Text = $": {_airBomber.AirBomber.Speed}"; + toolStripStatusLabelWeight.Text = $": {_airBomber.AirBomber.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_airBomber.AirBomber.BodyColor.Name}"; + } + + /// + /// "" + /// + /// + /// + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _airBomber = new DrawingHeavyAirBomber(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(); + } } } \ No newline at end of file