From 7d8ee126e29571bf17a1a12edb510fc329d550b7 Mon Sep 17 00:00:00 2001 From: x1337-man Date: Mon, 10 Feb 2025 14:21:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D0=BF=D1=80=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingGasolineTanker.cs | 201 ++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs new file mode 100644 index 0000000..583da3f --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs @@ -0,0 +1,201 @@ +namespace ProjectGasolineTanker; + +public class DrawingGasolineTanker +{ + /// + /// Класс-сущность + /// + public EntityGasolineTanker? EntityGasolineTanker { get; private set; } + + /// + /// Ширина окна + /// + private int? _pictureWidth; + + /// + /// Высота окна + /// + private int? _pictureHeight; + + /// + /// Левая координата прорисовки бензовоза + /// + private int? _posX; + + /// + /// Верхняя кооридната прорисовки бензовоза + /// + private int? _posY; + + /// + /// Ширина прорисовки бензовоза + /// + private readonly int _drawingWidth = 90; + + /// + /// Высота прорисовки бензовоза + /// + private readonly int _drawingHeight = 63; + + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Бак + /// Сигнальный маяк + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool signalBeacon) + { + EntityGasolineTanker = new EntityGasolineTanker(); + EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, tank, signalBeacon); + _pictureWidth = null; + _pictureHeight = null; + _posX = null; + _posY = null; + } + + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + public bool SetPictureSize(int width, int height) + { + if (width > _drawingWidth && height > _drawingHeight) + { + _pictureWidth = width; + _pictureHeight = height; + if (_posX != null && _posY != null) + { + if (_posX.Value < 0) _posX = 0; + if (_posY.Value < 0) _posY = 0; + if (_posX.Value + _drawingWidth > _pictureWidth) + { + _posX = _pictureWidth - _drawingWidth; + } + if (_posY.Value + _drawingHeight > _pictureHeight) + { + _posY = _pictureHeight - _drawingHeight; + } + } + return true; + } + return false; + } + + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + _posX = x; + _posY = y; + + if (_pictureHeight.Value < (_posY + _drawingHeight)) + { + _posY = _pictureHeight - _drawingHeight; + } + if (_pictureWidth.Value < (_posX = _drawingWidth)) + { + _posX = _pictureWidth - _drawingWidth; + } + } + + /// + /// Изменение направления перемещения + /// + /// Направление + /// true - перемещене выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntityGasolineTanker == null || !_posX.HasValue || !_posY.HasValue) + { + return false; + } + + switch (direction) + { + case DirectionType.Left: + if (_posX.Value - EntityGasolineTanker.Step > 0) + { + _posX -= EntityGasolineTanker.Step; + } + return true; + + case DirectionType.Up: + if (_posY.Value - EntityGasolineTanker.Step > 0) + { + _posY -= EntityGasolineTanker.Step; + } + return true; + + case DirectionType.Right: + if (_posX.Value + _drawingWidth + EntityGasolineTanker.Step < _pictureWidth) + { + _posX += EntityGasolineTanker.Step; + } + return true; + + case DirectionType.Down: + if (_posY + EntityGasolineTanker.Step + _drawingHeight < _pictureHeight) + { + _posY += EntityGasolineTanker.Step; + } + return true; + + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityGasolineTanker == null || !_posX.HasValue || !_posY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityGasolineTanker.AdditionalColor); + + // Кузов + Brush br = new SolidBrush(EntityGasolineTanker.BodyColor); + g.FillRectangle(br, _posX.Value + 0, _posY.Value + 35, 90, 7); + g.FillRectangle(br, _posX.Value + 67, _posY.Value + 5, 22, 28); + + // Колеса + Brush brBlack = new SolidBrush(Color.Black); + g.FillEllipse(brBlack, _posX.Value + 0, _posY.Value + 40, 23, 23); + g.FillEllipse(brBlack, _posX.Value + 23, _posY.Value + 40, 23, 23); + g.FillEllipse(brBlack, _posX.Value + 67, _posY.Value + 40, 23, 23); + + // Бак + if (EntityGasolineTanker.Tank) + { + g.DrawEllipse(pen, _posX.Value + 0, _posY.Value + 5, 64, 30); + g.FillEllipse(additionalBrush, _posX.Value + 0, _posY.Value + 5, 64, 30); + } + + // Сигнальный маяк + if (EntityGasolineTanker.SignalBeacon) + { + g.FillRectangle(additionalBrush, _posX.Value + 79, _posY.Value + 0, 5, 5); + g.DrawEllipse(pen, _posX.Value + 79, _posY.Value + 0, 5, 10); + g.FillEllipse(additionalBrush, _posX.Value + 79, _posY.Value + 0, 5, 10); + } + } +}