diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs new file mode 100644 index 0000000..6901245 --- /dev/null +++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class DrawingContainerShip : DrawingShip + { + public DrawingContainerShip(int speed, float weight, Color bodyColor, Color + dopColor, bool crane, bool containers) : + base(speed, weight, bodyColor, 110, 60) + { + Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers); + } + public override void DrawTransport(Graphics g) + { + if (Ship is not EntityContainerShip containerShip) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(containerShip.DopColor); + Brush brOrange = new SolidBrush(Color.Orange); + + base.DrawTransport(g); + + if (containerShip.Containers) + { + //Границы контейнеров + g.DrawRectangle(pen, _startPosX + 15, _startPosY + 15, 30, 15); + g.DrawRectangle(pen, _startPosX + 55, _startPosY + 15, 30, 15); + //Заливка контейнеров + g.FillRectangle(dopBrush, _startPosX + 16, _startPosY + 16, 29, 14); + g.FillRectangle(dopBrush, _startPosX + 56, _startPosY + 16, 29, 14); + //Заливка центральных полос на контейнерах + g.FillRectangle(brOrange, _startPosX + 16, _startPosY + 20, 29, 5); + g.FillRectangle(brOrange, _startPosX + 56, _startPosY + 20, 29, 5); + } + + if (containerShip.Crane) + { + //Граница стрелы крана + PointF point1 = new PointF(_startPosX + 50, _startPosY + 10); + PointF point2 = new PointF(_startPosX + 90, _startPosY + 13); + PointF point3 = new PointF(_startPosX + 50, _startPosY + 16); + PointF[] craneArrowBorder = new PointF[3] { point1, point2, point3 }; + + //Граница заливки стрелы крана + PointF point4 = new PointF(_startPosX + 51, _startPosY + 10); + PointF point5 = new PointF(_startPosX + 84, _startPosY + 13); + PointF point6 = new PointF(_startPosX + 51, _startPosY + 16); + PointF[] craneArrowFill = new PointF[3] { point4, point5, point6 }; + + g.DrawRectangle(pen, _startPosX + 45, _startPosY, 10, 30); + g.FillRectangle(brOrange, _startPosX + 46, _startPosY + 1, 9, 29); + + g.DrawPolygon(pen, craneArrowBorder); + g.FillPolygon(dopBrush, craneArrowFill); + + //Трос и крепление + g.DrawLine(pen, _startPosX + 90, _startPosY + 14, _startPosX + 90, _startPosY + 40); + g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 85, _startPosY + 43); + g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 90, _startPosY + 45); + g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 95, _startPosY + 43); + } + + + + + } + } +} \ No newline at end of file diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs index f424618..c3e967f 100644 --- a/ContainerShip/ContainerShip/DrawingShip.cs +++ b/ContainerShip/ContainerShip/DrawingShip.cs @@ -8,19 +8,23 @@ namespace ContainerShip { internal class DrawingShip { - public EntityShip Ship { get; private set; } - private float _startPosX; - private float _startPosY; + public EntityShip Ship { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; - protected readonly int _shipWidth = 100; - protected readonly int _shipHeight = 60; - + private readonly int _shipWidth = 100; + private readonly int _shipHeight = 60; public DrawingShip(int speed, float weight, Color bodyColor) { Ship = new EntityShip(speed, weight, bodyColor); - + } + protected DrawingShip(int speed, float weight, Color bodyColor, int shipWidth, + int shipHeight) : this(speed, weight, bodyColor) + { + _shipWidth = shipWidth; + _shipHeight = shipHeight; } public void SetPosition(int x, int y, int width, int height) @@ -77,7 +81,7 @@ namespace ContainerShip } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs new file mode 100644 index 0000000..38f8b88 --- /dev/null +++ b/ContainerShip/ContainerShip/EntityContainerShip.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class EntityContainerShip : EntityShip + { + public Color DopColor { get; private set; } + public bool Crane { get; private set; } + public bool Containers { get; private set; } + + public EntityContainerShip(int speed, float weight, Color bodyColor, Color + dopColor, bool crane, bool containers) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Crane = crane; + Containers = containers; + } + } + +} diff --git a/ContainerShip/ContainerShip/FormShip.Designer.cs b/ContainerShip/ContainerShip/FormShip.Designer.cs index 36ee96d..408ac3a 100644 --- a/ContainerShip/ContainerShip/FormShip.Designer.cs +++ b/ContainerShip/ContainerShip/FormShip.Designer.cs @@ -39,6 +39,7 @@ this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -141,11 +142,22 @@ this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17); this.toolStripStatusBodyColor.Text = "Цвет: "; // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(94, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 23); + this.buttonCreateModif.TabIndex = 10; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormShip // 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.buttonLeft); this.Controls.Add(this.buttonRight); @@ -155,7 +167,6 @@ this.Controls.Add(this.statusStrip); this.Name = "FormShip"; this.Text = "FormShip"; - this.Load += new System.EventHandler(this.FormShip_Load); this.Resize += new System.EventHandler(this.PictureBoxShip_Resize); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); this.statusStrip.ResumeLayout(false); @@ -177,5 +188,6 @@ private ToolStripStatusLabel toolStripStatusSpeed; private ToolStripStatusLabel toolStripStatusWeight; private ToolStripStatusLabel toolStripStatusBodyColor; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs index 2c2735d..bdf915b 100644 --- a/ContainerShip/ContainerShip/FormShip.cs +++ b/ContainerShip/ContainerShip/FormShip.cs @@ -48,26 +48,41 @@ namespace ContainerShip Draw(); } + private void SetData() + { + Random rnd = new(); + toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}"; + toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}"; + toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}"; + _ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height); + } + private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), - rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height); - toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}"; - toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}"; - toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}"; + rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + + Random rnd = new(); + _ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(255, 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(); + } + private void PictureBoxShip_Resize(object sender, EventArgs e) { _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); Draw(); } - private void FormShip_Load(object sender, EventArgs e) - { - - } } } diff --git a/ContainerShip/ContainerShip/FormShip.resx b/ContainerShip/ContainerShip/FormShip.resx index af27dc3..a6be4ca 100644 --- a/ContainerShip/ContainerShip/FormShip.resx +++ b/ContainerShip/ContainerShip/FormShip.resx @@ -61,7 +61,7 @@ iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAIAAADTOW0yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vQAADr0BR/uQrQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt + vAAADrwBlbxySQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt ZOzgiA/+tXEVsP4W3zws6SzewguD+GhWPsa7aMG5LHuF16EiQ1mzDzNxwhJZUMFkkJg4VtMxHyEgi6VG kTJtNoh15pA1ZyqFRSKQOGE8ghXikDtqcJ7yaKQPGRmm1oMOnTxJoRNNIm2MKj/6FMIMJb9Ca7feAeJ/ i+4+Xa8JvgMbdLh+SuR92OPKxTvC7sY2p84eEZMDOx07fEFAJmx2oP2Z0XzYr6XxjaGs2PLL/gPPc2PX