diff --git a/ProjectMonorail/ProjectMonorail.sln b/ProjectMonorail/ProjectMonorail.sln index 85a501b..6ef2aff 100644 --- a/ProjectMonorail/ProjectMonorail.sln +++ b/ProjectMonorail/ProjectMonorail.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.11.35303.130 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectMonorail", "ProjectMonorail\ProjectMonorail.csproj", "{FFFB69FA-2DD3-4887-B6FC-9BA8B6F356A2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectMonorail", "ProjectMonorail\ProjectMonorail.csproj", "{FFFB69FA-2DD3-4887-B6FC-9BA8B6F356A2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ProjectMonorail/ProjectMonorail/DrawningMonorail.cs b/ProjectMonorail/ProjectMonorail/DrawningMonorail.cs index 19f88cf..25d7ea4 100644 --- a/ProjectMonorail/ProjectMonorail/DrawningMonorail.cs +++ b/ProjectMonorail/ProjectMonorail/DrawningMonorail.cs @@ -1,4 +1,6 @@ -namespace ProjectMonorail; +using static System.Windows.Forms.AxHost; + +namespace ProjectMonorail; public class DrawningMonorail { @@ -25,11 +27,20 @@ public class DrawningMonorail /// /// Ширина прорисовки автомобиля /// - private readonly int _drawningWidth = 140; + private readonly int _drawningWidth = 110; /// /// Высота прорисовки автомобиля /// - private readonly int _drawningHeight = 60; + private readonly int _drawningHeight = 56; + /// + /// Минимальный отступ слева + /// + private readonly int minLeftMargin = 0; + /// + /// Минимальный отступ сверху + /// + private readonly int minTopMargin = 0; + /// /// Инициализация свойств /// @@ -48,6 +59,7 @@ public class DrawningMonorail _startPosX = null; _startPosY = null; } + /// /// Установка границ поля /// @@ -56,8 +68,6 @@ public class DrawningMonorail /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - // проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена if (width >= _drawningWidth && height >= _drawningHeight) { _pictureWidth = width; @@ -66,6 +76,7 @@ public class DrawningMonorail } return false; } + /// /// Установка позиции /// @@ -77,8 +88,10 @@ public class DrawningMonorail { return; } - // если при установке объекта в эти координаты, он будет "выходить" за границы формы - // то надо изменить координаты, чтобы он оставался в этих границах + + // Проверка на минимальные отступы + x = Math.Max(x, minLeftMargin); + y = Math.Max(y, minTopMargin); if (x + 140 > _pictureWidth.Value) { @@ -92,6 +105,7 @@ public class DrawningMonorail _startPosX = x; _startPosY = y; } + /// /// Изменение направления перемещения /// @@ -103,31 +117,27 @@ public class DrawningMonorail { return false; } + switch (direction) { - //влево case DirectionType.Left: - if (_startPosX.Value - EntityMonorail.Step > 0) + if (_startPosX.Value - EntityMonorail.Step > minLeftMargin) { _startPosX -= (int)EntityMonorail.Step; } return true; - //вверх case DirectionType.Up: - if (_startPosY.Value - EntityMonorail.Step > 0) + if (_startPosY.Value - EntityMonorail.Step > minTopMargin) { _startPosY -= (int)EntityMonorail.Step; } return true; - // вправо case DirectionType.Right: if (_startPosX.Value + EntityMonorail.Step + _drawningWidth < _pictureWidth) { _startPosX += (int)EntityMonorail.Step; } - return true; - //вниз case DirectionType.Down: if (_startPosY.Value + EntityMonorail.Step + _drawningHeight < _pictureHeight) { @@ -138,6 +148,7 @@ public class DrawningMonorail return false; } } + /// /// Прорисовка объекта /// @@ -149,109 +160,72 @@ public class DrawningMonorail return; } Pen pen = new(Color.Black); - Brush additionalBrush = new - SolidBrush(EntityMonorail.AdditionalColor); + Brush additionalBrush = new SolidBrush(EntityMonorail.AdditionalColor); + Brush BodyBrush = new SolidBrush(EntityMonorail.BodyColor); + Brush CraneBrush = new SolidBrush(Color.Black); - //магнитная рельса - if (EntityMonorail.MagneticRail) - { - g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 48, 130, 5); - } - //вторая кабина + //корпус + g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12); + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12); + g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15); + g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14); + g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 8, 5, 23); + g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 8, 5, 22); - if (EntityMonorail.SecondCabin) - { - Point[] second_cabin = { - new Point(_startPosX.Value + 125, _startPosY.Value), - new Point(_startPosX.Value + 132, _startPosY.Value + 20), - new Point(_startPosX.Value + 132, _startPosY.Value + 40), - new Point(_startPosX.Value + 125, _startPosY.Value + 40), - new Point(_startPosX.Value + 125, _startPosY.Value + 20), - new Point(_startPosX.Value + 132, _startPosY.Value + 20) - }; - g.DrawPolygon(pen, second_cabin); - g.FillPolygon(additionalBrush, second_cabin); - - } - - // Границы - Brush brush = new SolidBrush(EntityMonorail.BodyColor); - g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20, 120, 20); - Point[] p1 = { - new Point(_startPosX.Value + 12, _startPosY.Value), - new Point(_startPosX.Value + 125, _startPosY.Value), - new Point(_startPosX.Value + 125, _startPosY.Value + 20), - new Point(_startPosX.Value + 5, _startPosY.Value + 20) - }; - g.DrawPolygon(pen, p1); - - // Окрас - - g.FillRectangle(brush, _startPosX.Value + 6, _startPosY.Value + 21, 119, 19); - - Point[] p2 = { - new Point(_startPosX.Value + 12, _startPosY.Value + 1), - new Point(_startPosX.Value + 125, _startPosY.Value + 1), - new Point(_startPosX.Value + 125, _startPosY.Value + 20), - new Point(_startPosX.Value + 5, _startPosY.Value + 20) - }; - g.FillPolygon(brush, p2); - - //дверь - Brush brWhite = new SolidBrush(Color.White); - g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 8, 10, 25); - g.FillRectangle(brWhite, _startPosX.Value + 41, _startPosY.Value + 9, 9, 24); - - //окна - Pen pen1 = new(Color.Blue); - g.DrawRectangle(pen1, _startPosX.Value + 13, _startPosY.Value + 4, 10, 11); - g.DrawRectangle(pen1, _startPosX.Value + 27, _startPosY.Value + 4, 10, 11); - g.DrawRectangle(pen1, _startPosX.Value + 110, _startPosY.Value + 4, 10, 11); - - // держатели - - Brush brBlack = new SolidBrush(Color.Black); - - //1 - - Point[] point1 = { - new Point(_startPosX.Value + 7, _startPosY.Value + 40), - new Point(_startPosX.Value + 45, _startPosY.Value + 40), - new Point(_startPosX.Value + 38, _startPosY.Value + 46), - new Point(_startPosX.Value, _startPosY.Value + 46) - }; - g.DrawPolygon(pen, point1); - g.FillPolygon(brBlack, point1); - - //2 - - Point[] point3 = { - new Point(_startPosX.Value + 123, _startPosY.Value + 40), - new Point(_startPosX.Value + 130, _startPosY.Value + 46), - new Point(_startPosX.Value + 92, _startPosY.Value + 46), - new Point(_startPosX.Value + 85, _startPosY.Value + 40) - }; - g.DrawPolygon(pen, point3); - g.FillPolygon(brBlack, point3); + //стекло + g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16); + g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16); + //гусеницы + g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42); + g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53); + g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54); + g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55); + g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54); + g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43); + g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42); //колеса + g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9); + g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9); + g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9); - //1-ое колеса - g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + 40, 11, 11); - g.FillEllipse(brWhite, _startPosX.Value + 13, _startPosY.Value + 40, 11, 11); + g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6); + g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6); + g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6); + g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6); + g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6); + g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6); - //2-ое колесо - g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 40, 11, 11); - g.FillEllipse(brWhite, _startPosX.Value + 35, _startPosY.Value + 40, 11, 11); + g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4); + g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4); + g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4); + g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4); - //3-ее колесо - g.DrawEllipse(pen, _startPosX.Value + 85, _startPosY.Value + 40, 11, 11); - g.FillEllipse(brWhite, _startPosX.Value + 85, _startPosY.Value + 40, 11, 11); + //кран + if (EntityMonorail.Crane) + { + //балка + g.FillRectangle(BodyBrush, _startPosX.Value, _startPosY.Value, 110, 9); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 109, 8); - //4-ое колесо - g.DrawEllipse(pen, _startPosX.Value + 107, _startPosY.Value + 40, 11, 11); - g.FillEllipse(brWhite, _startPosX.Value + 107, _startPosY.Value + 40, 11, 11); + //крюк + g.FillRectangle(CraneBrush, _startPosX.Value + 107, _startPosY.Value + 8, 3, 13); + g.FillRectangle(CraneBrush, _startPosX.Value + 102, _startPosY.Value + 18, 8, 3); + g.FillRectangle(CraneBrush, _startPosX.Value + 102, _startPosY.Value + 16, 3, 5); + } + + //противовес + if (EntityMonorail.Сounterweight) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value, 10, 9); + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 9, 8); + + g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 2, _startPosX.Value + 44, _startPosY.Value + 2); + g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 4, _startPosX.Value + 44, _startPosY.Value + 4); + g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 6, _startPosX.Value + 44, _startPosY.Value + 6); + } } -} +} \ No newline at end of file diff --git a/ProjectMonorail/ProjectMonorail/EntityMonorail.cs b/ProjectMonorail/ProjectMonorail/EntityMonorail.cs index 5a5cfcc..4686dce 100644 --- a/ProjectMonorail/ProjectMonorail/EntityMonorail.cs +++ b/ProjectMonorail/ProjectMonorail/EntityMonorail.cs @@ -1,4 +1,11 @@ -namespace ProjectMonorail; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMonorail; + public class EntityMonorail { /// @@ -18,15 +25,15 @@ public class EntityMonorail /// public Color AdditionalColor { get; private set; } /// - /// Признак (опция) наличия обвеса + /// Признак (опция) наличия противовеса /// - public bool MagneticRail { get; private set; } + public bool Сounterweight { get; private set; } /// - /// /// Признак (опция) наличия антикрыла - /// /// - public bool SecondCabin { get; private set; } + /// Признак (опция) наличия крана + /// + public bool Crane { get; private set; } /// - /// Признак (опция) наличия гоночной полосы + /// Шаг перемещения автомобиля /// public double Step => Speed * 100 / Weight; /// @@ -36,17 +43,15 @@ public class EntityMonorail /// Вес автомобиля /// Основной цвет /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool magneticRail, bool secondCabin) + /// Признак наличия обвеса + /// Признак наличия крана + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool crane) { Speed = speed; Weight = weight; BodyColor = bodyColor; AdditionalColor = additionalColor; - MagneticRail = magneticRail; - SecondCabin = secondCabin; + Сounterweight = counterweight; + Crane = crane; } - } diff --git a/ProjectMonorail/ProjectMonorail/Properties/Resources.Designer.cs b/ProjectMonorail/ProjectMonorail/Properties/Resources.Designer.cs index 0e4ba07..c77aa93 100644 --- a/ProjectMonorail/ProjectMonorail/Properties/Resources.Designer.cs +++ b/ProjectMonorail/ProjectMonorail/Properties/Resources.Designer.cs @@ -10,9 +10,8 @@ namespace ProjectMonorail.Properties { using System; - using System.Drawing; - - + + /// /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. /// @@ -24,10 +23,7 @@ namespace ProjectMonorail.Properties { [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { - internal static Image free_icon_right; - internal static Image free_icon_left; - internal static Image free_icon_up; - internal static Image free_icon_down; + private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture;