From 3713f5cb1e2b0806237dc4ee95adcfb3afc64a6c Mon Sep 17 00:00:00 2001 From: User Date: Mon, 3 Feb 2025 09:40:33 +0300 Subject: [PATCH] Update --- ProjectMain/ProjectMain/Class1.cs | 78 ++++++- ProjectMain/ProjectMain/DirectionType.cs | 29 +++ ProjectMain/ProjectMain/DrawningBus.cs | 277 +++++++++++++++++++++++ 3 files changed, 378 insertions(+), 6 deletions(-) create mode 100644 ProjectMain/ProjectMain/DirectionType.cs create mode 100644 ProjectMain/ProjectMain/DrawningBus.cs diff --git a/ProjectMain/ProjectMain/Class1.cs b/ProjectMain/ProjectMain/Class1.cs index c725456..17cebc2 100644 --- a/ProjectMain/ProjectMain/Class1.cs +++ b/ProjectMain/ProjectMain/Class1.cs @@ -1,8 +1,74 @@ - -namespace ProjectMain +namespace ProjectBus; +/// +/// - " " +/// +private void ShowPropertiesOfSlateBlue(PaintEventArgs e) { - public class Class1 - { - } - + Color slateBlue = Color.FromName("SlateBlue"); + byte g = slateBlue.G; + byte b = slateBlue.B; + byte r = slateBlue.R; + byte a = slateBlue.A; + string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " + + "red:{1}, green: {2}, blue {3}", new object[] { a, r, g, b }); + e.Graphics.DrawString(text, + new Font(this.Font, FontStyle.Italic), + new SolidBrush(slateBlue), + new RectangleF(new PointF(0.0F, 0.0F), this.Size)); +} +public class EntityBus +{ + /// + /// + /// + 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 BodyKit { get; private set; } +/// +/// () +/// +public bool Wing { get; private set; } + /// + /// () + /// + public bool SportLine { get; private set; } + /// + /// + /// + public double Step => Speed * 100 / Weight; + /// + /// - + /// + /// + /// + /// + /// + /// + /// + /// + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool bodyKit, bool wing, bool sportLine) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } } diff --git a/ProjectMain/ProjectMain/DirectionType.cs b/ProjectMain/ProjectMain/DirectionType.cs new file mode 100644 index 0000000..566bd74 --- /dev/null +++ b/ProjectMain/ProjectMain/DirectionType.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMain; +/// +/// Направление перемещения +/// +public enum DirectionType +{ + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 +} diff --git a/ProjectMain/ProjectMain/DrawningBus.cs b/ProjectMain/ProjectMain/DrawningBus.cs new file mode 100644 index 0000000..25ea7b9 --- /dev/null +++ b/ProjectMain/ProjectMain/DrawningBus.cs @@ -0,0 +1,277 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using ProjectBus; + +namespace ProjectMain; +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningSportCar +{ + /// + /// Класс-сущность + /// + public EntityBus? EntityBus { get; private set; } + /// + /// Ширина окна + /// + private int? _pictureWidth; + /// + /// Высота окна + /// + private int? _pictureHeight; + /// + /// Левая координата прорисовки автомобиля + /// + private int? _startPosX; + /// + /// Верхняя кооридната прорисовки автомобиля + /// + private int? _startPosY; + /// + /// Ширина прорисовки автомобиля + /// + private readonly int _drawningCarWidth = 110; + /// + /// Высота прорисовки автомобиля + /// + private readonly int _drawningCarHeight = 60; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool bodyKit, bool wing, bool sportLine) + { + EntityBus = new EntityBus(); + EntityBus.Init(speed, weight, bodyColor, additionalColor, + bodyKit, wing, sportLine); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах +public bool SetPictureSize(int width, int height) + { + // TODO проверка, что объект "влезает" в размеры поля + // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + _pictureWidth = width; + _pictureHeight = height; + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы + // то надо изменить координаты, чтобы он оставался в этих границах + _startPosX = x; + _startPosY = y; + } + /// + /// Изменение направления перемещения + /// + /// Направление + /// true - перемещене выполнено, false - перемещение невозможно +public bool MoveTransport(DirectionType direction) + { + if (EntityBus == null || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return false; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntityBus.Step > 0) + { + _startPosX -= (int)EntityBus.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntityBus.Step > 0) + { + _startPosY -= (int)EntityBus.Step; + } + return true; + // вправо + case DirectionType.Right: + if (_startPosX.Value - EntityBus.Step > 0) + { + _startPosX += (int)EntityBus.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value - EntityBus.Step > 0) + { + _startPosY += (int)EntityBus.Step; + } + return true; + default: + return false; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityBus == null || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return; + } + Pen pen = new(Color.Black); + Brush additionalBrush = new + SolidBrush(EntityBus.AdditionalColor); + // обвесы + if (EntityBus.BodyKit) + { + g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value, + 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + + 40, 20, 20); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + + 10, 20, 40); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value, + 15, 15); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + + 45, 15, 15); + g.FillEllipse(additionalBrush, _startPosX.Value + 90, + _startPosY.Value, 20, 20); + g.FillEllipse(additionalBrush, _startPosX.Value + 90, + _startPosY.Value + 40, 20, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, + _startPosY.Value + 10, 20, 40); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, + _startPosY.Value + 1, 15, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, + _startPosY.Value + 45, 15, 15); + g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, + 20); + g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, + 20, 20); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, + 20, 40); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value, + 14, 15); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + + 45, 14, 15); + g.FillEllipse(additionalBrush, _startPosX.Value, + _startPosY.Value, 20, 20); + g.FillEllipse(additionalBrush, _startPosX.Value, + _startPosY.Value + 40, 20, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 1, + _startPosY.Value + 10, 25, 40); + g.FillRectangle(additionalBrush, _startPosX.Value + 5, + _startPosY.Value + 1, 15, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 5, + _startPosY.Value + 45, 15, 15); + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, + 39, 15); + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + + 45, 39, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 35, + _startPosY.Value + 1, 40, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 35, + _startPosY.Value + 45, 40, 15); + } + //границы автомобиля + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, + 20); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, + 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, + 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, +20); + g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, + 30); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, + 10, 30); + g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, + 52); + //задние фары + Brush brRed = new SolidBrush(Color.Red); + g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20, + 20); + g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35, + 20, 20); + //передние фары + Brush brYellow = new SolidBrush(Color.Yellow); + g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5, + 20, 20); + g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35, + 20, 20); + //кузов + Brush br = new SolidBrush(EntitySportCar.BodyColor); + g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10, + 30); + g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10, + 30); + g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70, + 50); + //стекла + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10, + 5, 40); + g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10, + 5, 40); + g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8, + 35, 2); + g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51, + 35, 2); + //выделяем рамкой крышу + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10, + 35, 40); + g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15, + 25, 30); + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, + 15, 30); + // спортивная линия + if (EntityBus.SportLine) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 75, + _startPosY.Value + 23, 25, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 35, + _startPosY.Value + 23, 35, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 10, + _startPosY.Value + 23, 20, 15); + } + // крыло + if (EntityBus.Wing) + { + g.FillRectangle(additionalBrush, _startPosX.Value, + _startPosY.Value + 5, 10, 50); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, + 10, 50); + } + } +}