From c853fe4b1ff118583055749ef74a0476878a8f59 Mon Sep 17 00:00:00 2001 From: Aidar Date: Fri, 8 Mar 2024 11:07:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLiner/ProjectLiner/DirectionType.cs | 1 + ProjectLiner/ProjectLiner/DrawningLiner.cs | 24 +++++++++++++++++++--- ProjectLiner/ProjectLiner/EntityLiner.cs | 10 ++++++++- ProjectLiner/ProjectLiner/FormLiner.cs | 7 ++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ProjectLiner/ProjectLiner/DirectionType.cs b/ProjectLiner/ProjectLiner/DirectionType.cs index ae64161..17b4361 100644 --- a/ProjectLiner/ProjectLiner/DirectionType.cs +++ b/ProjectLiner/ProjectLiner/DirectionType.cs @@ -1,4 +1,5 @@ namespace ProjectLiner; + /// /// Направление передвижения /// diff --git a/ProjectLiner/ProjectLiner/DrawningLiner.cs b/ProjectLiner/ProjectLiner/DrawningLiner.cs index c4accb4..3171ad2 100644 --- a/ProjectLiner/ProjectLiner/DrawningLiner.cs +++ b/ProjectLiner/ProjectLiner/DrawningLiner.cs @@ -1,4 +1,5 @@ namespace ProjectLiner; + /// /// Класс-прорисовка сущности "Лайнер" /// @@ -8,30 +9,37 @@ public class DrawningLiner /// Класс-сущность "Лайнер" /// public EntityLiner? EntityLiner { get; private set; } + /// /// Ширина окна /// private int? _pictureWidth; + /// /// Высота окна /// private int? _pictureHeight; + /// /// Левая координата прорисовки сущности "Лайнер" /// private int? _startPosX; + /// /// Верхнаяя координата прорисовки сущности "Лайнер" /// private int? _startPosY; + /// /// Ширина прорисовки сущности "Лайнер" /// private readonly int _drawningLinerWidth = 150; + /// /// Высота сущности "Лайнер" /// private readonly int _drawningLinerHeight = 65; + /// /// Инициализация свойств /// @@ -50,6 +58,7 @@ public class DrawningLiner _startPosX = null; _startPosY = null; } + /// /// Установка границ поля /// @@ -64,8 +73,11 @@ public class DrawningLiner } _pictureWidth = width; _pictureHeight = height; + if (_startPosX.HasValue && _startPosX + _drawningLinerWidth > width) _startPosX = _pictureWidth - _drawningLinerWidth; + if (_startPosY.HasValue && _startPosY + _drawningLinerHeight > height) _startPosY = _pictureHeight - _drawningLinerHeight; return true; } + /// /// Установка позиции /// @@ -117,6 +129,7 @@ public class DrawningLiner _startPosX -= (int)EntityLiner.Step; } return true; + // Вверх case DirectionType.Up: if (_startPosY.Value - EntityLiner.Step > 0) @@ -124,6 +137,7 @@ public class DrawningLiner _startPosY -= (int)EntityLiner.Step; } return true; + // Вправо case DirectionType.Right: @@ -132,6 +146,7 @@ public class DrawningLiner _startPosX += (int)EntityLiner.Step; } return true; + // Вниз case DirectionType.Down: if (_startPosY.Value + _drawningLinerHeight + EntityLiner.Step < _pictureHeight.Value) @@ -143,6 +158,7 @@ public class DrawningLiner return false; } } + /// /// Прорисовка объекта /// @@ -156,6 +172,7 @@ public class DrawningLiner Pen pen = new(Color.Black, 2); Brush br = new SolidBrush(EntityLiner.BodyColor); Brush additionalBrush = new SolidBrush(EntityLiner.AdditionalColor); + // Вторая палуба if (EntityLiner.SecondDeck) { @@ -175,6 +192,7 @@ public class DrawningLiner }); } + // Бассейн if (EntityLiner.Pool) { @@ -183,6 +201,7 @@ public class DrawningLiner g.DrawArc(pen, _startPosX.Value + 135, _startPosY.Value + 20, 8, 8, 180, 180); g.DrawLine(pen, _startPosX.Value + 143, _startPosY.Value + 25, _startPosX.Value + 143, _startPosY.Value + 30); } + // Корпус и палуба Лайнера g.FillPolygon(br, new[] { @@ -198,7 +217,6 @@ public class DrawningLiner new Point(_startPosX.Value + 100, _startPosY.Value + 15), new Point(_startPosX.Value + 105, _startPosY.Value + 30) }); - g.DrawPolygon(pen, new[] { new Point(_startPosX.Value + 0, _startPosY.Value + 30), @@ -213,11 +231,11 @@ public class DrawningLiner new Point(_startPosX.Value + 100, _startPosY.Value + 15), new Point(_startPosX.Value + 105, _startPosY.Value + 30) }); + // Якорь g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 33, _startPosX.Value + 30, _startPosY.Value + 45); g.DrawLine(pen, _startPosX.Value + 27, _startPosY.Value + 36, _startPosX.Value + 33, _startPosY.Value + 36); g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 40, _startPosX.Value + 30, _startPosY.Value + 45); g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 45, _startPosX.Value + 35, _startPosY.Value + 40); } -} - +} \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/EntityLiner.cs b/ProjectLiner/ProjectLiner/EntityLiner.cs index 8cd9294..444ed7b 100644 --- a/ProjectLiner/ProjectLiner/EntityLiner.cs +++ b/ProjectLiner/ProjectLiner/EntityLiner.cs @@ -1,4 +1,5 @@ namespace ProjectLiner; + /// /// Класс-сущность "Лайнер" /// @@ -8,30 +9,37 @@ public class EntityLiner /// Скорость /// public int Speed { get; private set; } + /// /// Вес /// public double Weight { get; private set; } + /// /// Основной цвет /// public Color BodyColor { get; private set; } + /// /// Дополнительный цвет /// public Color AdditionalColor { get; private set; } + /// /// Наличие второй палубы /// public bool SecondDeck { get; private set; } + /// /// Наличие бассейна /// public bool Pool { get; private set; } + /// /// Шаг перемещения сущности "Лайнер" /// public double Step => Speed * 100 / Weight; + /// /// Инициализация полей объекта класса "Лайнер" /// @@ -50,4 +58,4 @@ public class EntityLiner SecondDeck = secondDeck; Pool = pool; } -} +} \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs index e2d10f7..248a90e 100644 --- a/ProjectLiner/ProjectLiner/FormLiner.cs +++ b/ProjectLiner/ProjectLiner/FormLiner.cs @@ -1,4 +1,5 @@ namespace ProjectLiner; + /// /// Форма работы с объектом "Лайнер" /// @@ -8,6 +9,7 @@ public partial class FormLiner : Form /// Поле-объект для прорисовки объекта /// private DrawningLiner? _drawningLiner; + /// /// Конструктор формы /// @@ -15,6 +17,7 @@ public partial class FormLiner : Form { InitializeComponent(); } + /// /// Метод прорисовки Лайнера /// @@ -30,6 +33,7 @@ public partial class FormLiner : Form _drawningLiner.DrawTransport(gr); pictureBoxLiner.Image = bmp; } + /// /// Обработка нажатия кнопки "Создать" /// @@ -48,6 +52,7 @@ public partial class FormLiner : Form Draw(); } + /// /// Обработка нажатия кнопок навигации движения /// @@ -81,4 +86,4 @@ public partial class FormLiner : Form Draw(); } } -} +} \ No newline at end of file