diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs index a80a5f2..3a16ac1 100644 --- a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -8,9 +8,9 @@ namespace GasolineTanker { internal class DrawingGasolineTanker { - public EnityGasolineTanker GasolineTanker { get; private set; } - private float _startPosX; - private float _startPosY; + public EnityGasolineTanker GasolineTanker { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; private readonly int _gasolineTankerWidth = 160; @@ -21,6 +21,13 @@ namespace GasolineTanker GasolineTanker = new EnityGasolineTanker(speed, weight, bodyColor); } + protected DrawingGasolineTanker(int speed, float weight, Color bodyColor, int gasolineTankerWidth, int gasolineTankerHeight) : + this(speed, weight, bodyColor) + { + _gasolineTankerWidth = gasolineTankerWidth; + _gasolineTankerHeight = gasolineTankerHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x >= 0 && x + _gasolineTankerWidth <= width && y >= 0 && y + _gasolineTankerHeight <= height) @@ -70,7 +77,7 @@ namespace GasolineTanker break; } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs new file mode 100644 index 0000000..7e5228d --- /dev/null +++ b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class DrawingImprovedGasolineTanker : DrawingGasolineTanker + { + public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool ornamentWheels) : + base(speed, weight, bodyColor, 160, 55) + { + GasolineTanker = new EntityImprovedGasolineTanker(speed, weight, bodyColor, dopColor, bodyKit, ornamentWheels); + } + public override void DrawTransport(Graphics g) + { + if (GasolineTanker is not EntityImprovedGasolineTanker improvedGasolineTanker) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(improvedGasolineTanker.DopColor); + + if (improvedGasolineTanker.BodyKit) + { + Brush brOrange = new SolidBrush(Color.Orange); + g.FillRectangle(brOrange, _startPosX + 25, _startPosY + 5, 100, 35); + } + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + if (improvedGasolineTanker.OrnamentWheels) + { + Pen penGray = new(Color.Gray); + Brush brBlack = new SolidBrush(Color.Gray); + g.DrawEllipse(penGray, _startPosX + 140, _startPosY + 50, 20, 5); + g.DrawEllipse(penGray, _startPosX + 40, _startPosY + 50, 20, 5); + g.DrawEllipse(penGray, _startPosX + 20, _startPosY + 50, 20, 5); + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs b/GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs new file mode 100644 index 0000000..161e86e --- /dev/null +++ b/GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class EntityImprovedGasolineTanker : EnityGasolineTanker + { + public Color DopColor { get; private set; } + public bool BodyKit { get; private set; } + public bool OrnamentWheels { get; private set; } + public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool ornamentWheels) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + OrnamentWheels = ornamentWheels; + } + } +} diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs index 101c56a..5be7d04 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs @@ -38,6 +38,7 @@ this.keyUp = new System.Windows.Forms.Button(); this.keyLeft = new System.Windows.Forms.Button(); this.keyRight = new System.Windows.Forms.Button(); + this.ButtonCreateImproved = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -141,11 +142,22 @@ this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // ButtonCreateImproved + // + this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393); + this.ButtonCreateImproved.Name = "ButtonCreateImproved"; + this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23); + this.ButtonCreateImproved.TabIndex = 7; + this.ButtonCreateImproved.Text = "Improved"; + this.ButtonCreateImproved.UseVisualStyleBackColor = true; + this.ButtonCreateImproved.Click += new System.EventHandler(this.ButtonCreateImproved_Click); + // // FormGasolineTanker // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(807, 450); + this.Controls.Add(this.ButtonCreateImproved); this.Controls.Add(this.keyRight); this.Controls.Add(this.keyLeft); this.Controls.Add(this.keyUp); @@ -155,7 +167,6 @@ this.Controls.Add(this.statusStrip1); this.Name = "FormGasolineTanker"; this.Text = "Gasoline tanker"; - this.Load += new System.EventHandler(this.FormGasolineTanker_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); @@ -176,5 +187,6 @@ private Button keyUp; private Button keyLeft; private Button keyRight; + private Button ButtonCreateImproved; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs index da801f3..c7d0f1e 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -14,6 +14,14 @@ namespace GasolineTanker _gasolineTanker?.DrawTransport(gr); pictureBoxGasolineTanker.Image = bmp; } + private void SetData() + { + Random rnd = new(); + _gasolineTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}"; + toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}"; + toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}"; + } private void PictureBoxCar_Resize(object sender, EventArgs e) { _gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); @@ -25,9 +33,7 @@ namespace GasolineTanker Random rnd = new(); _gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _gasolineTanker.SetPosition(rnd.Next(10, 100),rnd.Next(50, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); - toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}"; - toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}"; - toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}"; + SetData(); Draw(); } @@ -58,5 +64,16 @@ namespace GasolineTanker _gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); Draw(); } + + private void ButtonCreateImproved_Click(object sender, EventArgs e) + { + Random rnd = new(); + _gasolineTanker = new DrawingImprovedGasolineTanker(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(); + } } } \ No newline at end of file