using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ContainerShip { public class DrawingContainerShip { public EntityContainerShip? EntityContainerShip { get; private set;} private int _pictureWidth; private int _pictureHeight; private int _startPosX; private int _startPosY; private readonly int _shipWidth = 140; private readonly int _shipHeight = 90; public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool load, bool crane, int width, int height) { _pictureWidth = width; _pictureHeight = height; if ((_pictureWidth < _shipWidth) || (_pictureHeight < _shipHeight)) { return false; } EntityContainerShip = new EntityContainerShip(); EntityContainerShip.Init(speed, weight, bodyColor, additionalColor, load, crane); return true; } public void SetPosition (int x, int y) { _startPosX = x; _startPosY = y; if (_startPosX + _shipWidth > _pictureWidth) { _startPosX = _pictureWidth - _shipWidth; } if (_startPosX < 0) { _startPosX = 0; } if (_startPosY + _shipHeight > _pictureHeight) { _startPosY = _pictureHeight - _shipHeight; } if (_startPosY < 0) { _startPosY = 0; } } public void MoveTransport (DirectionType direction) { if (EntityContainerShip == null) return; switch (direction) { case DirectionType.Left: if (_startPosX - EntityContainerShip.Step > 0) { _startPosX-= (int)EntityContainerShip.Step; } break; case DirectionType.Up: if (_startPosY - EntityContainerShip.Step > 0) { _startPosY -= (int)EntityContainerShip.Step; } break; case DirectionType.Right: if (_startPosX + EntityContainerShip.Step + _shipWidth < _pictureWidth) { _startPosX += (int)EntityContainerShip.Step; } break; case DirectionType.Down: if (_startPosY + EntityContainerShip.Step + _shipHeight < _pictureHeight) { _startPosY += (int)EntityContainerShip.Step; } break; } } public void DrawTransport (Graphics g) { if (EntityContainerShip == null) { return; } Pen pen = new(Color.Black); Brush bodyBrush = new SolidBrush(EntityContainerShip.BodyColor); Point point1 = new Point(_startPosX, _startPosY + 52); Point point2 = new Point(_startPosX + 137, _startPosY + 52); Point point3 = new Point(_startPosX + 137 - 20, _startPosY + 52 + 46 - 10); Point point4 = new Point(_startPosX + 20, _startPosY + 52 + 46 - 10); Point[] p = { point1, point2, point3, point4 }; g.FillPolygon(bodyBrush, p); //корпус Brush additionalBrush = new SolidBrush(EntityContainerShip.AdditionalColor); g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 32, 80, 20); //прямоугольник //груз if (EntityContainerShip.Load) { g.FillRectangle(additionalBrush, _startPosX + 100, _startPosY + 32, 30, 20); //большой прямоугольник } // кран if (EntityContainerShip.Crane) { g.DrawLine(pen, _startPosX + 90, _startPosY + 32, _startPosX + 120, _startPosY); g.DrawLine(pen, _startPosX + 80, _startPosY + 32, _startPosX + 120, _startPosY); g.DrawLine(pen, _startPosX + 120, _startPosY, _startPosX + 120, _startPosY + 30); } } } }