From eb0dcce5705a928e87dc0b81c990ccf04bb67f1b Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sat, 17 Sep 2022 21: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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AntiAircraftGun/DrawingAntiAircraftGun.cs | 22 ++++++-- .../DrawingUpdateAntiAircraftGun.cs | 51 +++++++++++++++++++ .../EntityUpdateAntiAircraftGun.cs | 40 +++++++++++++++ .../FormAntiAircraftGun.Designer.cs | 14 +++++ .../AntiAircraftGun/FormAntiAircraftGun.cs | 40 +++++++++++---- .../AntiAircraftGun/FormAntiAircraftGun.resx | 3 ++ 6 files changed, 157 insertions(+), 13 deletions(-) create mode 100644 AntiAircraftGun/AntiAircraftGun/DrawingUpdateAntiAircraftGun.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/EntityUpdateAntiAircraftGun.cs diff --git a/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs index 274c5f4..71380eb 100644 --- a/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs @@ -14,15 +14,15 @@ namespace AntiAircraftGun /// /// Класс-сущность /// - public EntityAntiAircraftGun AntiAircraftGun { private set; get; } + public EntityAntiAircraftGun AntiAircraftGun { protected set; get; } /// /// Левая координата отрисовки зенитного орудия /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки зенитного орудия /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -50,6 +50,20 @@ namespace AntiAircraftGun AntiAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor); } /// + /// Инициализация свойств + /// + /// Скорость + /// Вес зенитного орудия + /// Цвет корпуса + /// Ширина отрисовки зенитного орудия + /// Высота отрисовки зенитного орудия + protected DrawingAntiAircraftGun(int speed, float weight, Color bodyColor, int antiAircrafGunWidth, int antiAircrafGunHeight) : + this(speed, weight, bodyColor) + { + _antiAircrafGunWidth = antiAircrafGunWidth; + _antiAircrafGunHeight = antiAircrafGunHeight; + } + /// /// Установка позиции зенитного орудия /// /// Координата X @@ -112,7 +126,7 @@ namespace AntiAircraftGun /// Отрисовка зенитного орудия /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/AntiAircraftGun/AntiAircraftGun/DrawingUpdateAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/DrawingUpdateAntiAircraftGun.cs new file mode 100644 index 0000000..c25d471 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/DrawingUpdateAntiAircraftGun.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun +{ + internal class DrawingUpdateAntiAircraftGun : DrawingAntiAircraftGun + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес зенитного орудия + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия башни с орудием + /// Признак наличия радара + public DrawingUpdateAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, bool gun, bool radar) : + base(speed, weight, bodyColor, 110, 75) + { + AntiAircraftGun = new EntityUpdateAntiAircraftGun(speed, weight, bodyColor, dopColor, gun, radar); + } + public override void DrawTransport(Graphics g) + { + if (AntiAircraftGun is not EntityUpdateAntiAircraftGun updateAntiAircraftGun) + { + return; + } + Pen dopPen = new(updateAntiAircraftGun.DopColor, 4); + Brush dopBrush = new SolidBrush(updateAntiAircraftGun.DopColor); + _startPosY += 35; + base.DrawTransport(g); + _startPosY -= 35; + if (updateAntiAircraftGun.Gun) + { + g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 20, 25, 15); + g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 25, 50, 5); + g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 30, 20, 5); + } + if (updateAntiAircraftGun.Radar) + { + g.DrawLine(dopPen, _startPosX + 27, _startPosY + 35, _startPosX + 27, _startPosY + 20); + g.FillPie(dopBrush, _startPosX + 3, _startPosY, 30, 30, -45, 180); + g.DrawLine(dopPen, _startPosX + 20, _startPosY + 15, _startPosX + 15, _startPosY + 10); + g.FillEllipse(dopBrush, _startPosX + 10, _startPosY + 5, 10, 10); + } + } + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/EntityUpdateAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/EntityUpdateAntiAircraftGun.cs new file mode 100644 index 0000000..ff00aa8 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/EntityUpdateAntiAircraftGun.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun +{ + internal class EntityUpdateAntiAircraftGun : EntityAntiAircraftGun + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия башни с орудием + /// + public bool Gun { get; private set; } + /// + /// Признак наличия радара + /// + public bool Radar { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес зенитного орудия + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия башни с орудием + /// Признак наличия радара + public EntityUpdateAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, bool gun, bool radar) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Gun = gun; + Radar = radar; + } + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs index 32da52c..57fd6b3 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); + this.buttonCreareModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -142,11 +143,23 @@ this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreareModif + // + this.buttonCreareModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreareModif.Location = new System.Drawing.Point(111, 381); + this.buttonCreareModif.Name = "buttonCreareModif"; + this.buttonCreareModif.Size = new System.Drawing.Size(125, 29); + this.buttonCreareModif.TabIndex = 7; + this.buttonCreareModif.Text = "Модификация"; + this.buttonCreareModif.UseVisualStyleBackColor = true; + this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click); + // // FormAntiAircraftGun // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 451); + this.Controls.Add(this.buttonCreareModif); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); @@ -178,5 +191,6 @@ private Button buttonLeft; private Button buttonRight; private Button buttonDown; + private Button buttonCreareModif; } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs index f4902d0..bb62ffc 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs @@ -23,6 +23,17 @@ namespace AntiAircraftGun pictureBoxAntiAircraftGun.Image = bmp; } } + /// + /// + /// + private void SetData() + { + Random rnd = new(); + _antiAircrafGun.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); + toolStripStatusLabelSpeed.Text = $": {_antiAircrafGun.AntiAircraftGun.Speed}"; + toolStripStatusLabelWeight.Text = $": {_antiAircrafGun.AntiAircraftGun.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_antiAircrafGun.AntiAircraftGun.BodyColor.Name}"; + } /// /// "" @@ -31,15 +42,11 @@ namespace AntiAircraftGun /// private void ButtonCreate_Click(object sender, EventArgs e) { - Random rnd = new(); - _antiAircrafGun = new DrawingAntiAircraftGun(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _antiAircrafGun.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), - pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); - toolStripStatusLabelSpeed.Text = $": {_antiAircrafGun.AntiAircraftGun.Speed}"; - toolStripStatusLabelWeight.Text = $": {_antiAircrafGun.AntiAircraftGun.Weight}"; - toolStripStatusLabelBodyColor.Text = $": {_antiAircrafGun.AntiAircraftGun.BodyColor.Name}"; - Draw(); + Random rnd = new(); + _antiAircrafGun = new DrawingAntiAircraftGun(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); + Draw(); } /// /// @@ -77,5 +84,20 @@ namespace AntiAircraftGun _antiAircrafGun?.ChangeBorders(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); Draw(); } + /// + /// "" + /// + /// + /// + private void ButtonCreareModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _antiAircrafGun = new DrawingUpdateAntiAircraftGun(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))); + SetData(); + Draw(); + } } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.resx b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.resx index 2c0949d..bbf576a 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.resx +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.resx @@ -60,4 +60,7 @@ 17, 17 + + 79 + \ No newline at end of file