diff --git a/ProjectTrolleybus/ProjectTrolleybus/DirectionType.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs similarity index 90% rename from ProjectTrolleybus/ProjectTrolleybus/DirectionType.cs rename to ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs index 3d82936..be67327 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/DirectionType.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectTrolleybus; +namespace ProjectTrolleybus.Drawnings; /// /// Направление перемещения diff --git a/ProjectTrolleybus/ProjectTrolleybus/DrawningTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs similarity index 51% rename from ProjectTrolleybus/ProjectTrolleybus/DrawningTrolleybus.cs rename to ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs index adf1948..64f0ccb 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/DrawningTrolleybus.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs @@ -1,14 +1,18 @@ -namespace ProjectTrolleybus; +using ProjectTrolleybus.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawningTrolleybus +namespace ProjectTrolleybus.Drawnings; + +public class DrawningTrolleyB { /// /// Класс-сущность /// - public EntityTrolleybus? EntityTrolleybus { get; private set; } + public EntityTrolleyB? EntityTrolleyB { get; protected set; } /// /// Ширина окна @@ -23,42 +27,57 @@ public class DrawningTrolleybus /// /// Левая координата прорисовки транспорта /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя координата прорисовки транспорта /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки транспорта /// - private readonly int _drawningVehicleWidth = 100; + private readonly int _drawningVehicleWidth = 90; /// /// Высота прорисовки транспорта /// - private readonly int _drawningVehicleHeight = 48; + private readonly int _drawningVehicleHeight = 33; /// - /// Инициализация свойств + /// Пустой конструктор /// - /// - /// - /// - /// - /// - /// - /// - public void Init(EntityTrolleybus _Tr) + private DrawningTrolleyB() { - EntityTrolleybus = _Tr; _pictureHeight = null; _pictureWidth = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningTrolleyB(int speed, double weight, Color bodyColor) : this() + { + EntityTrolleyB = new EntityTrolleyB(speed, weight, bodyColor); + } + + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки транспорта + /// Высота прорисовки транспорта + protected DrawningTrolleyB(int drawningVehicleWidth, int drawningVehicleHeight) : this() + { + _drawningVehicleWidth = drawningVehicleWidth; + _drawningVehicleHeight = drawningVehicleHeight; + } + /// /// Установка границ поля /// @@ -102,7 +121,6 @@ public class DrawningTrolleybus { return; } - //TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы //то надо изменить координаты, чтобы он оставался в этих границах if (x + _drawningVehicleWidth > _pictureWidth) { @@ -127,7 +145,7 @@ public class DrawningTrolleybus /// public bool MoveVehicle(DirectionType direction) { - if (EntityTrolleybus == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityTrolleyB == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } @@ -136,48 +154,48 @@ public class DrawningTrolleybus { // влево case DirectionType.Left: - if (_startPosX.Value - EntityTrolleybus.Step > 0) + if (_startPosX.Value - EntityTrolleyB.Step > 0) { - _startPosX -= (int)EntityTrolleybus.Step; + _startPosX -= (int)EntityTrolleyB.Step; } return true; // вверх case DirectionType.Up: - if (_startPosY.Value - EntityTrolleybus.Step > 0) + if (_startPosY.Value - EntityTrolleyB.Step > 0) { - _startPosY -= (int)EntityTrolleybus.Step; + _startPosY -= (int)EntityTrolleyB.Step; } return true; - // вправо + // вправо case DirectionType.Right: { - if (_startPosX.Value + _drawningVehicleWidth + EntityTrolleybus.Step < _pictureWidth) + if (_startPosX.Value + _drawningVehicleWidth + EntityTrolleyB.Step < _pictureWidth) { - _startPosX += (int)EntityTrolleybus.Step; + _startPosX += (int)EntityTrolleyB.Step; } } return true; - // вниз + // вниз case DirectionType.Down: { - if (_startPosY.Value + _drawningVehicleHeight + EntityTrolleybus.Step < _pictureHeight) + if (_startPosY.Value + _drawningVehicleHeight + EntityTrolleyB.Step < _pictureHeight) { - _startPosY += (int)EntityTrolleybus.Step; + _startPosY += (int)EntityTrolleyB.Step; } - } + } return true; default: return false; } - } - + } + /// /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityTrolleybus == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityTrolleyB == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } @@ -186,68 +204,44 @@ public class DrawningTrolleybus //Колёса pen.Width = 2; - g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 36, 12, 12); - g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 36, 12, 12); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 21, 12, 12); + g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 21, 12, 12); pen.Width = 1; Brush brBlackWheel = new SolidBrush(Color.Black); - g.FillEllipse(brBlackWheel, _startPosX.Value + 20, _startPosY.Value + 36, 12, 12); - g.FillEllipse(brBlackWheel, _startPosX.Value + 80, _startPosY.Value + 36, 12, 12); + g.FillEllipse(brBlackWheel, _startPosX.Value + 10, _startPosY.Value + 21, 12, 12); + g.FillEllipse(brBlackWheel, _startPosX.Value + 70, _startPosY.Value + 21, 12, 12); Brush brYelWheel = new SolidBrush(Color.Goldenrod); - g.FillEllipse(brYelWheel, _startPosX.Value + 22, _startPosY.Value + 38, 8, 8); - g.FillEllipse(brYelWheel, _startPosX.Value + 82, _startPosY.Value + 38, 8, 8); + g.FillEllipse(brYelWheel, _startPosX.Value + 12, _startPosY.Value + 23, 8, 8); + g.FillEllipse(brYelWheel, _startPosX.Value + 72, _startPosY.Value + 23, 8, 8); //Кузов - Brush br = new SolidBrush(EntityTrolleybus.BodyColor); - g.FillRectangle(br, _startPosX.Value + 11, _startPosY.Value + 16, 89, 24); + Brush br = new SolidBrush(EntityTrolleyB.BodyColor); + g.FillRectangle(br, _startPosX.Value + 1, _startPosY.Value + 1, 89, 24); //Границы Автомобиля - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 90, 25); - g.DrawRectangle(pen, _startPosX.Value + 36, _startPosY.Value + 25, 10, 15); - g.DrawRectangle(pen, _startPosX.Value + 88, _startPosY.Value + 19, 12, 12); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 90, 25); + g.DrawRectangle(pen, _startPosX.Value + 26, _startPosY.Value + 10, 10, 15); + g.DrawRectangle(pen, _startPosX.Value + 78, _startPosY.Value + 4, 12, 12); pen.Width = 2; - g.DrawEllipse(pen, _startPosX.Value + 12, _startPosY.Value + 20, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 24, _startPosY.Value + 20, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 20, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 20, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 74, _startPosY.Value + 20, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 2, _startPosY.Value + 5, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 14, _startPosY.Value + 5, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 5, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 64, _startPosY.Value + 5, 8, 10); pen.Width = 1; //Стекла и кабина Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillRectangle(brBlue, _startPosX.Value + 89, _startPosY.Value + 20, 11, 11); - g.FillEllipse(brBlue, _startPosX.Value + 12, _startPosY.Value + 20, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 24, _startPosY.Value + 20, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 50, _startPosY.Value + 20, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 62, _startPosY.Value + 20, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 74, _startPosY.Value + 20, 8, 10); + g.FillRectangle(brBlue, _startPosX.Value + 79, _startPosY.Value + 5, 11, 11); + g.FillEllipse(brBlue, _startPosX.Value + 2, _startPosY.Value + 5, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 14, _startPosY.Value + 5, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 40, _startPosY.Value + 5, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 52, _startPosY.Value + 5, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 64, _startPosY.Value + 5, 8, 10); //Дверь Brush brBlack = new SolidBrush(Color.LightGray); - g.FillRectangle(brBlack, _startPosX.Value + 37, _startPosY.Value + 26, 9, 14); - - Brush additBrush = new SolidBrush(EntityTrolleybus.AdditionalColor); - - // "Рога" для проводов - if (EntityTrolleybus.Horns) - { - pen.Width = 2; - g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 15, _startPosX.Value + 52, _startPosY.Value + 2); - pen.Width = 1; - g.DrawRectangle(pen, _startPosX.Value + 34, _startPosY.Value, 20, 5); - - g.FillRectangle(additBrush, _startPosX.Value + 35, _startPosY.Value + 1, 19, 4); - - } - - // Отсек под батареи - if (EntityTrolleybus.BatteryCompartment) - { - g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 24, 10, 12); - - g.FillRectangle(additBrush, _startPosX.Value + 1, _startPosY.Value + 25, 9, 11); - } + g.FillRectangle(brBlack, _startPosX.Value + 27, _startPosY.Value + 11, 9, 14); } - - } diff --git a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs new file mode 100644 index 0000000..2c09a7f --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs @@ -0,0 +1,64 @@ +using ProjectTrolleybus.Entities; +using System.Drawing; + +namespace ProjectTrolleybus.Drawnings; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningTrolleybus : DrawningTrolleyB +{ + /// + /// Конструктор + /// + /// + /// + /// + /// + /// + /// + /// + public DrawningTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, bool batteryCompartment, bool horns) : base(100, 48) + { + EntityTrolleyB = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, batteryCompartment, horns); + } + + public override void DrawTransport(Graphics g) + { + + if (EntityTrolleyB == null || EntityTrolleyB is not EntityTrolleybus trolleybus || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additBrush = new SolidBrush(trolleybus.AdditionalColor); + + // "Рога" для проводов + if (trolleybus.Horns) + { + pen.Width = 2; + g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 15, _startPosX.Value + 52, _startPosY.Value + 2); + pen.Width = 1; + g.DrawRectangle(pen, _startPosX.Value + 34, _startPosY.Value, 20, 5); + + g.FillRectangle(additBrush, _startPosX.Value + 35, _startPosY.Value + 1, 19, 4); + + } + + // Отсек под батареи + if (trolleybus .BatteryCompartment) + { + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 24, 10, 12); + + g.FillRectangle(additBrush, _startPosX.Value + 1, _startPosY.Value + 25, 9, 11); + } + + _startPosX += 10; + _startPosY += 15; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 15; + } + +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/Entities/EntityTrolleyB.cs b/ProjectTrolleybus/ProjectTrolleybus/Entities/EntityTrolleyB.cs new file mode 100644 index 0000000..caba453 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/Entities/EntityTrolleyB.cs @@ -0,0 +1,41 @@ +namespace ProjectTrolleybus.Entities; + +/// +/// Класс-Сущность "Троллейбус" +/// +public class EntityTrolleyB +{ + /// + /// Скорость + /// + 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 EntityTrolleyB(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/EntityTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/Entities/EntityTrolleybus.cs similarity index 58% rename from ProjectTrolleybus/ProjectTrolleybus/EntityTrolleybus.cs rename to ProjectTrolleybus/ProjectTrolleybus/Entities/EntityTrolleybus.cs index 20e254b..aaa49ca 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/EntityTrolleybus.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Entities/EntityTrolleybus.cs @@ -1,24 +1,9 @@ -namespace ProjectTrolleybus; +namespace ProjectTrolleybus.Entities; /// /// Класс-Сущность "Троллейбус" /// -public class EntityTrolleybus +public class EntityTrolleybus : EntityTrolleyB { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет /// @@ -27,15 +12,13 @@ public class EntityTrolleybus /// /// Признак (опция) наличия отсека под батареи /// - public bool BatteryCompartment { get; private set; } + public bool BatteryCompartment { get; private set; } /// /// Признак (опция) наличия "Рогов" для подключения проводов /// public bool Horns { get; private set; } - public double Step => Speed * 100 / Weight; - /// /// /// @@ -45,11 +28,8 @@ public class EntityTrolleybus /// /// /// - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool batteryCompartment, bool horns) + public EntityTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, bool batteryCompartment, bool horns) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; BatteryCompartment = batteryCompartment; Horns = horns; diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs index 11c468d..f6ed86c 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs @@ -34,6 +34,7 @@ buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); + buttonCreateTrolleyB = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit(); SuspendLayout(); // @@ -51,9 +52,9 @@ buttonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateTrolleybus.Location = new Point(22, 406); buttonCreateTrolleybus.Name = "buttonCreateTrolleybus"; - buttonCreateTrolleybus.Size = new Size(75, 23); + buttonCreateTrolleybus.Size = new Size(204, 23); buttonCreateTrolleybus.TabIndex = 1; - buttonCreateTrolleybus.Text = "Создать"; + buttonCreateTrolleybus.Text = "Создать улучшенный троллейбус"; buttonCreateTrolleybus.UseVisualStyleBackColor = true; buttonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click; // @@ -105,11 +106,23 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // + // buttonCreateTrolleyB + // + buttonCreateTrolleyB.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateTrolleyB.Location = new Point(246, 406); + buttonCreateTrolleyB.Name = "buttonCreateTrolleyB"; + buttonCreateTrolleyB.Size = new Size(130, 23); + buttonCreateTrolleyB.TabIndex = 6; + buttonCreateTrolleyB.Text = "Создать троллейбус"; + buttonCreateTrolleyB.UseVisualStyleBackColor = true; + buttonCreateTrolleyB.Click += ButtonCreateTrolleyB_Click; + // // FormTrolleybus // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(buttonCreateTrolleyB); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); @@ -130,5 +143,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; + private Button buttonCreateTrolleyB; } } \ No newline at end of file diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs index 713edcd..fe80fdb 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs @@ -1,74 +1,97 @@ -namespace ProjectTrolleybus +using ProjectTrolleybus.Drawnings; +using ProjectTrolleybus.Entities; + +namespace ProjectTrolleybus; + +public partial class FormTrolleybus : Form { - public partial class FormTrolleybus : Form + private DrawningTrolleyB? _drawningTrolleyB; + + public FormTrolleybus() { - private DrawningTrolleybus? _drawningTrolleybus; + InitializeComponent(); + } - EntityTrolleybus? _Trolleybus; + private void Draw() + { + Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningTrolleyB.DrawTransport(gr); + pictureBoxTrolleybus.Image = bmp; + } - public FormTrolleybus() + private void CreateObject(string type) + { + Random random = new(); + switch (type) { - InitializeComponent(); - } - - private void Draw() - { - Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawningTrolleybus.DrawTransport(gr); - pictureBoxTrolleybus.Image = bmp; - } - - private void ButtonCreateTrolleybus_Click(object sender, EventArgs e) - { - - Random random = new(); - _Trolleybus = new EntityTrolleybus(); - _Trolleybus.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))); - _drawningTrolleybus = new DrawningTrolleybus(); - _drawningTrolleybus.Init(_Trolleybus); - //_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))); - _drawningTrolleybus.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); - _drawningTrolleybus.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); - Draw(); - - } - - private void ButtonMove_Click(object sender, EventArgs e) - { - if (_drawningTrolleybus == null) - { + case nameof(DrawningTrolleyB): + _drawningTrolleyB = new DrawningTrolleyB(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): + _drawningTrolleyB = 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))); + break; + default: return; - } + } - string name = ((Button)sender)?.Name ?? string.Empty; - bool result = false; - switch (name) - { - case "buttonUp": - result = _drawningTrolleybus.MoveVehicle(DirectionType.Up); - break; - case "buttonDown": - result = _drawningTrolleybus.MoveVehicle(DirectionType.Down); - break; - case "buttonLeft": - result = _drawningTrolleybus.MoveVehicle(DirectionType.Left); - break; - case "buttonRight": - result = _drawningTrolleybus.MoveVehicle(DirectionType.Right); - break; - } + _drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + _drawningTrolleyB.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + Draw(); + } - if (result) - { - Draw(); - } + /// + /// Обработка нажатия создать улучшеный троллейбус + /// + /// + /// + private void ButtonCreateTrolleybus_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningTrolleybus)); + } + + /// + /// Обработка нажатия создать троллейбус + /// + /// + /// + private void ButtonCreateTrolleyB_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningTrolleyB)); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningTrolleyB == null) + { + return; + } + + string name = ((Button)sender)?.Name ?? string.Empty; + bool result = false; + switch (name) + { + case "buttonUp": + result = _drawningTrolleyB.MoveVehicle(DirectionType.Up); + break; + case "buttonDown": + result = _drawningTrolleyB.MoveVehicle(DirectionType.Down); + break; + case "buttonLeft": + result = _drawningTrolleyB.MoveVehicle(DirectionType.Left); + break; + case "buttonRight": + result = _drawningTrolleyB.MoveVehicle(DirectionType.Right); + break; + } + + if (result) + { + Draw(); } } }