using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DoubleDeckerBus { internal class DrawingBus { public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; } private int _pictureWidth; private int _pictureHeight; private int _startPosX; private int _startPosY; private readonly int _busWidth = 180; private readonly int _busHeight = 120; public bool Init(EntityDoubleDeckerBus bus, int width, int height) { _pictureWidth = width; _pictureHeight = height; EntityDoubleDeckerBus = bus; if (_pictureWidth < _busWidth || _pictureHeight < _busHeight) { return false; } return true; } public void SetPosition(int x, int y) { _startPosX = x; _startPosY = y; if (_startPosX + _busWidth > _pictureWidth) { _startPosX = _pictureWidth - _busWidth; } if (_startPosX < 0) { _startPosX = 0; } if (_startPosY + _busHeight > _pictureHeight) { _startPosY = _pictureHeight - _busHeight; } if (_startPosY < 0) { _startPosY = 0; } } public void MoveTransport(Direction direction) { if (EntityDoubleDeckerBus == null) { return; } switch (direction) { case Direction.Left: if (_startPosX - EntityDoubleDeckerBus.Step > 0) { _startPosX -= (int)EntityDoubleDeckerBus.Step; } break; case Direction.Up: if (_startPosY - EntityDoubleDeckerBus.Step > 0) { _startPosY -= (int)EntityDoubleDeckerBus.Step; } break; case Direction.Right: if (_startPosX + EntityDoubleDeckerBus.Step + _busWidth < _pictureWidth) { _startPosX += (int)EntityDoubleDeckerBus.Step; } break; case Direction.Down: if (_startPosY + EntityDoubleDeckerBus.Step + _busHeight < _pictureHeight) { _startPosY += (int)EntityDoubleDeckerBus.Step; } break; } } public void DrawTransport(Graphics g) { if (EntityDoubleDeckerBus == null) { return; } Pen pen = new(Color.Black); Brush bodyColor = new SolidBrush(EntityDoubleDeckerBus.BodyColor); g.FillRectangle(bodyColor, _startPosX + 147, _startPosY + 52, 21, 20); g.FillRectangle(bodyColor, _startPosX + 147, _startPosY + 71, 30, 27); g.FillRectangle(bodyColor, _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); //ВТОРОЙ ЭТАЖ if (EntityDoubleDeckerBus.SecondFloor) { Brush additionalColor = new SolidBrush(EntityDoubleDeckerBus.AdditionalColor); g.FillRectangle(additionalColor, _startPosX + 7, _startPosY + 12, 172, 40); g.DrawLine(pen, _startPosX + 7, _startPosY + 36, _startPosX + 178, _startPosY + 36); g.FillRectangle(brBlue, _startPosX + 15, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 15, 15, 15); } //ЛЕСТНИЦА if (EntityDoubleDeckerBus.Stairs) { g.DrawLine(pen, _startPosX + 10, _startPosY + 55, _startPosX + 34, _startPosY + 55); g.DrawLine(pen, _startPosX + 10, _startPosY + 58, _startPosX + 34, _startPosY + 58); g.DrawLine(pen, _startPosX + 10, _startPosY + 64, _startPosX + 34, _startPosY + 64); g.DrawLine(pen, _startPosX + 10, _startPosY + 72, _startPosX + 34, _startPosY + 72); g.DrawLine(pen, _startPosX + 10, _startPosY + 80, _startPosX + 34, _startPosY + 80); g.DrawLine(pen, _startPosX + 10, _startPosY + 88, _startPosX + 34, _startPosY + 88); g.DrawLine(pen, _startPosX + 10, _startPosY + 94, _startPosX + 34, _startPosY + 94); } // колёса Brush gr = new SolidBrush(Color.Gray); g.FillEllipse(bodyColor, _startPosX + 23, _startPosY + 88, 25, 25); g.FillEllipse(bodyColor, _startPosX + 123, _startPosY + 88, 25, 25); g.FillEllipse(gr, _startPosX + 25, _startPosY + 90, 21, 21); g.FillEllipse(gr, _startPosX + 125, _startPosY + 90, 21, 21); } } }