using System.Reflection.Metadata.Ecma335; namespace ProjectCar; /// /// /// public class DrawningGasMachine { /// /// Класс-сущность /// public EntityMachine? EntityMachine { get; private set; } /// /// Ширина окна /// private int? _pictureWidth; /// /// Высота окна /// private int? _pictureHeight; /// /// Левая координата прорисовки газ автомобиля /// private int? _startPosX; /// /// Верхняя координата прорисовки газ автомобиля /// private int? _startPosY; /// /// Ширина прорисовки газ автомобиля /// private readonly int _drawningMachineWidth = 150; /// /// Высота прорисовки газ автомобиля /// private readonly int _drawningMachineHeight = 70; public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gas, bool wheels1, bool wheels2, bool wheels3, bool beacon) { EntityMachine = new EntityMachine(); EntityMachine.Init(speed, weight, bodyColor, additionalColor, gas, wheels1, wheels2, wheels3, beacon); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } /// /// Установка границ поля /// /// Ширина поля /// Высота поля /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих границах public bool SetPictureSize(int width, int height) { if (EntityMachine == null) { return false; } if (width >= _drawningMachineWidth && height >= _drawningMachineHeight) { _pictureWidth = width; _pictureHeight = height; if (_startPosX.HasValue && _startPosY.HasValue) { if (_startPosX + _drawningMachineWidth > _pictureWidth) { _startPosX = _pictureWidth - _drawningMachineWidth; } if (_startPosY + _drawningMachineHeight > _pictureHeight) { _startPosY = _pictureHeight - _drawningMachineHeight; } } return true; } return false; } /// /// Установка позиции /// /// Координата X /// Координата Y public void SetPosition(int x, int y) { if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } if (x < 0) { _startPosX = 0; } else if (x + _drawningMachineWidth > _pictureWidth) { _startPosX = _pictureWidth.Value - _drawningMachineWidth; } if (y < 0) { _startPosY = 0; } else if (y + _drawningMachineHeight > _pictureHeight) { _startPosY = _pictureHeight.Value - _drawningMachineHeight; } _startPosX = x; _startPosY = y; } public bool MoveTransport(DirectionType direction) { if (EntityMachine == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } switch (direction) { case DirectionType.Left: if (_startPosX.Value - EntityMachine.Step > 0) { _startPosX -= (int)EntityMachine.Step; } return true; case DirectionType.Up: if (_startPosY.Value - EntityMachine.Step > 0) { _startPosY -= (int)EntityMachine.Step; } return true; case DirectionType.Right: if (_startPosX.Value + EntityMachine.Step < _pictureWidth - _drawningMachineWidth) { _startPosX += (int)EntityMachine.Step; } return true; case DirectionType.Down: if (_startPosY.Value + EntityMachine.Step < _pictureHeight - _drawningMachineHeight) { _startPosY += (int)EntityMachine.Step; } return true; default: return false; } } /// /// Прорисовка объекта /// /// public void DrawTransport(Graphics g) { if (EntityMachine == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityMachine.AdditionalColor); //бак с газом if (EntityMachine.Gas) { g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 10, 80, 30); g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 10, 80, 30); } //границы автомобиля g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 40, 110, 10); g.DrawRectangle(pen, _startPosX.Value + 116, _startPosY.Value + 10, 30, 30); //кузов Brush br = new SolidBrush(EntityMachine.BodyColor); g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 40, 110, 10); //кабина g.FillRectangle(br, _startPosX.Value + 116, _startPosY.Value + 10, 30, 30); //маяк сигнальный if (EntityMachine.Beacon) { g.DrawRectangle(pen, _startPosX.Value + 130, _startPosY.Value, 10, 10); g.FillRectangle(additionalBrush, _startPosX.Value + 130, _startPosY.Value, 10, 10); } //колеса(2) //if (EntityMachine.Wheels1) //{ // g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 50, 20, 20); // g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 50, 20, 20); // g.DrawEllipse(pen, _startPosX.Value + 125, _startPosY.Value + 50, 20, 20); // g.FillEllipse(additionalBrush, _startPosX.Value + 125, _startPosY.Value + 50, 20, 20); //} //колеса(3) if (EntityMachine.Wheels2) { g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 50, 20, 20); g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 50, 20, 20); g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 50, 20, 20); g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 50, 20, 20); g.DrawEllipse(pen, _startPosX.Value + 125, _startPosY.Value + 50, 20, 20); g.FillEllipse(additionalBrush, _startPosX.Value + 125, _startPosY.Value + 50, 20, 20); } //колеса(4) //if (EntityMachine.Wheels3) //{ // g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 50, 20, 20); // g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 50, 20, 20); // g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 50, 20, 20); // g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 50, 20, 20); // g.DrawEllipse(pen, _startPosX.Value + 125, _startPosY.Value + 50, 20, 20); // g.FillEllipse(additionalBrush, _startPosX.Value + 125, _startPosY.Value + 50, 20, 20); // g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 50, 20, 20); // g.FillEllipse(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 50, 20, 20); //} } }