From 1ecf2e39605770b9f0b7a8b78f9cf6c2bb98423b Mon Sep 17 00:00:00 2001 From: "A.Novopoltsev" Date: Fri, 16 Dec 2022 19:15:56 +0300 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 | 71 +++++++++++++++++++++++ Warship/Warship/EntityAdvancedWarship.cs | 24 ++++++++ Warship/Warship/FormWarship.Designer.cs | 13 +++++ Warship/Warship/FormWarship.cs | 21 ++++++- 4 files changed, 128 insertions(+), 1 deletion(-) 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..d040237 --- /dev/null +++ b/Warship/Warship/DrawingAdvancedWarship.cs @@ -0,0 +1,71 @@ +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/EntityAdvancedWarship.cs b/Warship/Warship/EntityAdvancedWarship.cs new file mode 100644 index 0000000..ff91ad1 --- /dev/null +++ b/Warship/Warship/EntityAdvancedWarship.cs @@ -0,0 +1,24 @@ +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 bd15e34..87693f9 100644 --- a/Warship/Warship/FormWarship.Designer.cs +++ b/Warship/Warship/FormWarship.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -135,11 +136,22 @@ this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(120, 381); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(100, 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.buttonDown); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonLeft); @@ -169,5 +181,6 @@ private Button buttonLeft; private Button buttonUp; private Button buttonDown; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Warship/Warship/FormWarship.cs b/Warship/Warship/FormWarship.cs index d56466a..6aa3d15 100644 --- a/Warship/Warship/FormWarship.cs +++ b/Warship/Warship/FormWarship.cs @@ -54,6 +54,25 @@ namespace Warship { _warship?.ChangeBorders(pictureBoxWarship.Width, pictureBoxWarship.Height); Draw(); - } + } + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + Color color1 = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog1 = new(); + if (dialog1.ShowDialog() == DialogResult.OK) + { + color1 = dialog1.Color; + } + Color color2 = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog2 = new(); + if (dialog2.ShowDialog() == DialogResult.OK) + { + color2 = dialog2.Color; + } + _warship = new DrawingAdvancedWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), color1, color2, 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