using ProjectBulldozer.Entities; using ProjectBulldozer.MovementStrategy; namespace ProjectBulldozer.Drawning { public class DrawingTractor { public EntityTractor? EntityTractor { get; protected set; } protected int _pictureWidth; protected int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _tractWidth = 120; protected readonly int _tractHeight = 110; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _tractWidth; public int GetHeight => _tractHeight; public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this); public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth) { if (width < _tractWidth || heigth < _tractHeight) { return; } _pictureWidth = width; _pictureHeight = heigth; EntityTractor = new EntityTractor(speed, weight, bodyColor); } protected DrawingTractor(int speed, double weight, Color bodyColor, int width, int height, int tractWidth, int tractHeight) { if (width < _tractWidth || height < _tractHeight) { return; } _pictureWidth = width; _pictureHeight = height; _tractWidth = tractWidth; _tractHeight = tractHeight; EntityTractor = new EntityTractor(speed, weight, bodyColor); } //Установка позиции public void SetPosition(int x, int y) { if (x < 0 || x + _tractWidth > _pictureWidth) { x = _pictureWidth - _tractWidth; } if (y < 0 || y + _tractHeight > _pictureHeight) { y = _pictureHeight - _tractHeight; } _startPosX = x; _startPosY = y; } public void MoveTransport(DirectionType direction) { if (EntityTractor == null) { return; } switch (direction) { case DirectionType.Left: if (_startPosX - EntityTractor.Step > 0) { _startPosX -= (int)EntityTractor.Step; } break; case DirectionType.Up: if (_startPosY - EntityTractor.Step > 0) { _startPosY -= (int)EntityTractor.Step; } break; case DirectionType.Right: if (_startPosX + EntityTractor.Step + _tractWidth < _pictureWidth) { _startPosX += (int)EntityTractor.Step; } break; case DirectionType.Down: if (_startPosY + EntityTractor.Step + _tractHeight < _pictureHeight) { _startPosY += (int)EntityTractor.Step; } break; } } public virtual void DrawTransport(Graphics g) { { if (EntityTractor == null) return; } Pen pen = new(Color.Black); Brush brownBrush = new SolidBrush(Color.Brown); Brush windows = new SolidBrush(Color.LightYellow); Brush bodyColor = new SolidBrush(EntityTractor.BodyColor); Brush grayBrush = new SolidBrush(Color.Gray); //основное тело g.FillRectangle(bodyColor, _startPosX + 18, _startPosY + 42, 99, 56); g.DrawRectangle(pen, _startPosX + 18, _startPosY + 42, 99, 56); //кабина водителя g.FillRectangle(windows, _startPosX + 18, _startPosY + 4 , 37, 37); g.DrawRectangle(pen, _startPosX + 18, _startPosY +4 , 37, 37); //колеса g.FillEllipse(grayBrush, _startPosX + 19, _startPosY + 76, 45, 45); g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45); g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33); g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33); //выхлопная труба g.FillRectangle(brownBrush, _startPosX + 88, _startPosY+ 6, 14, 35); g.DrawRectangle(pen, _startPosX + 88, _startPosY + 6, 14, 35); } public bool CanMove(DirectionType direction) { if (EntityTractor == null) { return false; } return direction switch { //влево DirectionType.Left => _startPosX - EntityTractor.Step > 0, //вверх DirectionType.Up => _startPosY - EntityTractor.Step > 0, // вправо DirectionType.Right => _startPosX + EntityTractor.Step < _pictureWidth, //вниз DirectionType.Down => _startPosY + EntityTractor.Step < _pictureHeight, }; } } }