using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DumpTruck { public class DrawingDumpTruck { /// /// Класс-сущность /// public EntityDumpTruck? EntityDumpTruck { get; private set; } /// /// Ширина окна /// private int _pictureWidth; /// /// Высота окна /// private int _pictureHeight; /// /// Левая координата прорисовки самосвала /// private int _startPosX; /// /// Верхняя кооридната прорисовки самосвала /// private int _startPosY; /// /// Ширина прорисовки самосвала /// private readonly int _truckWidth = 160; /// /// Высота прорисовки самосвала /// private readonly int _truckHeight = 90; /// /// Инициализация свойств /// /// Скорость /// Вес /// Основной цвет самосвала /// Признак наличия тента /// Признак наличия кузова /// Цвет кузова /// Цвет тента /// Ширина картинки /// Высота картинки /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах public bool Init(int speed, double weight, Color bodyColor, bool tent, bool dumpBox, Color tentColor, Color dumpBoxColor, int width, int height) { _pictureWidth = width; _pictureHeight = height; if (_pictureHeight < _truckHeight || _pictureWidth < _truckWidth) return false; EntityDumpTruck = new EntityDumpTruck(); EntityDumpTruck.Init(speed, weight, bodyColor, tent, dumpBox, tentColor, dumpBoxColor); return true; } /// /// Установка позиции /// /// Координата X /// Координата Y public void SetPosition(int x, int y) { if (x < 0 || x + _truckWidth > _pictureWidth) { x = 0; } if (y < 0 || y + _truckHeight > _pictureHeight) { y = 0; } _startPosX = x; _startPosY = y; } /// /// Изменение направления перемещения /// /// Направление public void MoveTransport(Direction direction) { if (EntityDumpTruck == null) { return; } switch (direction) { //влево case Direction.Left: if (_startPosX - EntityDumpTruck.Step > 0) { _startPosX -= (int)EntityDumpTruck.Step; } break; //вверх case Direction.Up: if (_startPosY - EntityDumpTruck.Step > 0) { _startPosY -= (int)EntityDumpTruck.Step; } break; // вправо case Direction.Right: if (_startPosX + _truckWidth + EntityDumpTruck.Step < _pictureWidth) { _startPosX += (int)EntityDumpTruck.Step; } break; //вниз case Direction.Down: if (_startPosY + _truckHeight + EntityDumpTruck.Step < _pictureHeight) { _startPosY += (int)EntityDumpTruck.Step; } break; } } /// /// Прорисовка объекта /// /// public void DrawTransport(Graphics g) { if (EntityDumpTruck == null) { return; } Brush brush = new SolidBrush(EntityDumpTruck.BodyColor); g.FillRectangle(brush, _startPosX, _startPosY + 40, 160, 10); g.FillRectangle(brush, _startPosX + 120, _startPosY, 40, 40); g.FillEllipse(brush, _startPosX, _startPosY + 50, 40, 40); g.FillEllipse(brush, _startPosX + 40, _startPosY + 50, 40, 40); g.FillEllipse(brush, _startPosX + 120, _startPosY + 50, 40, 40); if (EntityDumpTruck.DumpBox) { Brush brDumpBox = new SolidBrush(EntityDumpTruck.DumpBoxColor); Point point1 = new Point(_startPosX + 20, _startPosY); Point point2 = new Point(_startPosX + 120, _startPosY); Point point3 = new Point(_startPosX + 100, _startPosY + 39); Point point4 = new Point(_startPosX, _startPosY + 39); Point[] dumpBoxPoints = { point1, point2, point3, point4}; g.FillPolygon(brDumpBox, dumpBoxPoints); } if (EntityDumpTruck.DumpBox && EntityDumpTruck.Tent) { Brush brTent = new SolidBrush(EntityDumpTruck.TentColor); Point point1 = new Point(_startPosX + 15, _startPosY); Point point2 = new Point(_startPosX + 120, _startPosY); Point point3 = new Point(_startPosX + 115, _startPosY + 10); Point point4 = new Point(_startPosX + 10, _startPosY + 10); Point[] tentPoints = { point1, point2, point3, point4 }; g.FillPolygon(brTent, tentPoints); } } } }