From 7196d002ecf50821d57eb67afba8ea261dd33209 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 6 Oct 2022 02:24:09 +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 --- .../AirplaneWithRadar/DrawingAirplane.cs | 14 ++++-- .../DrawningAirplaneWithRadar.cs | 48 +++++++++++++++++++ .../EntityAirplaneWithRadar.cs | 36 ++++++++++++++ .../FormAirplane.Designer.cs | 13 +++++ .../AirplaneWithRadar/FormAirplane.cs | 27 ++++++++++- 5 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs index 4555639..031f4c0 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs @@ -8,9 +8,9 @@ namespace AirplaneWithRadar { internal class DrawingAirplane { - public EntityAirplane Airplane { get; private set; } - private float _startPosX; - private float _startPosY; + public EntityAirplane Airplane { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; private readonly int _airplaneWidth = 50; @@ -19,6 +19,12 @@ namespace AirplaneWithRadar { Airplane = new EntityAirplane(speed, weight, bodyColor); } + protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : + this(speed, weight, bodyColor) + { + _airplaneWidth = airplaneWidth; + _airplaneHeight = airplaneHeight; + } public void SetPosition(int x, int y, int width, int height) { if (x + _airplaneWidth <= width && y + _airplaneHeight <= height && x >= 0 && y >= 0) @@ -67,7 +73,7 @@ namespace AirplaneWithRadar break; } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs new file mode 100644 index 0000000..ef67c7b --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class DrawningAirplaneWithRadar : DrawingAirplane + { + public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) : + base(speed, weight, bodyColor, 135, 60) + { + Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, ladder, window); + } + public override void DrawTransport(Graphics g) + { + if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar) + { + return; + } + + Pen pen = new(Color.Black, 2); + Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor); + + base.DrawTransport(g); + + if (airplaneWithRadar.Radar) + { + g.DrawEllipse(new Pen(Color.Black), _startPosX + 18, _startPosY + 3, 9, 4); + g.DrawRectangle(new Pen(Color.Black), _startPosX + 20, _startPosY + 6, 5, 4); + } + + if (airplaneWithRadar.Window) + { + g.DrawEllipse(new Pen(Color.Black), _startPosX + 40, _startPosY + 13, 5, 5); + } + + if (airplaneWithRadar.Ladder) + { + g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 18, _startPosX + 3, _startPosY + 12); + g.DrawLine(new Pen(Color.Black), _startPosX + 7, _startPosY + 18, _startPosX + 7, _startPosY + 12); + g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 16, _startPosX + 7, _startPosY + 16); + g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 13, _startPosX + 7, _startPosY + 13); + } + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs new file mode 100644 index 0000000..5a2409d --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class EntityAirplaneWithRadar : EntityAirplane + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия радара + /// + public bool Radar { get; private set; } + /// + /// Признак наличия лестницы + /// + public bool Ladder { get; private set; } + /// + /// Признак наличия окон + /// + public bool Window { get; private set; } + public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Radar = radar; + Ladder = ladder; + Window = window; + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs index ae453fa..d165b40 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs @@ -38,6 +38,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); + this.buttonCreateModify = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -143,11 +144,22 @@ this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModify + // + this.buttonCreateModify.Location = new System.Drawing.Point(111, 391); + this.buttonCreateModify.Name = "buttonCreateModify"; + this.buttonCreateModify.Size = new System.Drawing.Size(133, 29); + this.buttonCreateModify.TabIndex = 7; + this.buttonCreateModify.Text = "Модификация"; + this.buttonCreateModify.UseVisualStyleBackColor = true; + this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_Click); + // // FormAirplane // 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.buttonCreateModify); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -177,5 +189,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; + private Button buttonCreateModify; } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs index 2d04ac0..7b1960c 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs @@ -14,14 +14,22 @@ namespace AirplaneWithRadar _airplane?.DrawTransport(gr); pictureBoxAirplane.Image = bmp; } - private void ButtonCreate_Click(object sender, EventArgs e) + /// + /// + /// + private void SetData() { Random rnd = new(); - _airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height); toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}"; toolStripStatusLabelWeight.Text = $": {_airplane.Airplane.Weight}"; toolStripStatusLabelBodyColor.Text = $": {_airplane.Airplane.BodyColor.Name}"; + } + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) @@ -50,5 +58,20 @@ namespace AirplaneWithRadar _airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height); Draw(); } + /// + /// "" + /// + /// + /// + private void buttonCreateModify_Click(object sender, EventArgs e) + { + Random rnd = new(); + _airplane = new DrawningAirplaneWithRadar(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)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } } } \ No newline at end of file