Продвинутый объект
This commit is contained in:
parent
f69a83ecca
commit
86fefa46bf
75
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
75
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,19 +8,23 @@ namespace ContainerShip
|
|||||||
{
|
{
|
||||||
internal class DrawingShip
|
internal class DrawingShip
|
||||||
{
|
{
|
||||||
public EntityShip Ship { get; private set; }
|
public EntityShip Ship { get; protected set; }
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
|
|
||||||
protected readonly int _shipWidth = 100;
|
private readonly int _shipWidth = 100;
|
||||||
protected readonly int _shipHeight = 60;
|
private readonly int _shipHeight = 60;
|
||||||
|
|
||||||
public DrawingShip(int speed, float weight, Color bodyColor)
|
public DrawingShip(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Ship = new EntityShip(speed, weight, 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)
|
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
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
25
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
25
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
ContainerShip/ContainerShip/FormShip.Designer.cs
generated
14
ContainerShip/ContainerShip/FormShip.Designer.cs
generated
@ -39,6 +39,7 @@
|
|||||||
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.toolStripStatusBodyColor = 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();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -141,11 +142,22 @@
|
|||||||
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17);
|
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17);
|
||||||
this.toolStripStatusBodyColor.Text = "Цвет: ";
|
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
|
// FormShip
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
@ -155,7 +167,6 @@
|
|||||||
this.Controls.Add(this.statusStrip);
|
this.Controls.Add(this.statusStrip);
|
||||||
this.Name = "FormShip";
|
this.Name = "FormShip";
|
||||||
this.Text = "FormShip";
|
this.Text = "FormShip";
|
||||||
this.Load += new System.EventHandler(this.FormShip_Load);
|
|
||||||
this.Resize += new System.EventHandler(this.PictureBoxShip_Resize);
|
this.Resize += new System.EventHandler(this.PictureBoxShip_Resize);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
|
||||||
this.statusStrip.ResumeLayout(false);
|
this.statusStrip.ResumeLayout(false);
|
||||||
@ -177,5 +188,6 @@
|
|||||||
private ToolStripStatusLabel toolStripStatusSpeed;
|
private ToolStripStatusLabel toolStripStatusSpeed;
|
||||||
private ToolStripStatusLabel toolStripStatusWeight;
|
private ToolStripStatusLabel toolStripStatusWeight;
|
||||||
private ToolStripStatusLabel toolStripStatusBodyColor;
|
private ToolStripStatusLabel toolStripStatusBodyColor;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,26 +48,41 @@ namespace ContainerShip
|
|||||||
Draw();
|
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)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256),
|
_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)));
|
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);
|
SetData();
|
||||||
toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}";
|
|
||||||
toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}";
|
|
||||||
toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}";
|
|
||||||
Draw();
|
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)
|
private void PictureBoxShip_Resize(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
|
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormShip_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAIAAADTOW0yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAIAAADTOW0yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
vQAADr0BR/uQrQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt
|
vAAADrwBlbxySQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt
|
||||||
ZOzgiA/+tXEVsP4W3zws6SzewguD+GhWPsa7aMG5LHuF16EiQ1mzDzNxwhJZUMFkkJg4VtMxHyEgi6VG
|
ZOzgiA/+tXEVsP4W3zws6SzewguD+GhWPsa7aMG5LHuF16EiQ1mzDzNxwhJZUMFkkJg4VtMxHyEgi6VG
|
||||||
kTJtNoh15pA1ZyqFRSKQOGE8ghXikDtqcJ7yaKQPGRmm1oMOnTxJoRNNIm2MKj/6FMIMJb9Ca7feAeJ/
|
kTJtNoh15pA1ZyqFRSKQOGE8ghXikDtqcJ7yaKQPGRmm1oMOnTxJoRNNIm2MKj/6FMIMJb9Ca7feAeJ/
|
||||||
i+4+Xa8JvgMbdLh+SuR92OPKxTvC7sY2p84eEZMDOx07fEFAJmx2oP2Z0XzYr6XxjaGs2PLL/gPPc2PX
|
i+4+Xa8JvgMbdLh+SuR92OPKxTvC7sY2p84eEZMDOx07fEFAJmx2oP2Z0XzYr6XxjaGs2PLL/gPPc2PX
|
||||||
|
Loading…
Reference in New Issue
Block a user