From d6b157b93affc544055cff9a71f24a325c21bad5 Mon Sep 17 00:00:00 2001 From: Anastasia Yazykova Date: Tue, 2 Apr 2024 21:50:52 +0400 Subject: [PATCH 1/3] =?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=B4?= =?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 --- TrolleybusProject/TrolleybusProject.sln | 2 +- .../TrolleybusProject/DirectionType.cs | 2 +- .../DrawningBus.cs} | 162 ++++++++---------- .../Drawnings/DrawningTrolleybus.cs | 93 ++++++++++ .../TrolleybusProject/Entities/EntityBus.cs | 54 ++++++ .../{ => Entities}/EntityTrolleybus.cs | 35 ++-- .../FormTrolleybus.Designer.cs | 18 +- .../TrolleybusProject/FormTrolleybus.cs | 107 ++++++++---- 8 files changed, 331 insertions(+), 142 deletions(-) rename TrolleybusProject/TrolleybusProject/{DrawningTrolleybus.cs => Drawnings/DrawningBus.cs} (62%) create mode 100644 TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs create mode 100644 TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs rename TrolleybusProject/TrolleybusProject/{ => Entities}/EntityTrolleybus.cs (66%) diff --git a/TrolleybusProject/TrolleybusProject.sln b/TrolleybusProject/TrolleybusProject.sln index 2c5cb6e..47fba66 100644 --- a/TrolleybusProject/TrolleybusProject.sln +++ b/TrolleybusProject/TrolleybusProject.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrolleybusProject", "TrolleybusProject\TrolleybusProject.csproj", "{212BCE90-1598-4573-A91D-8498ED312A2B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrolleybusProject", "TrolleybusProject\TrolleybusProject.csproj", "{212BCE90-1598-4573-A91D-8498ED312A2B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/TrolleybusProject/TrolleybusProject/DirectionType.cs b/TrolleybusProject/TrolleybusProject/DirectionType.cs index 19324b3..39d3b0f 100644 --- a/TrolleybusProject/TrolleybusProject/DirectionType.cs +++ b/TrolleybusProject/TrolleybusProject/DirectionType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TrolleybusProject; +namespace TrolleybusProject.Drawnings; public enum DirectionType { diff --git a/TrolleybusProject/TrolleybusProject/DrawningTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs similarity index 62% rename from TrolleybusProject/TrolleybusProject/DrawningTrolleybus.cs rename to TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs index 84b8226..785995e 100644 --- a/TrolleybusProject/TrolleybusProject/DrawningTrolleybus.cs +++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs @@ -3,15 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TrolleybusProject.Entities; -namespace TrolleybusProject; +namespace TrolleybusProject.Drawnings; -public class DrawningTrolleybus +public class DrawningBus { /// /// Класс-сущность /// - public EntityTrolleybus? EntityTrolleybus { get; private set; } + public EntityBus? EntityBus { get; protected set; } /// /// Ширина окна /// @@ -23,41 +24,70 @@ public class DrawningTrolleybus /// /// Левая координата прорисовки троллейбуса /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя кооридната прорисовки троллейбуса /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки троллейбуса /// - public readonly int _drawningTrolleybusWidth = 150; + public readonly int _drawningBusWidth = 150; /// /// Высота прорисовки троллейбуса /// - public readonly int _drawningTrolleybusHeight = 86; + public readonly int _drawningBusHeight = 86; + + + /// - /// Инициализация свойств + /// Конструктор пустой /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия рогов - /// Признак наличия дверей - /// Признак наличия отсека - public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool doors, bool roga, bool otsek) + private DrawningBus() { - EntityTrolleybus = new EntityTrolleybus(); - EntityTrolleybus.Init(speed, weight, bodyColor, additionalColor, - doors, roga, otsek); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + + + + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + + public DrawningBus(int speed, double weight, Color bodyColor):this() + { + EntityBus = new EntityBus(speed, weight, bodyColor); + + } + + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки автобуса + /// Высота прорисовки автобуса + + + protected DrawningBus(int drawningBusWidth, int drawningBusHeight) : this() + { + _drawningBusWidth= drawningBusWidth; + _drawningBusHeight = drawningBusHeight; + + } + + + + + + /// /// Установка границ поля /// @@ -66,7 +96,7 @@ public class DrawningTrolleybus /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - if (width> _drawningTrolleybusWidth || height > _drawningTrolleybusHeight) + if (width > _drawningBusWidth || height > _drawningBusHeight) { _pictureWidth = width; _pictureHeight = height; @@ -75,17 +105,17 @@ public class DrawningTrolleybus if (_startPosY.HasValue && _startPosX.HasValue) { - if (_startPosX + _drawningTrolleybusWidth > width) + if (_startPosX + _drawningBusWidth > width) { - _startPosX = width - _drawningTrolleybusWidth; + _startPosX = width - _drawningBusWidth; } - if (_startPosY + _drawningTrolleybusHeight > height) + if (_startPosY + _drawningBusHeight > height) { - _startPosY = height - _drawningTrolleybusHeight; + _startPosY = height - _drawningBusHeight; } @@ -109,7 +139,7 @@ public class DrawningTrolleybus - + return false; @@ -137,22 +167,22 @@ public class DrawningTrolleybus if (_startPosY < 0) { _startPosY = 0; } - if (x + _drawningTrolleybusWidth > _pictureWidth) + if (x + _drawningBusWidth > _pictureWidth) { - _startPosX = _pictureWidth - _drawningTrolleybusWidth; + _startPosX = _pictureWidth - _drawningBusWidth; } - if (y + _drawningTrolleybusHeight > _pictureHeight) + if (y + _drawningBusHeight > _pictureHeight) { - _startPosY = _pictureHeight - _drawningTrolleybusHeight; + _startPosY = _pictureHeight - _drawningBusHeight; } - + } /// /// Изменение направления перемещения @@ -161,7 +191,7 @@ public class DrawningTrolleybus /// true - перемещене выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntityTrolleybus == null || !_startPosX.HasValue || + if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; @@ -170,31 +200,31 @@ public class DrawningTrolleybus { //влево case DirectionType.Left: - if (_startPosX.Value - EntityTrolleybus.Step > 0) + if (_startPosX.Value - EntityBus.Step > 0) { - _startPosX -= (int)EntityTrolleybus.Step; + _startPosX -= (int)EntityBus.Step; } return true; //вверх case DirectionType.Up: - if (_startPosY.Value - EntityTrolleybus.Step > 0) + if (_startPosY.Value - EntityBus.Step > 0) { - _startPosY -= (int)EntityTrolleybus.Step; + _startPosY -= (int)EntityBus.Step; } return true; // вправо case DirectionType.Right: - if (_startPosX.Value + EntityTrolleybus.Step < _pictureWidth - _drawningTrolleybusWidth) + if (_startPosX.Value + EntityBus.Step < _pictureWidth - _drawningBusWidth) { - _startPosX += (int)EntityTrolleybus.Step; + _startPosX += (int)EntityBus.Step; } return true; //вниз case DirectionType.Down: - if (_startPosY.Value + EntityTrolleybus.Step < _pictureHeight - _drawningTrolleybusHeight) + if (_startPosY.Value + EntityBus.Step < _pictureHeight - _drawningBusHeight) { - _startPosY += (int)EntityTrolleybus.Step; + _startPosY += (int)EntityBus.Step; } return true; default: @@ -205,18 +235,18 @@ public class DrawningTrolleybus /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityTrolleybus == null || !_startPosX.HasValue || + if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new - SolidBrush(EntityTrolleybus.AdditionalColor); - Brush brushBodyColor = new SolidBrush(EntityTrolleybus.BodyColor); - Pen addpen = new(EntityTrolleybus.AdditionalColor); + + + Brush brushBodyColor = new SolidBrush(EntityBus.BodyColor); + //троллейбус границы g.DrawEllipse(pen, _startPosX.Value + 27, _startPosY.Value + 64, 20, 20); @@ -301,45 +331,5 @@ public class DrawningTrolleybus - - //рога - - if (EntityTrolleybus.Roga) - { - g.DrawLine(addpen, _startPosX.Value + 42, _startPosY.Value + 7, - _startPosX.Value + 124, _startPosY.Value + 29); - g.DrawLine(addpen, _startPosX.Value + 62, _startPosY.Value + 2, - _startPosX.Value + 124, _startPosY.Value + 29); - - - } - //отсек для батареек - - if (EntityTrolleybus.Otsek) - { - g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + - 48, 5, 20); - g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + - 48, 5, 20); - - g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + - 48, 5, 20); - } - - //двойная дверь - - if (EntityTrolleybus.Doors) - { - g.DrawLine(addpen, _startPosX.Value + 66, _startPosY.Value + 40, - _startPosX.Value + 66, _startPosY.Value + 70); - - - - } - } } - - - - diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs new file mode 100644 index 0000000..232c600 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs @@ -0,0 +1,93 @@ +using TrolleybusProject.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +namespace TrolleybusProject.Drawnings; + +public class DrawningTrolleybus:DrawningBus +{ + /// + /// Клнструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия рогов + /// Признак наличия дверей + /// Признак наличия отсека + public DrawningTrolleybus(int speed, double weight, Color bodyColor, Color + additionalColor, bool doors, bool roga, bool otsek):base(150,86) + { + EntityBus = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, + doors, roga, otsek); + + + } + + public override void DrawTransport(Graphics g) + { + if (EntityBus == null || EntityBus is not EntityTrolleybus trolleybus|| !_startPosX.HasValue || + !_startPosY.HasValue) + { + return; + } + + + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(trolleybus.AdditionalColor); + Pen addpen = new(trolleybus.AdditionalColor); + + + + if (trolleybus.Otsek) + { + + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + + 48, 5, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + + 48, 5, 20); + + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + + 48, 5, 20); + } + + //двойная дверь + + + + _startPosX += 22; + _startPosY += 15; + base.DrawTransport(g); + _startPosX -= 22; + _startPosY -= 15; + + + if (trolleybus.Doors) + { + g.DrawLine(addpen, _startPosX.Value + 66, _startPosY.Value + 40, + _startPosX.Value + 66, _startPosY.Value + 70); + + + + } + } + + + + + +} + + + + + + + diff --git a/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs b/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs new file mode 100644 index 0000000..cb6a2a0 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs @@ -0,0 +1,54 @@ +using System; +using System.Net.Sockets; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + + + + + + + + +namespace TrolleybusProject.Entities; + +/// +/// Класс-сущность Автобус +/// +public class EntityBus +{ + /// + /// Скорость + /// + 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 EntityBus(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + + } +} diff --git a/TrolleybusProject/TrolleybusProject/EntityTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs similarity index 66% rename from TrolleybusProject/TrolleybusProject/EntityTrolleybus.cs rename to TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs index ce0aca5..060e21b 100644 --- a/TrolleybusProject/TrolleybusProject/EntityTrolleybus.cs +++ b/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs @@ -4,26 +4,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TrolleybusProject; -public class EntityTrolleybus +namespace TrolleybusProject.Entities; + +public class EntityTrolleybus: 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; } /// /// Признак (опция) наличие рогов @@ -38,10 +25,15 @@ public class EntityTrolleybus /// Признак (опция) наличия двойной двери /// public bool Doors { get; private set; } + /// /// Шаг перемещения троллейбуса /// - public double Step => Speed * 100 / Weight; + + + + + /// /// Инициализация полей объекта-класса троллейбуса /// @@ -52,12 +44,9 @@ public class EntityTrolleybus /// Признак наличия рогов /// Признак наличия отсека /// Признак наличия двойной двери - public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool roga, bool otsek, bool doors) + public EntityTrolleybus(int speed, double weight, Color bodyColor, Color + additionalColor, bool roga, bool otsek, bool doors):base(speed,weight,bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Roga = roga; Otsek = otsek; diff --git a/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs b/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs index e86db48..49c9e8d 100644 --- a/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs +++ b/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs @@ -34,6 +34,7 @@ buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); + buttonCreateBus = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit(); SuspendLayout(); // @@ -51,9 +52,9 @@ buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Location = new Point(21, 515); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(112, 34); + buttonCreate.Size = new Size(188, 34); buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; + buttonCreate.Text = "Создать Троллейбус"; buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += buttonCreate_Click; // @@ -105,11 +106,23 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += buttonMove_Click; // + // buttonCreateBus + // + buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateBus.Location = new Point(249, 515); + buttonCreateBus.Name = "buttonCreateBus"; + buttonCreateBus.Size = new Size(188, 34); + buttonCreateBus.TabIndex = 6; + buttonCreateBus.Text = "Создать Автобус"; + buttonCreateBus.UseVisualStyleBackColor = true; + buttonCreateBus.Click += buttonCreateBus_Click; + // // FormTrolleybus // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1273, 561); + Controls.Add(buttonCreateBus); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); @@ -130,5 +143,6 @@ private Button buttonRight; private Button buttonUp; private Button buttonDown; + private Button buttonCreateBus; } } \ No newline at end of file diff --git a/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs b/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs index 7c54417..bfa8d9e 100644 --- a/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs +++ b/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs @@ -7,40 +7,91 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using TrolleybusProject.Drawnings; namespace TrolleybusProject { public partial class FormTrolleybus : Form { - private DrawningTrolleybus? _drawningTrolleybus; + private DrawningBus? _drawningBus; public FormTrolleybus() { InitializeComponent(); + } + + + + /// + /// Метод прорисовки машины + /// + private void Draw() + { + if (_drawningBus == null) + { + return; + } + Bitmap bmp = new(pictureBoxTrolleybus.Width, + pictureBoxTrolleybus.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningBus.DrawTransport(gr); + pictureBoxTrolleybus.Image = bmp; + } + + + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawningBus): + _drawningBus = new DrawningBus(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(DrawningTrolleybus): + _drawningBus = new DrawningTrolleybus(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)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + _drawningBus.SetPictureSize(pictureBoxTrolleybus.Width, + pictureBoxTrolleybus.Height); + _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); + + Draw(); + + } + + + + + + + + private void buttonCreate_Click(object sender, EventArgs e) { - Random random = new(); - _drawningTrolleybus = new DrawningTrolleybus(); - _drawningTrolleybus.Init(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)), Convert.ToBoolean(random.Next(0, 2))); - - _drawningTrolleybus.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); - - _drawningTrolleybus.SetPosition(random.Next(10, 100), random.Next(10, 100)); - - Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawningTrolleybus.DrawTransport(gr); - pictureBoxTrolleybus.Image = bmp; - + CreateObject(nameof(DrawningTrolleybus)); } private void buttonMove_Click(object sender, EventArgs e) { - if (_drawningTrolleybus == null) + if (_drawningBus == null) { return; } @@ -49,34 +100,32 @@ namespace TrolleybusProject switch (name) { case "buttonUp": - result = _drawningTrolleybus.MoveTransport(DirectionType.Up); + result = _drawningBus.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningTrolleybus.MoveTransport(DirectionType.Down); + result = _drawningBus.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningTrolleybus.MoveTransport(DirectionType.Left); + result = _drawningBus.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningTrolleybus.MoveTransport(DirectionType.Right); + result = _drawningBus.MoveTransport(DirectionType.Right); break; } if (result) { - Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawningTrolleybus.DrawTransport(gr); - pictureBoxTrolleybus.Image = bmp; + Draw(); } } + private void buttonCreateBus_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningBus)); - - - + } } } \ No newline at end of file -- 2.25.1 From ab92a28aff26fd06ef1a924d514c2766ca598570 Mon Sep 17 00:00:00 2001 From: Anastasia Yazykova Date: Tue, 2 Apr 2024 23:35:31 +0400 Subject: [PATCH 2/3] =?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=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrolleybusProject/DirectionType.cs | 2 +- .../Drawnings/DrawningBus.cs | 18 +++ .../FormTrolleybus.Designer.cs | 26 ++++ .../TrolleybusProject/FormTrolleybus.cs | 62 ++++++++- .../MovementStrategy/AbstractractStrategy.cs | 127 ++++++++++++++++++ .../MovementStrategy/IMoveableObjectcs.cs | 30 +++++ .../MovementStrategy/MoveToBorder.cs | 58 ++++++++ .../MovementStrategy/MoveToCenter.cs | 56 ++++++++ .../MovementStrategy/MoveableBus.cs | 72 ++++++++++ .../MovementStrategy/MovementDirection.cs | 27 ++++ .../MovementStrategy/ObjectParameters.cs | 70 ++++++++++ .../MovementStrategy/StrategyStatus.cs | 25 ++++ 12 files changed, 568 insertions(+), 5 deletions(-) create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/AbstractractStrategy.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/IMoveableObjectcs.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToBorder.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToCenter.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/MoveableBus.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/MovementDirection.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs create mode 100644 TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs diff --git a/TrolleybusProject/TrolleybusProject/DirectionType.cs b/TrolleybusProject/TrolleybusProject/DirectionType.cs index 39d3b0f..81b2b42 100644 --- a/TrolleybusProject/TrolleybusProject/DirectionType.cs +++ b/TrolleybusProject/TrolleybusProject/DirectionType.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace TrolleybusProject.Drawnings; public enum DirectionType -{ +{ Unknow=-1, /// /// Вверх /// diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs index 785995e..3a60e8e 100644 --- a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs +++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs @@ -40,6 +40,24 @@ public class DrawningBus public readonly int _drawningBusHeight = 86; + /// + /// Координата X объекта + /// + public int? GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int? GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _drawningBusWidth; + /// + /// Высота объекта + /// + public int GetHeight => _drawningBusHeight; + + /// /// Конструктор пустой diff --git a/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs b/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs index 49c9e8d..0205489 100644 --- a/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs +++ b/TrolleybusProject/TrolleybusProject/FormTrolleybus.Designer.cs @@ -35,6 +35,8 @@ buttonUp = new Button(); buttonDown = new Button(); buttonCreateBus = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit(); SuspendLayout(); // @@ -117,11 +119,33 @@ buttonCreateBus.UseVisualStyleBackColor = true; buttonCreateBus.Click += buttonCreateBus_Click; // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); + comboBoxStrategy.Location = new Point(1079, 29); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(182, 33); + comboBoxStrategy.TabIndex = 7; + // + // buttonStrategyStep + // + buttonStrategyStep.Location = new Point(1149, 68); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(112, 34); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += buttonStrategyStep_Click; + // // FormTrolleybus // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1273, 561); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateBus); Controls.Add(buttonDown); Controls.Add(buttonUp); @@ -144,5 +168,7 @@ private Button buttonUp; private Button buttonDown; private Button buttonCreateBus; + private ComboBox comboBoxStrategy; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs b/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs index bfa8d9e..644be9c 100644 --- a/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs +++ b/TrolleybusProject/TrolleybusProject/FormTrolleybus.cs @@ -8,16 +8,19 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using TrolleybusProject.Drawnings; +using TrolleybusProject.MovementStrategy; namespace TrolleybusProject { public partial class FormTrolleybus : Form { private DrawningBus? _drawningBus; + + private AbstractractStrategy? _strategy; public FormTrolleybus() { InitializeComponent(); - + _strategy = null; } @@ -73,8 +76,9 @@ namespace TrolleybusProject pictureBoxTrolleybus.Height); _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - + _strategy = null; + comboBoxStrategy.Enabled = true; + Draw(); } @@ -89,6 +93,11 @@ namespace TrolleybusProject CreateObject(nameof(DrawningTrolleybus)); } + + + + + private void buttonMove_Click(object sender, EventArgs e) { if (_drawningBus == null) @@ -122,10 +131,55 @@ namespace TrolleybusProject } + + + + + private void buttonCreateBus_Click(object sender, EventArgs e) { CreateObject(nameof(DrawningBus)); } + + + + + + private void buttonStrategyStep_Click(object sender, EventArgs e) + { + if (_drawningBus == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) + { + return; + } + _strategy.SetData(new MoveableBus(_drawningBus), + pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + } + if (_strategy == null) + { + return; + } + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + if (_strategy.GetStatus() == StrategyStatus.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } + } -} \ No newline at end of file +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/AbstractractStrategy.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/AbstractractStrategy.cs new file mode 100644 index 0000000..a71e8f9 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/AbstractractStrategy.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy; + +public abstract class AbstractractStrategy +{ + /// + /// Перемещаемый объект + /// + private IMoveableObjectcs? _moveableObject; + /// + /// Статус перемещения + /// + private StrategyStatus _state = StrategyStatus.NotInit; + /// + /// Ширина поля + /// + protected int FieldWidth { get; private set; } + /// + /// Высота поля + /// + protected int FieldHeight { get; private set; } + /// + /// Статус перемещения + /// + public StrategyStatus GetStatus() { return _state; } + /// + /// Установка данных + /// + /// Перемещаемый объект + /// Ширина поля + /// Высота поля + public void SetData(IMoveableObjectcs moveableObject, int width, int height) + { + if (moveableObject == null) + { + _state = StrategyStatus.NotInit; + return; + } + _state = StrategyStatus.InProgress; + _moveableObject = moveableObject; + FieldWidth = width; + FieldHeight = height; + } + /// + /// Шаг перемещения + /// + public void MakeStep() + { + if (_state != StrategyStatus.InProgress) + { + return; + } + if (IsTargetDestinaion()) + { + _state = StrategyStatus.Finish; + return; + } + MoveToTarget(); + } + /// + /// Перемещение влево + /// + /// Результат перемещения (true - удалось переместиться, false -неудача) +protected bool MoveLeft() => MoveTo(MovementDirection.Left); + /// + /// Перемещение вправо + /// + /// Результат перемещения (true - удалось переместиться, false -неудача) +protected bool MoveRight() => MoveTo(MovementDirection.Right); + /// + /// Перемещение вверх + /// + /// Результат перемещения (true - удалось переместиться, false -неудача) +protected bool MoveUp() => MoveTo(MovementDirection.Up); + /// + /// Перемещение вниз + /// + /// Результат перемещения (true - удалось переместиться, false -неудача) +protected bool MoveDown() => MoveTo(MovementDirection.Down); + /// + /// Параметры объекта + /// + protected ObjectParameters? GetObjectParameters => + _moveableObject?.GetObjectPosition; + /// + /// Шаг объекта + /// + /// + protected int? GetStep() + { + if (_state != StrategyStatus.InProgress) + { + return null; + } + return _moveableObject?.GetStep; + } + /// + /// Перемещение к цели + /// + protected abstract void MoveToTarget(); + /// + /// Достигнута ли цель + /// + /// + protected abstract bool IsTargetDestinaion(); + /// + /// Попытка перемещения в требуемом направлении + /// + /// Направление + /// Результат попытки (true - удалось переместиться, false -неудача) +private bool MoveTo(MovementDirection movementDirection) + { + if (_state != StrategyStatus.InProgress) + { + return false; + } + return _moveableObject?.TryMoveObject(movementDirection) ?? false; + } + + + +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/IMoveableObjectcs.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/IMoveableObjectcs.cs new file mode 100644 index 0000000..ba63901 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/IMoveableObjectcs.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy; + +public interface IMoveableObjectcs +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + /// + /// Шаг объекта + /// + int GetStep { get; } + /// + /// Попытка переместить объект в указанном направлении + /// + /// Направление + /// true - объект перемещен, false - перемещение невозможно +bool TryMoveObject(MovementDirection direction); + + + + + +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToBorder.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..655d0be --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy; + +public class MoveToBorder: AbstractractStrategy +{ + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + + return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth && + objParams.DownBorder <= FieldHeight && + objParams.DownBorder + GetStep() >= FieldHeight; + } + + protected override void MoveToTarget() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + + int diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + + int diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToCenter.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..40df469 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy; + +public class MoveToCenter : AbstractractStrategy +{ + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 + && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && + objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 + && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; + } + protected override void MoveToTarget() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } + +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveableBus.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveableBus.cs new file mode 100644 index 0000000..a69c00d --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/MoveableBus.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TrolleybusProject.Drawnings; + +namespace TrolleybusProject.MovementStrategy; + +public class MoveableBus : IMoveableObjectcs +{ + /// + /// Поле-объект класса DrawningBus или его наследника + /// + private readonly DrawningBus? _bus = null; + /// + /// Конструктор + /// + /// Объект класса DrawningBus + public MoveableBus(DrawningBus bus) + { + _bus = bus; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_bus == null || _bus.EntityBus == null || + !_bus.GetPosX.HasValue || !_bus.GetPosY.HasValue) + { + return null; + } + return new ObjectParameters(_bus.GetPosX.Value, + _bus.GetPosY.Value, _bus.GetWidth, _bus.GetHeight); + } + } + public int GetStep => (int)(_bus?.EntityBus?.Step ?? 0); + public bool TryMoveObject(MovementDirection direction) + { + if (_bus == null || _bus.EntityBus == null) + { + return false; + } + return _bus.MoveTransport(GetDirectionType(direction)); + } + /// + /// Конвертация из MovementDirection в DirectionType + /// + /// MovementDirection + /// DirectionType + private static DirectionType GetDirectionType(MovementDirection direction) + { + return direction switch + { + MovementDirection.Left => DirectionType.Left, + MovementDirection.Right => DirectionType.Right, + MovementDirection.Up => DirectionType.Up, + MovementDirection.Down => DirectionType.Down, + _=> DirectionType.Unknow, + }; + } +} + + + + + + + + + + diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/MovementDirection.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..ddce05a --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/MovementDirection.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy; + +public enum MovementDirection +{ + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..69bdae0 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy +{ + public class ObjectParameters + { + /// + /// Координата X + /// + private readonly int _x; + /// + /// Координата Y + /// + private readonly int _y; + /// + /// Ширина объекта + /// + private readonly int _width; + /// + /// Высота объекта + /// + private readonly int _height; + /// + /// Левая граница + /// + public int LeftBorder => _x; + /// + /// Верхняя граница + /// + public int TopBorder => _y; + /// + /// Правая граница + /// + public int RightBorder => _x + _width; + /// + /// Нижняя граница + /// + public int DownBorder => _y + _height; + /// + /// Середина объекта + /// + public int ObjectMiddleHorizontal => _x + _width / 2; + /// + /// Середина объекта + /// + public int ObjectMiddleVertical => _y + _height / 2; + /// + /// Конструктор + /// + /// Координата X + /// Координата Y + /// Ширина объекта + /// Высота объекта + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } + + + + + } +} diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..5c85260 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrolleybusProject.MovementStrategy; + +public enum StrategyStatus +{ + /// + /// Все готово к началу + /// + NotInit, + /// + /// Выполняется + /// + InProgress, + /// + /// Завершено + /// + Finish + + +} -- 2.25.1 From 8e476617e17c83212f35565f60a88fff8641dde1 Mon Sep 17 00:00:00 2001 From: Anastasia Yazykova Date: Wed, 3 Apr 2024 00:02:15 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drawnings/DrawningBus.cs | 72 +++++++++---------- .../Drawnings/DrawningTrolleybus.cs | 32 +++++++-- 2 files changed, 63 insertions(+), 41 deletions(-) diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs index 3a60e8e..590f45d 100644 --- a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs +++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs @@ -266,49 +266,49 @@ public class DrawningBus Brush brushBodyColor = new SolidBrush(EntityBus.BodyColor); //троллейбус границы - g.DrawEllipse(pen, _startPosX.Value + 27, _startPosY.Value + - 64, 20, 20); - g.DrawEllipse(pen, _startPosX.Value + 109, _startPosY.Value + - 64, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 22, _startPosY.Value + + 42, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 104, _startPosY.Value + + 42, 20, 20); - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + - 30, 140, 41); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + + 8, 140, 41); //троллейбус - g.FillRectangle(brushBodyColor, _startPosX.Value + 10, _startPosY.Value + - 30, 140, 41); - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + - 30, 140, 41); + g.FillRectangle(brushBodyColor, _startPosX.Value + 5, _startPosY.Value + + 8, 140, 41); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + + 8, 140, 41); //дверь - g.DrawRectangle(pen, _startPosX.Value + 57, _startPosY.Value + - 40, 24, 31); + g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + + 18, 24, 31); //окна Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillEllipse(brBlue, _startPosX.Value + 13, _startPosY.Value + - 34, 15, 20); + g.FillEllipse(brBlue, _startPosX.Value + 8, _startPosY.Value + + 12, 15, 20); - g.FillEllipse(brBlue, _startPosX.Value + 38, _startPosY.Value + - 34, 15, 20); + g.FillEllipse(brBlue, _startPosX.Value + 33, _startPosY.Value + + 12, 15, 20); - g.FillEllipse(brBlue, _startPosX.Value + 85, _startPosY.Value + - 34, 15, 20); - g.FillEllipse(brBlue, _startPosX.Value + 102, _startPosY.Value + - 34, 15, 20); - g.FillEllipse(brBlue, _startPosX.Value + 118, _startPosY.Value + - 34, 15, 20); - g.FillEllipse(brBlue, _startPosX.Value + 134, _startPosY.Value + - 34, 15, 20); + g.FillEllipse(brBlue, _startPosX.Value + 80, _startPosY.Value + + 12, 15, 20); + g.FillEllipse(brBlue, _startPosX.Value + 97, _startPosY.Value + + 12, 15, 20); + g.FillEllipse(brBlue, _startPosX.Value + 113, _startPosY.Value + + 12, 15, 20); + g.FillEllipse(brBlue, _startPosX.Value + 129, _startPosY.Value + + 12, 15, 20); @@ -318,21 +318,21 @@ public class DrawningBus - g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + - 34, 15, 20); + g.DrawEllipse(pen, _startPosX.Value + 8, _startPosY.Value + + 12, 15, 20); - g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + - 34, 15, 20); + g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + + 12, 15, 20); - g.DrawEllipse(pen, _startPosX.Value + 85, _startPosY.Value + - 34, 15, 20); - g.DrawEllipse(pen, _startPosX.Value + 102, _startPosY.Value + - 34, 15, 20); - g.DrawEllipse(pen, _startPosX.Value + 118, _startPosY.Value + - 34, 15, 20); - g.DrawEllipse(pen, _startPosX.Value + 134, _startPosY.Value + - 34, 15, 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + + 12, 15, 20); + g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + + 12, 15, 20); + g.DrawEllipse(pen, _startPosX.Value + 113, _startPosY.Value + + 12, 15, 20); + g.DrawEllipse(pen, _startPosX.Value + 129, _startPosY.Value + + 12, 15, 20); diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs index 232c600..26a0011 100644 --- a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs +++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs @@ -46,6 +46,15 @@ public class DrawningTrolleybus:DrawningBus + _startPosX += 5; + _startPosY += 22; + + base.DrawTransport(g); + _startPosX -= 5; + _startPosY -= 22; + + + if (trolleybus.Otsek) { @@ -62,11 +71,7 @@ public class DrawningTrolleybus:DrawningBus - _startPosX += 22; - _startPosY += 15; - base.DrawTransport(g); - _startPosX -= 22; - _startPosY -= 15; + if (trolleybus.Doors) @@ -77,6 +82,23 @@ public class DrawningTrolleybus:DrawningBus } + + + + + //рога + + if (trolleybus.Roga) + { + g.DrawLine(addpen, _startPosX.Value + 42, _startPosY.Value + 7, + _startPosX.Value + 124, _startPosY.Value + 29); + g.DrawLine(addpen, _startPosX.Value + 62, _startPosY.Value + 2, + _startPosX.Value + 124, _startPosY.Value + 29); + + + } + + } -- 2.25.1