From 96d2bfbb8f3bd2edd42812b9dfc6e94d7e5fb9b4 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Tue, 20 Sep 2022 21:26: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 --- Warship/Warship/DrawingAdvancedWarship.cs | 70 +++++++++++++++++++++++ Warship/Warship/DrawingWarship.cs | 19 ++++-- Warship/Warship/EntityAdvancedWarship.cs | 23 ++++++++ Warship/Warship/FormWarship.Designer.cs | 25 ++++++-- Warship/Warship/FormWarship.cs | 22 +++++-- 5 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 Warship/Warship/DrawingAdvancedWarship.cs create mode 100644 Warship/Warship/EntityAdvancedWarship.cs diff --git a/Warship/Warship/DrawingAdvancedWarship.cs b/Warship/Warship/DrawingAdvancedWarship.cs new file mode 100644 index 0000000..ed98ec3 --- /dev/null +++ b/Warship/Warship/DrawingAdvancedWarship.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Warship +{ + internal class DrawingAdvancedWarship : DrawingWarship + { + public DrawingAdvancedWarship(int speed,float weight, Color bodyColor, Color dopColor, bool Helipad, bool Antenna, bool Missile) : base(speed, weight, bodyColor, 120, 50) + { + Warship = new EntityAdvancedWarship(speed, weight, bodyColor, dopColor, Helipad, Antenna, Missile); + } + public override void DrawTransport(Graphics g) + { + if (Warship is not EntityAdvancedWarship advancedWarship) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(advancedWarship.DopColor); + + if (advancedWarship.Missile) + { + g.FillPolygon(dopBrush, new Point[] + { + new Point(_startPosX+25,_startPosY+5-5),new Point(_startPosX+65,_startPosY+5-5), + new Point(_startPosX+75,_startPosY+10-5),new Point(_startPosX+25,_startPosY+10-5), + new Point(_startPosX+25,_startPosY+5-5) + } + ); + g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 5 - 5), new Point(_startPosX + 65, _startPosY + 5 - 5)); + g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 5 - 5), new Point(_startPosX + 75, _startPosY + 10 - 5)); + g.DrawLine(pen, new Point(_startPosX + 75, _startPosY + 10 - 5), new Point(_startPosX + 25, _startPosY + 10 - 5)); + g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 10 - 5), new Point(_startPosX + 25, _startPosY + 5 - 5)); + + g.FillPolygon(dopBrush, new Point[] + { + new Point(_startPosX+25,_startPosY+50-5),new Point(_startPosX+75,_startPosY+50-5), + new Point(_startPosX+65,_startPosY+55-5),new Point(_startPosX+25,_startPosY+55-5), + new Point(_startPosX+25,_startPosY+50-5) + } + ); + g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 50 - 5), new Point(_startPosX + 75, _startPosY + 50 - 5)); + g.DrawLine(pen, new Point(_startPosX + 75, _startPosY + 50 - 5), new Point(_startPosX + 65, _startPosY + 55 - 5)); + g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 55 - 5), new Point(_startPosX + 25, _startPosY + 55 - 5)); + g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 55 - 5), new Point(_startPosX + 25, _startPosY + 50 - 5)); + } + _startPosY += 5; + base.DrawTransport(g); + _startPosY -= 5; + + if (advancedWarship.Helipad) + { + g.FillEllipse(dopBrush, _startPosX + 85, _startPosY + 20-5, 20, 20); + g.DrawEllipse(pen, _startPosX + 85, _startPosY + 20-5, 20, 20); + g.DrawLine(pen, _startPosX + 90, _startPosY + 25 - 5, _startPosX + 90, _startPosY + 35 - 5); + g.DrawLine(pen, _startPosX + 90+10, _startPosY + 25 - 5, _startPosX + 90+10, _startPosY + 35 - 5); + g.DrawLine(pen, _startPosX + 90, _startPosY + 30 - 5, _startPosX + 100, _startPosY + 30 - 5); + } + if (advancedWarship.Antenna) + { + g.DrawLine(pen, _startPosX + 15, _startPosY + 20 - 5, _startPosX + 15, _startPosY + 40 - 5); + g.DrawLine(pen, _startPosX +10, _startPosY + 30 - 5, _startPosX + 20, _startPosY + 30 - 5); + } + } + } +} diff --git a/Warship/Warship/DrawingWarship.cs b/Warship/Warship/DrawingWarship.cs index 0fcbba0..0f7cf91 100644 --- a/Warship/Warship/DrawingWarship.cs +++ b/Warship/Warship/DrawingWarship.cs @@ -8,19 +8,26 @@ namespace Warship { internal class DrawingWarship { - public EntityWarship Warship { get; private set; } - private int _startPosX; - private int _startPosY; + public EntityWarship Warship { get; protected set; } + protected int _startPosX; + protected int _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; private readonly int _warshipWidth = 120; private readonly int _warshipHeight = 40; - public DrawingWarship(int speed, float weight,Color bodyColor) + public DrawingWarship(int speed, float weight, Color bodyColor) { - Warship = new EntityWarship(speed, weight, bodyColor); + Warship=new EntityWarship(speed, weight, bodyColor); } + protected DrawingWarship(int speed, float weight,Color bodyColor, int warshipWidth, int warshipHeight) : this(speed,weight,bodyColor) + { + _warshipWidth = warshipWidth; + _warshipHeight = warshipHeight; + } + + public void SetPosition(int x, int y, int width, int height) { if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height) @@ -71,7 +78,7 @@ namespace Warship } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { diff --git a/Warship/Warship/EntityAdvancedWarship.cs b/Warship/Warship/EntityAdvancedWarship.cs new file mode 100644 index 0000000..527e776 --- /dev/null +++ b/Warship/Warship/EntityAdvancedWarship.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Warship +{ + internal class EntityAdvancedWarship : EntityWarship + { + public Color DopColor { get; private set; } + public bool Helipad { get;private set; } + public bool Antenna { get; private set; } + public bool Missile { get; private set; } + public EntityAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, bool helipad, bool antenna, bool missile) : base(speed,weight,bodyColor) { + DopColor = dopColor; + Helipad = helipad; + Antenna = antenna; + Missile = missile; + } + + } +} diff --git a/Warship/Warship/FormWarship.Designer.cs b/Warship/Warship/FormWarship.Designer.cs index 46de26f..cf33e56 100644 --- a/Warship/Warship/FormWarship.Designer.cs +++ b/Warship/Warship/FormWarship.Designer.cs @@ -38,6 +38,7 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -51,7 +52,7 @@ this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxWarship.TabIndex = 0; this.pictureBoxWarship.TabStop = false; - this.pictureBoxWarship.Resize += new System.EventHandler(this.pictureBoxWarship_Resize); + this.pictureBoxWarship.Resize += new System.EventHandler(this.PictureBoxWarship_Resize); // // statusStrip // @@ -91,7 +92,7 @@ this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Создать"; this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); // // buttonDown // @@ -104,7 +105,7 @@ this.buttonDown.TabIndex = 3; this.buttonDown.Text = " "; this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonUp // @@ -117,7 +118,7 @@ this.buttonUp.TabIndex = 4; this.buttonUp.Text = " "; this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonRight // @@ -130,7 +131,7 @@ this.buttonRight.TabIndex = 5; this.buttonRight.Text = " "; this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonLeft // @@ -143,13 +144,24 @@ this.buttonLeft.TabIndex = 6; this.buttonLeft.Text = " "; this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 393); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); // // FormWarship // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonUp); @@ -179,5 +191,6 @@ private Button buttonUp; private Button buttonRight; private Button buttonLeft; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Warship/Warship/FormWarship.cs b/Warship/Warship/FormWarship.cs index f99c694..9ae9161 100644 --- a/Warship/Warship/FormWarship.cs +++ b/Warship/Warship/FormWarship.cs @@ -15,17 +15,23 @@ namespace Warship pictureBoxWarship.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + private void SetData() { Random rnd = new(); - _warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height); toolStripStatusLabelSpeed.Text = $"C: {_warship.Warship.Speed}"; toolStripStatusLabelWeight.Text = $": {_warship.Warship.Weight}"; toolStripStatusLabelBodyColor.Text = $": {_warship.Warship.BodyColor.Name}"; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } - private void buttonMove_Click(object sender, EventArgs e) + private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; switch (name) @@ -46,10 +52,18 @@ namespace Warship Draw(); } - private void pictureBoxWarship_Resize(object sender, EventArgs e) + private void PictureBoxWarship_Resize(object sender, EventArgs e) { _warship?.ChangeBorders(pictureBoxWarship.Width, pictureBoxWarship.Height); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _warship = new DrawingAdvancedWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), 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