From 1b9308c71221dd98a0792b72a0c66a2bc037dd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B8=D1=80=20=D0=9D=D1=83=D0=B3=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Sun, 9 Oct 2022 21:08:29 +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 --- Bus/Bus/DrawingBus.cs | 16 ++++++-- Bus/Bus/DrawingSportBus.cs | 81 +++++++++++++++++++++++++++++++++++++ Bus/Bus/EntitySportBus.cs | 25 ++++++++++++ Bus/Bus/FormBus.Designer.cs | 13 ++++++ Bus/Bus/FormBus.cs | 26 ++++++++++-- 5 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 Bus/Bus/DrawingSportBus.cs create mode 100644 Bus/Bus/EntitySportBus.cs diff --git a/Bus/Bus/DrawingBus.cs b/Bus/Bus/DrawingBus.cs index 00a4a2c..ab1cb38 100644 --- a/Bus/Bus/DrawingBus.cs +++ b/Bus/Bus/DrawingBus.cs @@ -8,9 +8,9 @@ namespace Bus { internal class DrawingBus { - public EntityBus Bus { get; private set; } - private float _startPosX; - private float _startPosY; + public EntityBus Bus { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; protected readonly int _busWidth = 157; @@ -21,6 +21,14 @@ namespace Bus Bus = new EntityBus(speed, weight, bodyColor); } + + protected DrawingBus(int speed, float weight, Color bodyColor, int busWidth, int busHeight) : + this(speed, weight, bodyColor) + { + _busWidth = busWidth; + _busHeight = busHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x < 0 || y < 0 || width < x+_busWidth || height < y + _busHeight) @@ -71,7 +79,7 @@ namespace Bus } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { diff --git a/Bus/Bus/DrawingSportBus.cs b/Bus/Bus/DrawingSportBus.cs new file mode 100644 index 0000000..7d20d4c --- /dev/null +++ b/Bus/Bus/DrawingSportBus.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bus +{ + internal class DrawingSportBus : DrawingBus + { + public DrawingSportBus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor) + { + Bus = new EntitySportBus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + + public override void DrawTransport(Graphics g) + { + if (Bus is not EntitySportBus sportBus) + { + return; + } + Pen pen = new Pen(Color.Black); + Brush dopBrush = new SolidBrush(sportBus.DopColor); + + if (sportBus.BodyKit) + { + + + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + + + Brush brBlue = new SolidBrush(Color.Blue); + g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); + } + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + if (sportBus.Sportline) + { + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + + + Brush brBlue = new SolidBrush(Color.Blue); + g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); + } + + if (sportBus.Wing) + { + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + + + Brush brBlue = new SolidBrush(Color.Blue); + g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); + } + + + + + } + } +} diff --git a/Bus/Bus/EntitySportBus.cs b/Bus/Bus/EntitySportBus.cs new file mode 100644 index 0000000..8e06a6a --- /dev/null +++ b/Bus/Bus/EntitySportBus.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bus +{ + internal class EntitySportBus : EntityBus + { + public Color DopColor { get; private set; } + public bool BodyKit { get; private set; } + public bool Wing { get; private set; } + public bool Sportline { get; private set; } + + public EntitySportBus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportline) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + Wing = wing; + Sportline = sportline; + } + } +} diff --git a/Bus/Bus/FormBus.Designer.cs b/Bus/Bus/FormBus.Designer.cs index 73895eb..57ee227 100644 --- a/Bus/Bus/FormBus.Designer.cs +++ b/Bus/Bus/FormBus.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.pictureBoxBus)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -143,11 +144,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(111, 384); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(141, 29); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormBus // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(827, 455); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -178,5 +190,6 @@ private Button buttonLeft; private Button buttonDown; private Button buttonRight; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Bus/Bus/FormBus.cs b/Bus/Bus/FormBus.cs index 49fa996..3d0f408 100644 --- a/Bus/Bus/FormBus.cs +++ b/Bus/Bus/FormBus.cs @@ -18,14 +18,21 @@ namespace Bus pictureBoxBus.Image = bmp; } + private void SetData() + { + Random rnd = new(); + _bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBus.Width, pictureBoxBus.Height); + toolStripStatusLabelSpeed.Text = $": {_bus.Bus?.Speed}"; + toolStripStatusLabelWeight.Text = $": {_bus.Bus?.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_bus.Bus?.BodyColor.Name}"; + + } + private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _bus.SetPosition(rnd.Next(10,100), rnd.Next(10, 100), pictureBoxBus.Width, pictureBoxBus.Height); - toolStripStatusLabelSpeed.Text = $": {_bus.Bus?.Speed}"; - toolStripStatusLabelWeight.Text = $": {_bus.Bus?.Weight}"; - toolStripStatusLabelBodyColor.Text = $": {_bus.Bus?.BodyColor.Name}"; + SetData(); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) @@ -54,5 +61,16 @@ namespace Bus _bus?.ChangeBorbers(pictureBoxBus.Width, pictureBoxBus.Height); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _bus = new DrawingSportBus(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, 1)), Convert.ToBoolean(rnd.Next(0,1)), Convert.ToBoolean(rnd.Next(0,1))); + SetData(); + Draw(); + } } } \ No newline at end of file