using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Bulldozer; using ProjectBulldozer.Entities; using ProjectBulldozer.Properties; namespace ProjectBulldozer.Drawings { public class DrawingTractor { public EntityTractor? EntityTractor { get; protected set; } protected int _pictureWidth; protected int _pictureHeight; protected int _startPosX; protected int _startPosY; private int tractWidth; protected readonly int _tractWidth = 140; protected readonly int _tractHeight = 123; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _tractWidth; public int GetHeight => _tractHeight; 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 + 20, _startPosY + 40, 100, 60); g.DrawRectangle(pen, _startPosX + 20, _startPosY + 40, 100, 60); //кабина водителя g.FillRectangle(windows, _startPosX + 20, _startPosY, 40, 40); g.DrawRectangle(pen, _startPosX + 20, _startPosY, 40, 40); //колеса g.FillEllipse(grayBrush, _startPosX + 20, _startPosY + 74, 47, 47); g.DrawEllipse(pen, _startPosX + 20, _startPosY + 74, 47, 47); g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 85, 35, 35); g.DrawEllipse(pen, _startPosX + 80, _startPosY + 85, 35, 35); //выхлопная труба g.FillRectangle(brownBrush, _startPosX + 90, _startPosY, 15, 40); g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 40); } 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, }; } } }