using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DoubleDeckerbus.Entities; using DoubleDeckerbus.Move_Strategy; namespace DoubleDeckerbus.Drawing { public class DrawingBus { public IMoveableObject GetMoveableObject => new DrawingObjectBus(this); public EntityBus? EntityBus { get; protected set; } public int _pictureWidth; public int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _busWidth = 175; protected readonly int _busHeight = 115; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _busWidth; public int GetHeight => _busHeight; public DrawingBus(int speed, double weight, Color bodyColor, int width, int height) { if (width < _busWidth || height < _busHeight) { return; } _pictureWidth = width; _pictureHeight = height; EntityBus = new EntityBus(speed, weight, bodyColor); } protected DrawingBus(int speed, double weight, Color bodyColor, int width, int height, int busWidth, int busHeight) { if (width < _busWidth || height < _busHeight) { return; } _pictureWidth = width; _pictureHeight = height; _busWidth = busWidth; _busHeight = busHeight; EntityBus = new EntityBus(speed, weight, bodyColor); } public void SetPosition(int x, int y) { if (x > _pictureWidth || y > _pictureHeight) { return; } _startPosX = x; _startPosY = y; } public void MoveTransport(DirectionType direction) { if (!CanMove(direction) || EntityBus == null) { return; } switch (direction) { case DirectionType.Left: if (_startPosX - EntityBus.Step > 0) { _startPosX -= (int)EntityBus.Step; } break; case DirectionType.Up: if (_startPosY - EntityBus.Step > 0) { _startPosY -= (int)EntityBus.Step; } break; case DirectionType.Right: if (_startPosX + _busWidth + EntityBus.Step < _pictureWidth) { _startPosX += (int)EntityBus.Step; } break; case DirectionType.Down: if (_startPosY + _busHeight + EntityBus.Step < _pictureHeight) { _startPosY += (int)EntityBus.Step; } break; } } public virtual void DrawTransport(Graphics g) { Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityBus.BodyColor); g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 52, 21, 20); g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 71, 30, 27); g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 52, 137, 46); Brush brBlue = new SolidBrush(Color.LightBlue); g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 55, 15, 15); g.DrawLine(pen, _startPosX + 30, _startPosY + 52, _startPosX + 30, _startPosY + 98); g.DrawLine(pen, _startPosX + 35, _startPosY + 52, _startPosX + 35, _startPosY + 98); Brush gr = new SolidBrush(Color.Gray); g.FillEllipse(additionalBrush, _startPosX + 23, _startPosY + 88, 25, 25); g.FillEllipse(additionalBrush, _startPosX + 123, _startPosY + 88, 25, 25); g.FillEllipse(gr, _startPosX + 25, _startPosY + 90, 21, 21); g.FillEllipse(gr, _startPosX + 125, _startPosY + 90, 21, 21); } public bool CanMove(DirectionType direction) { if (EntityBus == null) { return false; } return direction switch { DirectionType.Left => _startPosX - EntityBus.Step > 0, DirectionType.Up => _startPosY - EntityBus.Step > 0, DirectionType.Right => _startPosX + _busWidth + EntityBus.Step < _pictureWidth, DirectionType.Down => _startPosY + _busHeight + EntityBus.Step < _pictureHeight, _ => false, }; } public void ChangeBordersPicture(int width, int height) { _pictureWidth = width; _pictureHeight = height; } } }