From cf4b1b18eceddaad5c31b61313b7b93ede26c962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Tue, 4 Oct 2022 17:41:20 +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 --- AirBomber/AirBomber/DrawningBomber.cs | 18 ++++--- AirBomber/AirBomber/DrawningWarplane.cs | 53 +++++++++++++++++++ AirBomber/AirBomber/EntityWarplane.cs | 25 +++++++++ AirBomber/AirBomber/FormAirBomber.Designer.cs | 14 +++++ AirBomber/AirBomber/FormAirBomber.cs | 23 +++++++- 5 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 AirBomber/AirBomber/DrawningWarplane.cs create mode 100644 AirBomber/AirBomber/EntityWarplane.cs diff --git a/AirBomber/AirBomber/DrawningBomber.cs b/AirBomber/AirBomber/DrawningBomber.cs index 91422e1..ed8491e 100644 --- a/AirBomber/AirBomber/DrawningBomber.cs +++ b/AirBomber/AirBomber/DrawningBomber.cs @@ -8,9 +8,9 @@ namespace AirBomber { internal class DrawningBomber { - public EntityAirBomber AirBomber { private set; get; } - private float _startPosX; - private float _startPosY; + public EntityAirBomber AirBomber { protected set; get; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; private readonly int _airBomberWidth = 100; @@ -21,6 +21,13 @@ namespace AirBomber AirBomber = new EntityAirBomber(speed, weight, bodyColor); } + protected DrawningBomber(int speed, float weight, Color bodyColor, int airBomberWidth, int airBomberHeight) : + this (speed, weight, bodyColor) + { + _airBomberWidth = airBomberWidth; + _airBomberHeight = airBomberHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x + _airBomberWidth > width || x < 0) return; @@ -66,7 +73,7 @@ namespace AirBomber } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { @@ -101,8 +108,7 @@ namespace AirBomber new Point((int)(_startPosX), (int)(_startPosY + _airBomberHeight / 2)), new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 - 5)), new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 + 5)), - }); - + }); } public void ChangeBorders(int width, int height) diff --git a/AirBomber/AirBomber/DrawningWarplane.cs b/AirBomber/AirBomber/DrawningWarplane.cs new file mode 100644 index 0000000..e5b4c34 --- /dev/null +++ b/AirBomber/AirBomber/DrawningWarplane.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawningWarplane : DrawningBomber + { + public DrawningWarplane(int speed, float weight, Color bodyColor, Color dopColor, bool engines, bool weapons) : + base(speed, weight, bodyColor, 120, 120) + { + AirBomber = new EntityWarplane(speed, weight, bodyColor, dopColor, engines, weapons); + } + + public override void DrawTransport(Graphics g) + { + if (AirBomber is not EntityWarplane warplane) + { + return; + } + + Pen pen = new Pen(Color.Black); + Brush dopBrush = new SolidBrush(warplane.DopColor); + + if (warplane.Engines) + { + + g.FillEllipse(dopBrush, _startPosX + 50, _startPosY + 15, 30, 15); + g.FillEllipse(dopBrush, _startPosX + 45, _startPosY + 35, 35, 15); + g.FillEllipse(dopBrush, _startPosX + 45, _startPosY + 70, 35, 15); + g.FillEllipse(dopBrush, _startPosX + 50, _startPosY + 90, 30, 15); + + g.DrawEllipse(pen, _startPosX + 50, _startPosY + 15, 30, 15); + g.DrawEllipse(pen, _startPosX + 45, _startPosY + 35, 35, 15); + g.DrawEllipse(pen, _startPosX + 45, _startPosY + 70, 35, 15); + g.DrawEllipse(pen, _startPosX + 50, _startPosY + 90, 30, 15); + } + if (warplane.Weapons) + { + g.FillRectangle(dopBrush, _startPosX + 40, _startPosY, 30, 5); + g.FillRectangle(dopBrush, _startPosX + 40, _startPosY + 115, 30, 5); + + g.DrawRectangle(pen, _startPosX + 40, _startPosY, 30, 5); + g.DrawRectangle(pen, _startPosX + 40, _startPosY + 115, 30, 5); + } + + base.DrawTransport(g); + } + } +} diff --git a/AirBomber/AirBomber/EntityWarplane.cs b/AirBomber/AirBomber/EntityWarplane.cs new file mode 100644 index 0000000..f66ecac --- /dev/null +++ b/AirBomber/AirBomber/EntityWarplane.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class EntityWarplane : EntityAirBomber + { + public Color DopColor { get; private set; } + + public bool Engines { get; private set; } + + public bool Weapons { get; private set; } + + public EntityWarplane(int speed, float weight, Color bodyColor, Color dopColor, bool engines, bool weapons) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Engines = engines; + Weapons = weapons; + } + } +} diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 9234790..47ac65b 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.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -141,11 +142,23 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonCreate_Move); // + // buttonCreateModif + // + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(109, 455); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 35); + 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(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(874, 515); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -175,5 +188,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 f2b0106..8703674 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -1,3 +1,5 @@ +using System; + namespace AirBomber { public partial class FormAirBomber : Form @@ -16,14 +18,20 @@ namespace AirBomber pictureBoxAirBomber.Image = bmp; } - private void ButtonCreate_Click(object sender, EventArgs e) + private void SetData() { Random rnd = new(); - _airBomber = new DrawningBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _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}"; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _airBomber = new DrawningBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } @@ -53,5 +61,16 @@ namespace AirBomber _airBomber?.ChangeBorders(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _airBomber = new DrawningWarplane(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