diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs index 0b0acdd..5ca6b12 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs @@ -9,17 +9,23 @@ namespace AirPlaneWithRadar { internal class DrawingPlain { - public EntetyPlain Plain { get; private set; } - private float startPosX; - private float startPosY; + public EntetyPlain Plain { get; protected set; } + protected float startPosX; + protected float startPosY; private int? pictureWidth = null; private int? pictureHeight = null; protected readonly int plainWidth = 120; - protected readonly int plainHeight =70; + protected readonly int plainHeight = 70; public DrawingPlain(int speed, float weight, Color bodycolor) { Plain = new EntetyPlain(speed, weight, bodycolor); } + protected DrawingPlain(int speed, float weight,Color bodyColor,int plainWidth,int plainHeight): + this(speed,weight, bodyColor) + { + this.plainWidth = plainWidth; + this.plainHeight = plainHeight; + } public void setPosition(int x,int y,int width,int height) { @@ -58,7 +64,7 @@ namespace AirPlaneWithRadar break; } } - public void DrawTransoprt (Graphics g) + public virtual void DrawTransoprt (Graphics g) { if(startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue) { diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs new file mode 100644 index 0000000..9747a0e --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace AirPlaneWithRadar +{ + internal class DrawingRadarPlane : DrawingPlain + { + public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60) + { + Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox); + } + public override void DrawTransoprt(Graphics g) + { + if(Plain is not RadioPlane radioPlane) + { + return; + } + Pen pen = new(Color.Black); + Brush doBrush = new SolidBrush(radioPlane.DopColor); + base.DrawTransoprt(g); + if (radioPlane.OilBox) + { + g.DrawRectangle(pen, startPosX + 40, startPosY + 48, 20, 10); + g.FillRectangle(doBrush, startPosX + 40, startPosY + 48, 20, 10); + + g.DrawRectangle(pen, startPosX , startPosY+15, 30, 10); + g.FillRectangle(doBrush, startPosX, startPosY + 15, 30, 10); + } + if (radioPlane.Radar) + { + g.FillRectangle(doBrush, startPosX + 55, startPosY + 20, 10, 10); + g.FillEllipse(doBrush, startPosX + 40, startPosY + 13, 40, 10); + } + + } + } +} diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.Designer.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.Designer.cs index 03e91d1..91f6fb9 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.Designer.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.Designer.cs @@ -38,6 +38,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.ButtonCreate = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlain)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -146,11 +147,22 @@ this.ButtonCreate.UseVisualStyleBackColor = true; this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(125, 259); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(134, 29); + this.buttonCreateModif.TabIndex = 8; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // // FormPlain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(535, 318); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.ButtonCreate); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -180,5 +192,6 @@ private Button buttonRight; public ToolStripStatusLabel toolStripStatusLabelSpeed; private Button ButtonCreate; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.cs index 25cdcc4..8ab85cd 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormPlain.cs @@ -18,17 +18,22 @@ namespace AirPlaneWithRadar _plain?.DrawTransoprt(gr); pictureBoxPlain.Image = bmp; } - + private void SetData() + { + Random rnd = new(); + _plain.setPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxPlain.Width, pictureBoxPlain.Height); + toolStripStatusLabelSpeed.Text = $": {_plain.Plain.Speed}"; + toolStripStatusLabelWeight.Text = $": {_plain.Plain.Weight}"; + toolStripStatusLabelColor.Text = $": {_plain.Plain.BodyColor.Name}"; + } private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _plain = new DrawingPlain(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _plain.setPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxPlain.Width, pictureBoxPlain.Height); - toolStripStatusLabelSpeed.Text = $": {_plain.Plain.Speed}"; - toolStripStatusLabelWeight.Text = $": {_plain.Plain.Weight}"; - toolStripStatusLabelColor.Text = $": {_plain.Plain.BodyColor.Name}"; + + SetData(); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) @@ -57,8 +62,21 @@ namespace AirPlaneWithRadar _plain?.ChangeBorders(pictureBoxPlain.Width, pictureBoxPlain.Height); Draw(); } - + private void buttonCreateModif_Click(object sender, EventArgs e) + { + + Random rnd = new(); + _plain = new DrawingRadarPlane(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(); + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/RadioPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/RadioPlane.cs new file mode 100644 index 0000000..294a489 --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/RadioPlane.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + internal class RadioPlane : EntetyPlain + { + public Color DopColor { get; set; } + public bool Radar { get; set; } + public bool OilBox { get; set; } + public RadioPlane(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + Radar = radar; + OilBox = oilBox; + } + } +}