From dc49392ffdeeb8dfa98f30f6990af1d66d3f86d5 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 16 Apr 2024 11:19:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B0=D1=81=D1=82=D0=B8=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => Drawing}/DirectionType.cs | 4 +- .../HoistingCrane/Drawing/DrawingCar.cs | 180 ++++++++++++++++++ .../{ => Drawing}/DrawingHoistingCrane.cs | 4 +- .../HoistingCrane/Entities/EntityCrane.cs | 24 +++ .../{ => Entities}/EntityHoistingCrane.cs | 7 +- 5 files changed, 208 insertions(+), 11 deletions(-) rename HoistingCrane/HoistingCrane/{ => Drawing}/DirectionType.cs (85%) create mode 100644 HoistingCrane/HoistingCrane/Drawing/DrawingCar.cs rename HoistingCrane/HoistingCrane/{ => Drawing}/DrawingHoistingCrane.cs (99%) create mode 100644 HoistingCrane/HoistingCrane/Entities/EntityCrane.cs rename HoistingCrane/HoistingCrane/{ => Entities}/EntityHoistingCrane.cs (91%) diff --git a/HoistingCrane/HoistingCrane/DirectionType.cs b/HoistingCrane/HoistingCrane/Drawing/DirectionType.cs similarity index 85% rename from HoistingCrane/HoistingCrane/DirectionType.cs rename to HoistingCrane/HoistingCrane/Drawing/DirectionType.cs index f7b59b9..f515958 100644 --- a/HoistingCrane/HoistingCrane/DirectionType.cs +++ b/HoistingCrane/HoistingCrane/Drawing/DirectionType.cs @@ -1,6 +1,4 @@ - - -namespace HoistingCrane +namespace HoistingCrane.Drawing { public enum DirectionType { diff --git a/HoistingCrane/HoistingCrane/Drawing/DrawingCar.cs b/HoistingCrane/HoistingCrane/Drawing/DrawingCar.cs new file mode 100644 index 0000000..7683b63 --- /dev/null +++ b/HoistingCrane/HoistingCrane/Drawing/DrawingCar.cs @@ -0,0 +1,180 @@ +using HoistingCrane.Entities; + +namespace HoistingCrane.Drawing; + +public class DrawingCar +{ + /// Класс-сущность + public EntityCrane? EntityCrane { get; private set; } + /// Ширина окна + private int? _pictureWidth; + /// Высота окна + private int? _pictureHeight; + /// Левая координата прорисовки автомобиля + private int? _startPosX; + /// Верхняя кооридната прорисовки автомобиля + private int? _startPosY; + /// Ширина прорисовки автомобиля + private readonly int _drawningCraneWidth = 110; + /// Высота прорисовки автомобиля + private readonly int _drawningCraneHeight = 56; + + + /// Инициализация свойств + /// Скорость + /// Вес автомобиля + /// Основной цвет + public void Init(int speed, double weight, Color bodyColor) + { + EntityCrane = new EntityCrane(speed, weight, bodyColor); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + /// Установка границ поля + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + public bool SetPictureSize(int width, int height) + { + // TODO проверка, что объект "влезает" в размеры поля + // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + if (width < _drawningCraneWidth || height < _drawningCraneHeight) + { + return false; + } + + _pictureWidth = width; + _pictureHeight = height; + + if (_startPosX != null || _startPosY != null) + { + if (_startPosX + _drawningCraneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningCraneWidth; + if (_startPosY + _drawningCraneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningCraneHeight; + if (_startPosX < 0) _startPosX = 0; + if (_startPosY < 0) _startPosY = 0; + } + return true; + } + /// Установка позиции + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы + // то надо изменить координаты, чтобы он оставался в этих границах + _startPosX = x; + _startPosY = y; + if (_startPosX + _drawningCraneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningCraneWidth; + if (_startPosY + _drawningCraneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningCraneHeight; + if (_startPosX < 0) _startPosX = 0; + if (_startPosY < 0) _startPosY = 0; + } + /// Изменение направления перемещения + /// Направление + /// true - перемещене выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntityCrane == null || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return false; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntityCrane.Step > 0) + { + _startPosX -= (int)EntityCrane.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntityCrane.Step > 0) + { + _startPosY -= (int)EntityCrane.Step; + } + return true; + // вправо + case DirectionType.Right: + if (_startPosX.Value + EntityCrane.Step < _pictureWidth - _drawningCraneWidth) + { + _startPosX += (int)EntityCrane.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + EntityCrane.Step < _pictureHeight - _drawningCraneHeight) + { + _startPosY += (int)EntityCrane.Step; + } + return true; + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + + public void DrawTransport(Graphics g) + { + if (EntityCrane == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + Pen pen = new(Color.Black); + Brush BodyBrush = new SolidBrush(EntityCrane.BodyColor); + + //Уменьшаем все числа на 8 + //корпус + g.FillRectangle(BodyBrush, _startPosX.Value + 2, _startPosY.Value + 22, 54, 4); + g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 22, 54, 4); + g.FillRectangle(BodyBrush, _startPosX.Value + 14, _startPosY.Value + 8, -4, 7); + g.DrawRectangle(pen, _startPosX.Value + 14, _startPosY.Value + 8, -4, 6); + g.FillRectangle(BodyBrush, _startPosX.Value + 29, _startPosY.Value , -3, 15); + g.DrawRectangle(pen, _startPosX.Value + 29, _startPosY.Value + 0, -3, 14); + + //гусеницы + g.DrawLine(pen, _startPosX.Value , _startPosY.Value + 34, _startPosX.Value + 2, _startPosY.Value + 34); + g.DrawLine(pen, _startPosX.Value - 1, _startPosY.Value + 35, _startPosX.Value - 1, _startPosY.Value + 45); + g.DrawLine(pen, _startPosX.Value , _startPosY.Value + 46, _startPosX.Value + 4, _startPosY.Value + 46); + g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 47, _startPosX.Value + 61, _startPosY.Value + 47); + g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 46, _startPosX.Value + 65, _startPosY.Value + 46); + g.DrawLine(pen, _startPosX.Value + 66, _startPosY.Value + 45, _startPosX.Value + 66, _startPosY.Value + 35); + g.DrawLine(pen, _startPosX.Value + 63, _startPosY.Value + 34, _startPosX.Value + 65, _startPosY.Value + 34); + + //колеса + g.FillEllipse(BodyBrush, _startPosX.Value + 2, _startPosY.Value + 36, 1, 1); + g.DrawEllipse(pen, _startPosX.Value + 2, _startPosY.Value + 36, 1, 1); + g.FillEllipse(BodyBrush, _startPosX.Value + 55, _startPosY.Value + 36, 1, 1); + g.DrawEllipse(pen, _startPosX.Value + 55, _startPosY.Value + 36, 1, 1); + + g.FillEllipse(BodyBrush, _startPosX.Value + 17, _startPosY.Value + 40, -2, -2); + g.DrawEllipse(pen, _startPosX.Value + 17, _startPosY.Value + 40, -2, -2); + g.FillEllipse(BodyBrush, _startPosX.Value + 30, _startPosY.Value + 40, -2, -2); + g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 40, -2, -2); + g.FillEllipse(BodyBrush, _startPosX.Value + 42, _startPosY.Value + 40, -2, -2); + g.DrawEllipse(pen, _startPosX.Value + 42, _startPosY.Value + 40, -2, -2); + + g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 36, -4, -4); + g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 36, -4, -4); + g.FillEllipse(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 46, -4, -4); + g.DrawEllipse(pen, _startPosX.Value + 37, _startPosY.Value + 36, -4, -4); + + //стекло + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX.Value + 44, _startPosY.Value + 6, 13, 8); + g.DrawRectangle(pen, _startPosX.Value + 44, _startPosY.Value + 6, 12, 8); + + } +} diff --git a/HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs b/HoistingCrane/HoistingCrane/Drawing/DrawingHoistingCrane.cs similarity index 99% rename from HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs rename to HoistingCrane/HoistingCrane/Drawing/DrawingHoistingCrane.cs index 373405c..f8b91da 100644 --- a/HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/Drawing/DrawingHoistingCrane.cs @@ -1,6 +1,4 @@ - - -namespace HoistingCrane; +namespace HoistingCrane.Drawing; public class DrawingHoistingCrane { diff --git a/HoistingCrane/HoistingCrane/Entities/EntityCrane.cs b/HoistingCrane/HoistingCrane/Entities/EntityCrane.cs new file mode 100644 index 0000000..073961a --- /dev/null +++ b/HoistingCrane/HoistingCrane/Entities/EntityCrane.cs @@ -0,0 +1,24 @@ +namespace HoistingCrane.Entities; +///Класс-сущность "Автомобиль" + +public class EntityCrane +{ + /// Скорость + public int Speed { get; private set; } + /// Вес + public double Weight { get; private set; } + /// Основной цвет + public Color BodyColor { get; private set; } + /// Шаг перемещения автомобиля + public double Step => Speed * 100 / Weight; + /// Конструктор сущности + /// Скорость + /// Вес автомобиля + /// Основной цвет + public EntityCrane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs similarity index 91% rename from HoistingCrane/HoistingCrane/EntityHoistingCrane.cs rename to HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs index 63845eb..dff8c37 100644 --- a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs @@ -1,6 +1,5 @@ - - -namespace HoistingCrane +namespace HoistingCrane.Entities +///Класс-сущность "Спортивный автомобиль" { public class EntityHoistingCrane { @@ -16,8 +15,6 @@ namespace HoistingCrane public bool Crane { get; private set; } /// Признак (опция) наличия противовеса public bool Counterweight { get; private set; } - /// Шаг перемещения автомобиля - public double Step => Speed * 100 / Weight; /// Инициализация полей объекта-класса спортивного автомобиля /// Скорость