From 41000f3cc55ac544fc6180538a734f5aadca2145 Mon Sep 17 00:00:00 2001 From: Danil Kargin Date: Wed, 5 Oct 2022 23:14:01 +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 --- AirFighter/AirFighter/DrawningAirFighter.cs | 14 ++- .../AirFighter/DrawningUpgradeAirFighter.cs | 99 +++++++++++++++++++ .../AirFighter/EntityUpgradeAirFighter.cs | 43 ++++++++ .../AirFighter/FormAirFighter.Designer.cs | 14 +++ AirFighter/AirFighter/FormAirFighter.cs | 29 +++++- 5 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 AirFighter/AirFighter/DrawningUpgradeAirFighter.cs create mode 100644 AirFighter/AirFighter/EntityUpgradeAirFighter.cs diff --git a/AirFighter/AirFighter/DrawningAirFighter.cs b/AirFighter/AirFighter/DrawningAirFighter.cs index edba9d3..f42f2e4 100644 --- a/AirFighter/AirFighter/DrawningAirFighter.cs +++ b/AirFighter/AirFighter/DrawningAirFighter.cs @@ -14,15 +14,15 @@ namespace AirFighter /// /// Класс-сущность /// - public EntityAirFighter AirFighter { private set; get; } + public EntityAirFighter AirFighter { protected set; get; } /// /// Левая координата отрисовки самолета /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки самолета /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -49,6 +49,12 @@ namespace AirFighter { AirFighter = new EntityAirFighter(speed, weight, bodyColor); } + protected DrawningAirFighter(int speed, float weight, Color bodyColor, int airFighterWight, int airFighterHeight) : + this(speed, weight, bodyColor) + { + _airFighterWidth = airFighterWight; + _airFighterHeight = airFighterHeight; + } /// /// Установка позиции самолета /// @@ -123,7 +129,7 @@ namespace AirFighter /// /// Отрисовка самолета /// - public void DrawAirFighter(Graphics g) + public virtual void DrawAirFighter(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { diff --git a/AirFighter/AirFighter/DrawningUpgradeAirFighter.cs b/AirFighter/AirFighter/DrawningUpgradeAirFighter.cs new file mode 100644 index 0000000..de85e9b --- /dev/null +++ b/AirFighter/AirFighter/DrawningUpgradeAirFighter.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirFighter +{ + internal class DrawningUpgradeAirFighter : DrawningAirFighter + { + /// + /// Инициализация свойств + /// + /// + /// + /// + /// + /// + /// + public DrawningUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWing, bool rocket) : + base(speed, weight, bodyColor, 85, 80) + { + AirFighter = new EntityUpgradeAirFighter(speed, weight, bodyColor, dopColor, dopWing, rocket); + } + public override void DrawAirFighter(Graphics g) + { + if(AirFighter is not EntityUpgradeAirFighter upgradeAirFighter) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(upgradeAirFighter.DopColor); + + _startPosX += 5; + _startPosY += 5; + base.DrawAirFighter(g); + _startPosX -= 5; + _startPosY -= 5; + + if (upgradeAirFighter.DopWing) + { + PointF[] _pointBackWing = + { + new PointF(_startPosX, _startPosY + 35), + new PointF(_startPosX, _startPosY + 45), + new PointF(_startPosX + 10, _startPosY + 40) + }; + PointF[] _pointLeftWing = + { + new PointF(_startPosX + 50, _startPosY + 35), + new PointF(_startPosX + 55, _startPosY + 30), + new PointF(_startPosX + 65, _startPosY + 35) + }; + PointF[] _pointRightWing = + { + new PointF(_startPosX + 50, _startPosY + 45), + new PointF(_startPosX + 55, _startPosY + 50), + new PointF(_startPosX + 65, _startPosY + 45) + }; + + g.FillPolygon(dopBrush, _pointBackWing); + g.FillPolygon(dopBrush, _pointLeftWing); + g.FillPolygon(dopBrush, _pointRightWing); + + g.DrawPolygon(pen, _pointBackWing); + g.DrawPolygon(pen, _pointLeftWing); + g.DrawPolygon(pen, _pointRightWing); + } + + if (upgradeAirFighter.Rocket) + { + PointF[] _pointLeftRocket = + { + new PointF(_startPosX + 35, _startPosY), + new PointF(_startPosX + 45, _startPosY), + new PointF(_startPosX + 50, _startPosY + 3), + new PointF(_startPosX + 45, _startPosY + 5), + new PointF(_startPosX + 35, _startPosY + 5) + }; + PointF[] _pointRightRocket = + { + new PointF(_startPosX + 35, _startPosY + 75), + new PointF(_startPosX + 45, _startPosY + 75), + new PointF(_startPosX + 50, _startPosY + 77), + new PointF(_startPosX + 45, _startPosY + 80), + new PointF(_startPosX + 35, _startPosY + 80) + }; + + g.FillPolygon(dopBrush, _pointLeftRocket); + g.FillPolygon(dopBrush, _pointRightRocket); + + g.DrawPolygon(pen, _pointLeftRocket); + g.DrawPolygon(pen, _pointRightRocket); + } + + } + } +} diff --git a/AirFighter/AirFighter/EntityUpgradeAirFighter.cs b/AirFighter/AirFighter/EntityUpgradeAirFighter.cs new file mode 100644 index 0000000..70f80cb --- /dev/null +++ b/AirFighter/AirFighter/EntityUpgradeAirFighter.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirFighter +{ + /// + /// Класс-сущность самолет разведчик + /// + internal class EntityUpgradeAirFighter : EntityAirFighter + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия дополнительных крыльев + /// + public bool DopWing { get; private set; } + /// + /// Признак наличия ракет + /// + public bool Rocket { get; private set; } + /// + /// Инициализация свойств + /// + /// + /// + /// + /// + /// + /// + public EntityUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWing, bool rocket) : + base(speed,weight,bodyColor) + { + DopColor = dopColor; + DopWing = dopWing; + Rocket = rocket; + } + } +} diff --git a/AirFighter/AirFighter/FormAirFighter.Designer.cs b/AirFighter/AirFighter/FormAirFighter.Designer.cs index fbca490..b5e7eda 100644 --- a/AirFighter/AirFighter/FormAirFighter.Designer.cs +++ b/AirFighter/AirFighter/FormAirFighter.Designer.cs @@ -38,6 +38,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonUpgrade = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -142,11 +143,23 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonUpgrade + // + this.buttonUpgrade.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonUpgrade.Location = new System.Drawing.Point(148, 379); + this.buttonUpgrade.Name = "buttonUpgrade"; + this.buttonUpgrade.Size = new System.Drawing.Size(127, 29); + this.buttonUpgrade.TabIndex = 7; + this.buttonUpgrade.Text = "Модификация"; + this.buttonUpgrade.UseVisualStyleBackColor = true; + this.buttonUpgrade.Click += new System.EventHandler(this.ButtonUpgrade_Click); + // // FormAirFighter // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonUpgrade); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonDown); @@ -176,5 +189,6 @@ private Button buttonDown; private Button buttonLeft; private Button buttonRight; + private Button buttonUpgrade; } } \ No newline at end of file diff --git a/AirFighter/AirFighter/FormAirFighter.cs b/AirFighter/AirFighter/FormAirFighter.cs index f5dc5f1..60b932e 100644 --- a/AirFighter/AirFighter/FormAirFighter.cs +++ b/AirFighter/AirFighter/FormAirFighter.cs @@ -18,6 +18,17 @@ namespace AirFighter pictureBoxAirFighter.Image = bmp; } /// + /// + /// + private void SetData() + { + Random rnd = new Random(); + _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); + toolStripStatusLabelSpeed.Text = $": {_airFighter.AirFighter?.Speed}"; + toolStripStatusLabelWeight.Text = $": {_airFighter.AirFighter?.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_airFighter.AirFighter?.BodyColor}"; + } + /// /// "" /// /// @@ -26,10 +37,7 @@ namespace AirFighter { Random rnd = new Random(); _airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); - toolStripStatusLabelSpeed.Text = $": {_airFighter.AirFighter?.Speed}"; - toolStripStatusLabelWeight.Text = $": {_airFighter.AirFighter?.Weight}"; - toolStripStatusLabelBodyColor.Text = $": {_airFighter.AirFighter?.BodyColor}"; + SetData(); Draw(); } /// @@ -67,5 +75,18 @@ namespace AirFighter _airFighter?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Draw(); } + /// + /// "" + /// + /// + /// + private void ButtonUpgrade_Click(object sender, EventArgs e) + { + Random rnd = new(); + _airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), 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))); + SetData(); + Draw(); + } } } \ No newline at end of file