From 976bf76ff8ab8daedf5944e058d50fa3f301d6b4 Mon Sep 17 00:00:00 2001 From: LESN1K Date: Sat, 9 Mar 2024 20:03:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectSportCar/FormMonorail.Designer.cs | 53 ++++--- ProjectSportCar/FormMonorail.cs | 87 ++++++---- .../{ => Monorail/Drawnings}/DirectionType.cs | 2 +- .../Drawnings/DrawingModernMonorail.cs | 137 ++++++++++++++++ .../DrawingMonorail.cs} | 150 +++++------------- .../EntityModernMonorail.cs} | 32 +--- .../Monorail/Entities/EntityMonorail.cs | 41 +++++ 7 files changed, 317 insertions(+), 185 deletions(-) rename ProjectSportCar/Scripts/{ => Monorail/Drawnings}/DirectionType.cs (89%) create mode 100644 ProjectSportCar/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs rename ProjectSportCar/Scripts/Monorail/{DrawMonorail.cs => Drawnings/DrawingMonorail.cs} (57%) rename ProjectSportCar/Scripts/Monorail/{EntityMonorail.cs => Entities/EntityModernMonorail.cs} (62%) create mode 100644 ProjectSportCar/Scripts/Monorail/Entities/EntityMonorail.cs diff --git a/ProjectSportCar/FormMonorail.Designer.cs b/ProjectSportCar/FormMonorail.Designer.cs index 3a375e4..61d6b4e 100644 --- a/ProjectSportCar/FormMonorail.Designer.cs +++ b/ProjectSportCar/FormMonorail.Designer.cs @@ -33,6 +33,7 @@ buttonMove_Left = new Button(); buttonMove_Up = new Button(); pictureBoxMonorail = new PictureBox(); + buttonCreateModernMonorail = new Button(); buttonCreateMonorail = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit(); SuspendLayout(); @@ -42,10 +43,9 @@ buttonMove_Right.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMove_Right.BackgroundImage = Properties.Resources.ArrowRight; buttonMove_Right.BackgroundImageLayout = ImageLayout.Stretch; - buttonMove_Right.Location = new Point(875, 569); - buttonMove_Right.Margin = new Padding(3, 4, 3, 4); + buttonMove_Right.Location = new Point(766, 427); buttonMove_Right.Name = "buttonMove_Right"; - buttonMove_Right.Size = new Size(40, 47); + buttonMove_Right.Size = new Size(35, 35); buttonMove_Right.TabIndex = 0; buttonMove_Right.UseVisualStyleBackColor = true; buttonMove_Right.Click += ButtonMove_Click; @@ -55,10 +55,9 @@ buttonMove_Down.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMove_Down.BackgroundImage = Properties.Resources.ArrowDown; buttonMove_Down.BackgroundImageLayout = ImageLayout.Stretch; - buttonMove_Down.Location = new Point(829, 569); - buttonMove_Down.Margin = new Padding(3, 4, 3, 4); + buttonMove_Down.Location = new Point(725, 427); buttonMove_Down.Name = "buttonMove_Down"; - buttonMove_Down.Size = new Size(40, 47); + buttonMove_Down.Size = new Size(35, 35); buttonMove_Down.TabIndex = 1; buttonMove_Down.UseVisualStyleBackColor = true; buttonMove_Down.Click += ButtonMove_Click; @@ -68,10 +67,9 @@ buttonMove_Left.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMove_Left.BackgroundImage = Properties.Resources.ArrowLeft; buttonMove_Left.BackgroundImageLayout = ImageLayout.Stretch; - buttonMove_Left.Location = new Point(782, 569); - buttonMove_Left.Margin = new Padding(3, 4, 3, 4); + buttonMove_Left.Location = new Point(684, 427); buttonMove_Left.Name = "buttonMove_Left"; - buttonMove_Left.Size = new Size(40, 47); + buttonMove_Left.Size = new Size(35, 35); buttonMove_Left.TabIndex = 2; buttonMove_Left.UseVisualStyleBackColor = true; buttonMove_Left.Click += ButtonMove_Click; @@ -81,10 +79,9 @@ buttonMove_Up.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMove_Up.BackgroundImage = Properties.Resources.ArrowUp; buttonMove_Up.BackgroundImageLayout = ImageLayout.Stretch; - buttonMove_Up.Location = new Point(829, 515); - buttonMove_Up.Margin = new Padding(3, 4, 3, 4); + buttonMove_Up.Location = new Point(725, 386); buttonMove_Up.Name = "buttonMove_Up"; - buttonMove_Up.Size = new Size(40, 47); + buttonMove_Up.Size = new Size(35, 35); buttonMove_Up.TabIndex = 3; buttonMove_Up.UseVisualStyleBackColor = true; buttonMove_Up.Click += ButtonMove_Click; @@ -94,36 +91,45 @@ pictureBoxMonorail.Dock = DockStyle.Fill; pictureBoxMonorail.ImageLocation = ""; pictureBoxMonorail.Location = new Point(0, 0); - pictureBoxMonorail.Margin = new Padding(3, 4, 3, 4); pictureBoxMonorail.Name = "pictureBoxMonorail"; - pictureBoxMonorail.Size = new Size(929, 632); + pictureBoxMonorail.Size = new Size(813, 474); pictureBoxMonorail.TabIndex = 4; pictureBoxMonorail.TabStop = false; // + // buttonCreateModernMonorail + // + buttonCreateModernMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateModernMonorail.Location = new Point(12, 439); + buttonCreateModernMonorail.Name = "buttonCreateModernMonorail"; + buttonCreateModernMonorail.Size = new Size(220, 23); + buttonCreateModernMonorail.TabIndex = 5; + buttonCreateModernMonorail.Text = "Создать современный монорельс"; + buttonCreateModernMonorail.UseVisualStyleBackColor = true; + buttonCreateModernMonorail.Click += ButtonCreateModernMonorail_Click; + // // buttonCreateMonorail // buttonCreateMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateMonorail.Location = new Point(14, 585); - buttonCreateMonorail.Margin = new Padding(3, 4, 3, 4); + buttonCreateMonorail.Location = new Point(238, 439); buttonCreateMonorail.Name = "buttonCreateMonorail"; - buttonCreateMonorail.Size = new Size(86, 31); - buttonCreateMonorail.TabIndex = 5; - buttonCreateMonorail.Text = "Создать"; + buttonCreateMonorail.Size = new Size(194, 23); + buttonCreateMonorail.TabIndex = 6; + buttonCreateMonorail.Text = "Создать монорельс"; buttonCreateMonorail.UseVisualStyleBackColor = true; - buttonCreateMonorail.Click += ButtonCreateMonorail_Click; + buttonCreateMonorail.Click += buttonCreateMonorail_Click; // // FormMonorail // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(929, 632); + ClientSize = new Size(813, 474); Controls.Add(buttonCreateMonorail); + Controls.Add(buttonCreateModernMonorail); Controls.Add(buttonMove_Up); Controls.Add(buttonMove_Left); Controls.Add(buttonMove_Down); Controls.Add(buttonMove_Right); Controls.Add(pictureBoxMonorail); - Margin = new Padding(3, 4, 3, 4); Name = "FormMonorail"; Text = "Монорельс"; ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit(); @@ -137,6 +143,7 @@ private Button buttonMove_Left; private Button buttonMove_Up; private PictureBox pictureBoxMonorail; + private Button buttonCreateModernMonorail; private Button buttonCreateMonorail; } } \ No newline at end of file diff --git a/ProjectSportCar/FormMonorail.cs b/ProjectSportCar/FormMonorail.cs index 0f6ac8e..b86977a 100644 --- a/ProjectSportCar/FormMonorail.cs +++ b/ProjectSportCar/FormMonorail.cs @@ -1,10 +1,10 @@ -using ProjectMonorail.Scripts.Locomative; +using ProjectMonorail.Scripts.Monorail.Drawnings; namespace ProjectMonorail { public partial class FormMonorail : Form { - private DrawMonorail? _drawningMonorail; + private DrawingMonorail? _drawningMonorail; public FormMonorail() { @@ -14,7 +14,7 @@ namespace ProjectMonorail /// /// Метод для прорисовки автомобиля /// - private void Draw () + private void Draw() { if (_drawningMonorail == null) return; @@ -24,26 +24,6 @@ namespace ProjectMonorail pictureBoxMonorail.Image = bmp; } - /// - /// Обработка нажатия кнопки "Создать" - /// - private void ButtonCreateMonorail_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningMonorail = new DrawMonorail(); - - _drawningMonorail.Initialization(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2))); - - _drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height); - _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100)); - - Draw(); - } - /// /// Обработка кнопок перемешения /// @@ -53,23 +33,74 @@ namespace ProjectMonorail string name = ((Button)sender).Name ?? string.Empty; bool result = false; - switch(name) + switch (name) { case "buttonMove_Up": - result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Up); + result = _drawningMonorail.MoveTransport(DirectionType.Up); break; case "buttonMove_Down": - result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Down); + result = _drawningMonorail.MoveTransport(DirectionType.Down); break; case "buttonMove_Right": - result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Right); + result = _drawningMonorail.MoveTransport(DirectionType.Right); break; case "buttonMove_Left": - result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Left); + result = _drawningMonorail.MoveTransport(DirectionType.Left); break; } if (result) Draw(); } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создоваемого объекта + private void CreateObject(string type) + { + Random random = new(); + + switch (type) + { + case nameof(DrawingMonorail): + _drawningMonorail = new DrawingMonorail(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + break; + case nameof(DrawingModernMonorail): + bool randomTrack = Convert.ToBoolean(random.Next(0, 2)); + _drawningMonorail = new DrawingModernMonorail(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + randomTrack, + (randomTrack? Convert.ToBoolean(random.Next(0, 2)) : true)); + break; + default: + return; + } + + _drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height); + _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100)); + + Draw(); + } + + /// + /// Обработка нажатия кнопки "Создать современный монорельс" + /// + private void ButtonCreateModernMonorail_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingModernMonorail)); + } + + /// + /// Обработка нажатия кнопки "Создать монорельс" + /// + /// + /// + private void buttonCreateMonorail_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingMonorail)); + } + } } diff --git a/ProjectSportCar/Scripts/DirectionType.cs b/ProjectSportCar/Scripts/Monorail/Drawnings/DirectionType.cs similarity index 89% rename from ProjectSportCar/Scripts/DirectionType.cs rename to ProjectSportCar/Scripts/Monorail/Drawnings/DirectionType.cs index b3c2733..1851297 100644 --- a/ProjectSportCar/Scripts/DirectionType.cs +++ b/ProjectSportCar/Scripts/Monorail/Drawnings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectMonorail.Scripts +namespace ProjectMonorail.Scripts.Monorail.Drawnings { /// /// Направление перемещения diff --git a/ProjectSportCar/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs b/ProjectSportCar/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs new file mode 100644 index 0000000..be1faf7 --- /dev/null +++ b/ProjectSportCar/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs @@ -0,0 +1,137 @@ +using System.Drawing.Drawing2D; +using ProjectMonorail.Scripts.Monorail.Entities; + +namespace ProjectMonorail.Scripts.Monorail.Drawnings +{ + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawingModernMonorail : DrawingMonorail + { + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия монорельсового пути + /// Признак наличия кабиныы + public DrawingModernMonorail(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin) : base((cabin ? 170 : 90), 40) + { + EntityMonorail = new EntityModernMonorail(speed, weight, bodyColor, additionalColor, monorailTrack, cabin); + } + + /// + /// Прорисовка объекта + /// + public override void DrawTransport(Graphics g) + { + if (EntityMonorail == null || EntityMonorail is not EntityModernMonorail entityModernMonorail || !_startPositionX.HasValue || !_startPositionY.HasValue) return; + + Pen pen_Body = new Pen(EntityMonorail.BodyColor, 1.5f); + Pen pen_Additional = new Pen(entityModernMonorail.AdditionalColor, 1.5f); + + Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor); + Brush brush_Additional = new SolidBrush(entityModernMonorail.AdditionalColor); + + + base.DrawTransport(g); + + //Перекраска окон первого монорельса + g.DrawRectangle(pen_Additional, _startPositionX.Value + 14, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Additional, _startPositionX.Value + 21, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Additional, _startPositionX.Value + 70, _startPositionY.Value + 2, 5, 6); + + if (entityModernMonorail.MonorailTrack) + { + if (entityModernMonorail.Cabin) + { + g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 170, 5); + } + else + { + g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 86, 5); + } + } + + //Колеса + Brush brush_White = new SolidBrush(Color.White); + g.FillEllipse(brush_White, _startPositionX.Value + 10, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value + 10, _startPositionY.Value + 30, 10, 10); + + g.FillEllipse(brush_White, _startPositionX.Value + 25, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value + 25, _startPositionY.Value + 30, 10, 10); + + g.FillEllipse(brush_White, _startPositionX.Value + 65, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value + 65, _startPositionY.Value + 30, 10, 10); + + g.FillEllipse(brush_White, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10); + + + if (entityModernMonorail.Cabin) + { + int offset = 170; + //Кузов монорельса + GraphicsPath pointsMonorailBody_RightBody = new GraphicsPath(); + pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 13 + offset, _startPositionY.Value); + pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 13 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value); + pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25); + pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 25); + pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10); + g.DrawLine(pen_Body, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 30 + offset, _startPositionY.Value + 10); + g.DrawLine(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 10, _startPositionX.Value - 80 + offset, _startPositionY.Value + 10); + g.DrawPath(pen_Body, pointsMonorailBody_RightBody); + + //Дверь + g.DrawRectangle(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 5, 9, 15); + + //Окна + g.DrawRectangle(pen_Additional, _startPositionX.Value - 20 + offset, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Additional, _startPositionX.Value - 27 + offset, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Additional, _startPositionX.Value - 76 + offset, _startPositionY.Value + 2, 5, 6); + + //Связка монорельса + g.FillRectangle(brush_Body, _startPositionX.Value - 87 + offset, _startPositionY.Value + 2, 7, 22); + + //Нижняя часть монорельса + PointF[] pointsLowerPartMonorail_2_LeftSide = new PointF[8]; + pointsLowerPartMonorail_2_LeftSide[0] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 30); + pointsLowerPartMonorail_2_LeftSide[1] = new PointF(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25); + pointsLowerPartMonorail_2_LeftSide[2] = new PointF(_startPositionX.Value - 72 + offset, _startPositionY.Value + 25); + pointsLowerPartMonorail_2_LeftSide[3] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 25); + pointsLowerPartMonorail_2_LeftSide[4] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 32); + pointsLowerPartMonorail_2_LeftSide[5] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 32); + pointsLowerPartMonorail_2_LeftSide[6] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 35); + pointsLowerPartMonorail_2_LeftSide[7] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 32); + g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_LeftSide); + + PointF[] pointsLowerPartMonorail_2_RightSide = new PointF[7]; + pointsLowerPartMonorail_2_RightSide[0] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 30); + pointsLowerPartMonorail_2_RightSide[1] = new PointF(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25); + pointsLowerPartMonorail_2_RightSide[2] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 25); + pointsLowerPartMonorail_2_RightSide[3] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 32); + pointsLowerPartMonorail_2_RightSide[4] = new PointF(_startPositionX.Value - 69 + offset, _startPositionY.Value + 32); + pointsLowerPartMonorail_2_RightSide[5] = new PointF(_startPositionX.Value - 79 + offset, _startPositionY.Value + 35); + pointsLowerPartMonorail_2_RightSide[6] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 32); + g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_RightSide); + g.FillRectangle(brush_Body, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25, 70, 3); + + + //Колеса + g.FillEllipse(brush_White, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10); + + g.FillEllipse(brush_White, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10); + + g.FillEllipse(brush_White, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10); + + g.FillEllipse(brush_White, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10); + g.DrawEllipse(pen_Body, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10); + } + } + } +} diff --git a/ProjectSportCar/Scripts/Monorail/DrawMonorail.cs b/ProjectSportCar/Scripts/Monorail/Drawnings/DrawingMonorail.cs similarity index 57% rename from ProjectSportCar/Scripts/Monorail/DrawMonorail.cs rename to ProjectSportCar/Scripts/Monorail/Drawnings/DrawingMonorail.cs index 5e26aba..aadc1e3 100644 --- a/ProjectSportCar/Scripts/Monorail/DrawMonorail.cs +++ b/ProjectSportCar/Scripts/Monorail/Drawnings/DrawingMonorail.cs @@ -1,13 +1,17 @@ -using System.Drawing.Drawing2D; +using ProjectMonorail.Scripts.Monorail.Entities; +using System.Drawing.Drawing2D; -namespace ProjectMonorail.Scripts.Locomative +namespace ProjectMonorail.Scripts.Monorail.Drawnings { - public class DrawMonorail + /// + /// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности + /// + public class DrawingMonorail { /// /// Класс-сущность /// - public EntityMonorail? EntityMonorail { get; private set; } + public EntityMonorail? EntityMonorail { get; protected set; } /// /// Ширина окна @@ -20,45 +24,55 @@ namespace ProjectMonorail.Scripts.Locomative private int? _pictureHeight; /// - /// Левая координата прорисовки автомобиля + /// Левая координата прорисовки монорельса /// - private int? _startPositionX; + protected int? _startPositionX; /// - /// Верхняя кооридната прорисовки автомобиля + /// Верхняя кооридната прорисовки монорельса /// - private int? _startPositionY; + protected int? _startPositionY; /// - /// Ширина прорисовки автомобиля + /// Ширина прорисовки монорельса /// - private int _drawningMonorailWidth = 110; + private readonly int _drawningMonorailWidth = 90; /// - /// Высота прорисовки автомобиля + /// Высота прорисовки монорельса /// private readonly int _drawningMonorailHeight = 40; - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия монорельсового пути - /// Признак наличия кабиныы - public void Initialization(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin) + private DrawingMonorail() { - EntityMonorail = new EntityMonorail(); - EntityMonorail.Initialization(speed, weight, bodyColor, additionalColor, monorailTrack, cabin); - _drawningMonorailWidth = cabin ? 170 : 90; _pictureWidth = null; _pictureHeight = null; _startPositionX = null; _startPositionY = null; } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawingMonorail(int speed, double weight, Color bodyColor) : this() + { + EntityMonorail = new EntityMonorail(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки монорельса + /// Высота прорисовки монорельса + protected DrawingMonorail(int drawningMonorailWidth, int drawningMonorailHeight) : this() + { + _drawningMonorailWidth = drawningMonorailWidth; + _drawningMonorailHeight = drawningMonorailHeight; + } + /// /// Установка границ поля /// @@ -69,7 +83,7 @@ namespace ProjectMonorail.Scripts.Locomative { // TODO проверка, что объект "влезает" в размеры поля // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена - if (_drawningMonorailWidth > width || _drawningMonorailHeight > height) return false; + if (_drawningMonorailWidth > width || _drawningMonorailHeight > height) return false; if (_startPositionX.HasValue && _startPositionY.HasValue) { @@ -164,15 +178,13 @@ namespace ProjectMonorail.Scripts.Locomative /// /// Прорисовка объекта /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (EntityMonorail == null || !_startPositionX.HasValue || !_startPositionY.HasValue) return; Pen pen_Body = new Pen(EntityMonorail.BodyColor, 1.5f); - Pen pen_Additional = new Pen(EntityMonorail.AdditionalColor, 1.5f); Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor); - Brush brush_Additional = new SolidBrush(EntityMonorail.AdditionalColor); //Кузов монорельса @@ -190,9 +202,9 @@ namespace ProjectMonorail.Scripts.Locomative g.DrawRectangle(pen_Body, _startPositionX.Value + 30, _startPositionY.Value + 5, 9, 15); //Окна - g.DrawRectangle(pen_Additional, _startPositionX.Value + 14, _startPositionY.Value + 2, 5, 6); - g.DrawRectangle(pen_Additional, _startPositionX.Value + 21, _startPositionY.Value + 2, 5, 6); - g.DrawRectangle(pen_Additional, _startPositionX.Value + 70, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Body, _startPositionX.Value + 14, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Body, _startPositionX.Value + 21, _startPositionY.Value + 2, 5, 6); + g.DrawRectangle(pen_Body, _startPositionX.Value + 70, _startPositionY.Value + 2, 5, 6); //Связка монорельса g.FillRectangle(brush_Body, _startPositionX.Value + 80, _startPositionY.Value + 2, 7, 22); @@ -220,18 +232,6 @@ namespace ProjectMonorail.Scripts.Locomative g.FillPolygon(brush_Body, pointsLowerPartMonorail_RightSide); g.FillRectangle(brush_Body, _startPositionX.Value + 8, _startPositionY.Value + 25, 70, 3); - if (EntityMonorail.MonorailTrack) - { - if (EntityMonorail.Cabin) - { - g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 170, 5); - } - else - { - g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 86, 5); - } - } - //Колеса Brush brush_White = new SolidBrush(Color.White); g.FillEllipse(brush_White, _startPositionX.Value + 10, _startPositionY.Value + 30, 10, 10); @@ -245,70 +245,6 @@ namespace ProjectMonorail.Scripts.Locomative g.FillEllipse(brush_White, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10); g.DrawEllipse(pen_Body, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10); - - - if (EntityMonorail.Cabin) - { - int offset = 170; - //Кузов монорельса - GraphicsPath pointsMonorailBody_RightBody = new GraphicsPath(); - pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 13 + offset, _startPositionY.Value); - pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 13 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value); - pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25); - pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 25); - pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10); - g.DrawLine(pen_Body, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 30 + offset, _startPositionY.Value + 10); - g.DrawLine(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 10, _startPositionX.Value - 80 + offset, _startPositionY.Value + 10); - g.DrawPath(pen_Body, pointsMonorailBody_RightBody); - - //Дверь - g.DrawRectangle(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 5, 9, 15); - - //Окна - g.DrawRectangle(pen_Additional, _startPositionX.Value - 20 + offset, _startPositionY.Value + 2, 5, 6); - g.DrawRectangle(pen_Additional, _startPositionX.Value - 27 + offset, _startPositionY.Value + 2, 5, 6); - g.DrawRectangle(pen_Additional, _startPositionX.Value - 76 + offset, _startPositionY.Value + 2, 5, 6); - - //Связка монорельса - g.FillRectangle(brush_Body, _startPositionX.Value - 87 + offset, _startPositionY.Value + 2, 7, 22); - - //Нижняя часть монорельса - PointF[] pointsLowerPartMonorail_2_LeftSide = new PointF[8]; - pointsLowerPartMonorail_2_LeftSide[0] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 30); - pointsLowerPartMonorail_2_LeftSide[1] = new PointF(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25); - pointsLowerPartMonorail_2_LeftSide[2] = new PointF(_startPositionX.Value - 72 + offset, _startPositionY.Value + 25); - pointsLowerPartMonorail_2_LeftSide[3] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 25); - pointsLowerPartMonorail_2_LeftSide[4] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 32); - pointsLowerPartMonorail_2_LeftSide[5] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 32); - pointsLowerPartMonorail_2_LeftSide[6] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 35); - pointsLowerPartMonorail_2_LeftSide[7] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 32); - g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_LeftSide); - - PointF[] pointsLowerPartMonorail_2_RightSide = new PointF[7]; - pointsLowerPartMonorail_2_RightSide[0] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 30); - pointsLowerPartMonorail_2_RightSide[1] = new PointF(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25); - pointsLowerPartMonorail_2_RightSide[2] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 25); - pointsLowerPartMonorail_2_RightSide[3] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 32); - pointsLowerPartMonorail_2_RightSide[4] = new PointF(_startPositionX.Value - 69 + offset, _startPositionY.Value + 32); - pointsLowerPartMonorail_2_RightSide[5] = new PointF(_startPositionX.Value - 79 + offset, _startPositionY.Value + 35); - pointsLowerPartMonorail_2_RightSide[6] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 32); - g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_RightSide); - g.FillRectangle(brush_Body, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25, 70, 3); - - - //Колеса - g.FillEllipse(brush_White, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10); - g.DrawEllipse(pen_Body, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10); - - g.FillEllipse(brush_White, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10); - g.DrawEllipse(pen_Body, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10); - - g.FillEllipse(brush_White, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10); - g.DrawEllipse(pen_Body, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10); - - g.FillEllipse(brush_White, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10); - g.DrawEllipse(pen_Body, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10); - } } } } diff --git a/ProjectSportCar/Scripts/Monorail/EntityMonorail.cs b/ProjectSportCar/Scripts/Monorail/Entities/EntityModernMonorail.cs similarity index 62% rename from ProjectSportCar/Scripts/Monorail/EntityMonorail.cs rename to ProjectSportCar/Scripts/Monorail/Entities/EntityModernMonorail.cs index b1b500c..2fe635d 100644 --- a/ProjectSportCar/Scripts/Monorail/EntityMonorail.cs +++ b/ProjectSportCar/Scripts/Monorail/Entities/EntityModernMonorail.cs @@ -1,22 +1,10 @@ -namespace ProjectMonorail +namespace ProjectMonorail.Scripts.Monorail.Entities { - public class EntityMonorail + /// + /// Класс-сущности "Современный монорельс" + /// + public class EntityModernMonorail : EntityMonorail { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет (для опциональных элементов) /// @@ -32,11 +20,6 @@ /// public bool Cabin { get; private set; } - /// - /// Шаг перемещения автомобиля - /// - public double Step => Speed * 100 / Weight; - /// /// Инициальзация полей объекта-класса спортивного автомобиля /// @@ -46,11 +29,8 @@ /// Дополнительный цвет /// Признак наличия монорельсового пути /// Признак наличия кабины - public void Initialization(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin) + public EntityModernMonorail(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; MonorailTrack = monorailTrack; Cabin = cabin; diff --git a/ProjectSportCar/Scripts/Monorail/Entities/EntityMonorail.cs b/ProjectSportCar/Scripts/Monorail/Entities/EntityMonorail.cs new file mode 100644 index 0000000..62591c7 --- /dev/null +++ b/ProjectSportCar/Scripts/Monorail/Entities/EntityMonorail.cs @@ -0,0 +1,41 @@ +namespace ProjectMonorail.Scripts.Monorail.Entities +{ + /// + /// Класс-сущности "Монорельс" + /// + public class EntityMonorail + { + /// + /// Скорость + /// + 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 EntityMonorail(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } +}