Добавление родителей и ввод конструкторов

This commit is contained in:
Anya 2024-04-11 11:18:53 +04:00
parent d8499a8db4
commit b956941018
7 changed files with 268 additions and 161 deletions

View File

@ -1,10 +1,8 @@
using System; namespace ProjectBus. Drawings;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBus; /// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType public enum DirectionType
{ {

View File

@ -0,0 +1,91 @@
using ProjectBus.Entities;
using System.Drawing;
namespace ProjectBus.Drawnings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningBus : DrawningSimpleBus
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="additionalCompartment">Признак наличия дополнительного отсека</param>
/// <param name="accordion"">Признак наличия гармошки</param>
public DrawningBus(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalCompartment, bool accordion) : base(310,52)
{
EntitySimpleBus = new EntityBus(speed, weight, bodyColor, additionalColor, additionalCompartment, accordion);
}
public override void DrawTransport(Graphics g)
{
if (EntitySimpleBus == null || EntitySimpleBus is not EntityBus bus || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush= new SolidBrush(bus.AdditionalColor);
//доп отсек
if (bus.AdditionalCompartment)
{
//корпус
g.DrawRectangle(pen, _startPosX.Value + 204, _startPosY.Value - 1, 105, 50);
g.DrawRectangle(pen, _startPosX.Value + 205, _startPosY.Value, 105, 50);
g.FillRectangle(additionalBrush, _startPosX.Value + 205, _startPosY.Value, 105, 50);
//окна
g.FillEllipse(additionalBrush, _startPosX.Value + 247, _startPosY.Value + 6, 16, 25);
g.FillEllipse(additionalBrush, _startPosX.Value + 275, _startPosY.Value + 6, 16, 25);
g.DrawEllipse(pen, _startPosX.Value + 247, _startPosY.Value + 6, 16, 25);
g.DrawEllipse(pen, _startPosX.Value + 275, _startPosY.Value + 6, 16, 25);
//дверь
g.FillRectangle(additionalBrush, _startPosX.Value + 215, _startPosY.Value + 10, 20, 40);
g.DrawRectangle(pen, _startPosX.Value + 215, _startPosY.Value + 10, 20, 40);
//колеса
g.FillEllipse(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 40, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 250, _startPosY.Value + 40, 20, 20);
}
_startPosX += 0;
_startPosY += 0;
base.DrawTransport(g);
//гармошка
if (bus.Accordion)
{
Brush brGray = new SolidBrush(Color.LightGray);
g.FillRectangle(brGray, _startPosX.Value + 175, _startPosY.Value + 4, 30, 42);
g.FillRectangle(brGray, _startPosX.Value + 180, _startPosY.Value + 4, 5, 42);
g.FillRectangle(brGray, _startPosX.Value + 185, _startPosY.Value + 4, 5, 42);
g.FillRectangle(brGray, _startPosX.Value + 190, _startPosY.Value + 4, 5, 42);
g.FillRectangle(brGray, _startPosX.Value + 195, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 175, _startPosY.Value + 4, 30, 42);
g.DrawRectangle(pen, _startPosX.Value + 180, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 185, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 190, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 195, _startPosY.Value + 4, 5, 42);
}
}
}

View File

@ -1,15 +1,14 @@
namespace ProjectBus; using ProjectBus.Drawings;
using ProjectBus.Entities;
/// <summary> namespace ProjectBus.Drawnings;
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingBus public class DrawningSimpleBus
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityBus? EntityBus { get; private set; } public EntitySimpleBus? EntitySimpleBus { get; protected set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
@ -24,16 +23,16 @@ public class DrawingBus
/// <summary> /// <summary>
/// Левая координата прорисовки автобуса /// Левая координата прорисовки автобуса
/// </summary> /// </summary>
private int? _startPosX; protected int? _startPosX;
/// <summary> /// <summary>
/// Верхняя кооридната прорисовки автобуса /// Верхняя кооридната прорисовки автобуса
/// </summary> /// </summary>
private int? _startPosY; protected int? _startPosY;
/// <summary> /// <summary>
/// /// Ширина прорисовки автобуса /// Ширина прорисовки автобуса
/// /// </summary> /// /// </summary>
private readonly int _drawningBusWidth = 310; private readonly int _drawningBusWidth = 310;
@ -43,22 +42,37 @@ public class DrawingBus
private readonly int _drawningBusHeight = 52; private readonly int _drawningBusHeight = 52;
/// <summary> /// <summary>
/// Инициализация свойств /// Пустой конструктор
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> private DrawningSimpleBus()
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="additionalCompartment">Признак наличия дополнительного отсека</param>
/// <param name="accordion"">Признак наличия гармошки</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalCompartment, bool accordion, bool v)
{ {
EntityBus = new EntityBus();
EntityBus.Init(speed, weight, bodyColor, additionalColor, additionalCompartment, accordion);
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
_startPosY = null; _startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningSimpleBus(int speed, double weight, Color bodyColor) : this()
{
EntitySimpleBus = new EntitySimpleBus(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="drawningBusWidth">Ширина прорисовки автобуса</param>
/// <param name="drawningBusHeight">Высота прорисовки автобуса</param>
protected DrawningSimpleBus(int drawningBusWidth, int drawningBusHeight) : this()
{
_drawningBusWidth = drawningBusWidth;
_drawningBusHeight= drawningBusHeight;
} }
/// <summary> /// <summary>
@ -67,16 +81,6 @@ public class DrawingBus
/// <param name="width">Ширина поля</param> /// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param> /// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns> /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
//public bool SetPictureSize(int width, int height)
//{
// // TODO проверка, что объект "влезает" в размеры поля
// // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
// _pictureWidth = width;
// _pictureHeight = height;
// return true;
//}
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
if (width >= _drawningBusWidth && height >= _drawningBusWidth) if (width >= _drawningBusWidth && height >= _drawningBusWidth)
@ -148,7 +152,7 @@ public class DrawingBus
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns> /// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction) public bool MoveTransport(DirectionType direction)
{ {
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntitySimpleBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return false; return false;
} }
@ -157,30 +161,30 @@ public class DrawingBus
{ {
//влево //влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX.Value - EntityBus.Step > 0) if (_startPosX.Value - EntitySimpleBus.Step > 0)
{ {
_startPosX -= (int)EntityBus.Step; _startPosX -= (int)EntitySimpleBus.Step;
} }
return true; return true;
//вверх //вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY.Value - EntityBus.Step > 0) if (_startPosY.Value - EntitySimpleBus.Step > 0)
{ {
_startPosY -= (int)EntityBus.Step; _startPosY -= (int)EntitySimpleBus.Step;
} }
return true; return true;
// вправо // вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX.Value + EntityBus.Step <_pictureWidth - _drawningBusWidth) if (_startPosX.Value + EntitySimpleBus.Step <_pictureWidth - _drawningBusWidth)
{ {
_startPosX += (int)EntityBus.Step; _startPosX += (int)EntitySimpleBus.Step;
} }
return true; return true;
//вниз //вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY.Value + EntityBus.Step < _pictureHeight - _drawningBusHeight) if (_startPosY.Value + EntitySimpleBus.Step < _pictureHeight - _drawningBusHeight)
{ {
_startPosY += (int)EntityBus.Step; _startPosY += (int)EntitySimpleBus.Step;
} }
return true; return true;
default: default:
@ -192,15 +196,15 @@ public class DrawingBus
/// Прорисовка объекта /// Прорисовка объекта
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
public void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntitySimpleBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityBus.AdditionalColor);
//корпус автобуса //корпус автобуса
@ -209,7 +213,8 @@ public class DrawingBus
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value, 175, 50); g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value, 175, 50);
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value - 1, 175, 50); g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value - 1, 175, 50);
g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value, 175, 50); Brush br1 = new SolidBrush(EntitySimpleBus.BodyColor);
g.FillRectangle(br1, _startPosX.Value + 0, _startPosY.Value, 175, 50);
//окна //окна
@ -231,10 +236,10 @@ public class DrawingBus
//дверь //дверь
Brush br = new SolidBrush(EntityBus.BodyColor); Brush br2 = new SolidBrush(EntitySimpleBus.BodyColor);
g.DrawRectangle(pen, _startPosX.Value + 49, _startPosY.Value + 9, 20, 40); g.DrawRectangle(pen, _startPosX.Value + 49, _startPosY.Value + 9, 20, 40);
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40); g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40);
g.FillRectangle(br, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40); g.FillRectangle(br2, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40);
@ -247,60 +252,7 @@ public class DrawingBus
g.DrawEllipse(pen, _startPosX.Value + 115, _startPosY.Value + 40, 20, 20); g.DrawEllipse(pen, _startPosX.Value + 115, _startPosY.Value + 40, 20, 20);
//доп отсек
if (EntityBus.AdditionalCompartment)
{
//корпус
g.DrawRectangle(pen, _startPosX.Value + 204, _startPosY.Value - 1, 105, 50);
g.DrawRectangle(pen, _startPosX.Value + 205, _startPosY.Value, 105, 50);
g.FillRectangle(additionalBrush, _startPosX.Value + 205, _startPosY.Value, 105, 50);
//окна
g.FillEllipse(brBlue, _startPosX.Value + 247, _startPosY.Value + 6, 16, 25);
g.FillEllipse(brBlue, _startPosX.Value + 275, _startPosY.Value + 6, 16, 25);
g.DrawEllipse(pen, _startPosX.Value + 247, _startPosY.Value + 6, 16, 25);
g.DrawEllipse(pen, _startPosX.Value + 275, _startPosY.Value + 6, 16, 25);
//дверь
g.FillRectangle(br, _startPosX.Value + 215, _startPosY.Value + 10, 20, 40);
g.DrawRectangle(pen, _startPosX.Value + 215, _startPosY.Value + 10, 20, 40);
//колеса
g.FillEllipse(brGrey, _startPosX.Value + 250, _startPosY.Value + 40, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 250, _startPosY.Value + 40, 20, 20);
}
//гармошка
if (EntityBus.Accordion)
{
Brush brGray = new SolidBrush(Color.LightGray);
g.FillRectangle(brGray, _startPosX.Value + 175, _startPosY.Value + 4, 30, 42);
g.FillRectangle(brGray, _startPosX.Value + 180, _startPosY.Value + 4, 5, 42);
g.FillRectangle(brGray, _startPosX.Value + 185, _startPosY.Value + 4, 5, 42);
g.FillRectangle(brGray, _startPosX.Value + 190, _startPosY.Value + 4, 5, 42);
g.FillRectangle(brGray, _startPosX.Value + 195, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 175, _startPosY.Value + 4, 30, 42);
g.DrawRectangle(pen, _startPosX.Value + 180, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 185, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 190, _startPosY.Value + 4, 5, 42);
g.DrawRectangle(pen, _startPosX.Value + 195, _startPosY.Value + 4, 5, 42);
}
} }
} }

View File

@ -1,45 +1,27 @@
namespace ProjectBus; namespace ProjectBus.Entities;
/// <summary> /// <summary>
/// Класс-сущность "Автобус" /// Класс-сущность "Автобус"
/// </summary> /// </summary>
public class EntityBus public class EntityBus : EntitySimpleBus
{ {
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary> /// <summary>
/// Дополнительный цвет (для опциональных элементов) /// Дополнительный цвет (для опциональных элементов)
/// </summary> /// </summary>
///
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public Color BodyColor { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия контейнеров /// Признак (опция) наличия дополнительного отсека
/// </summary> /// </summary>
public bool AdditionalCompartment { get; private set; } public bool AdditionalCompartment { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия крана для разгрузки /// Признак (опция) наличия гармошки
/// </summary> /// </summary>
public bool Accordion { get; private set; } public bool Accordion { get; private set; }
/// <summary>
/// Шаг перемещения автобуса
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary> /// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля /// Инициализация полей объекта-класса спортивного автомобиля
/// </summary> /// </summary>
@ -49,12 +31,10 @@ public class EntityBus
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="additionalCompartment">Признак наличия дополнительного отсека</param> /// <param name="additionalCompartment">Признак наличия дополнительного отсека</param>
/// <param name="accordion">Признак наличия гармошки</param> /// <param name="accordion">Признак наличия гармошки</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalCompartment, bool accordion) public EntityBus(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalCompartment, bool accordion) : base(speed, weight, bodyColor)
{ {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
BodyColor = bodyColor;
AdditionalCompartment = additionalCompartment; AdditionalCompartment = additionalCompartment;
Accordion = accordion; Accordion = accordion;
} }

View File

@ -0,0 +1,42 @@
namespace ProjectBus.Entities;
/// <summary>
/// Класс-сущность "Автобус"
/// </summary>
public class EntitySimpleBus
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автобуса</param>
/// <param name="bodyColor">Основной цвет</param>
public EntitySimpleBus(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -34,6 +34,7 @@
buttonRight = new Button(); buttonRight = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonCreateSimpleBus = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -42,18 +43,18 @@
pictureBoxBus.Dock = DockStyle.Fill; pictureBoxBus.Dock = DockStyle.Fill;
pictureBoxBus.Location = new Point(0, 0); pictureBoxBus.Location = new Point(0, 0);
pictureBoxBus.Name = "pictureBoxBus"; pictureBoxBus.Name = "pictureBoxBus";
pictureBoxBus.Size = new Size(800, 450); pictureBoxBus.Size = new Size(1155, 557);
pictureBoxBus.TabIndex = 7; pictureBoxBus.TabIndex = 7;
pictureBoxBus.TabStop = false; pictureBoxBus.TabStop = false;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 392); buttonCreate.Location = new Point(12, 501);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(150, 46); buttonCreate.Size = new Size(410, 46);
buttonCreate.TabIndex = 2; buttonCreate.TabIndex = 2;
buttonCreate.Text = "Создать"; buttonCreate.Text = "Создать автобус с доп.отсеком";
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click; buttonCreate.Click += ButtonCreate_Click;
// //
@ -62,7 +63,7 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(626, 388); buttonLeft.Location = new Point(981, 495);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(50, 50); buttonLeft.Size = new Size(50, 50);
buttonLeft.TabIndex = 3; buttonLeft.TabIndex = 3;
@ -74,7 +75,7 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight; buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(738, 390); buttonRight.Location = new Point(1093, 497);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(50, 50); buttonRight.Size = new Size(50, 50);
buttonRight.TabIndex = 4; buttonRight.TabIndex = 4;
@ -86,7 +87,7 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp; buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(682, 332); buttonUp.Location = new Point(1037, 439);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(50, 50); buttonUp.Size = new Size(50, 50);
buttonUp.TabIndex = 5; buttonUp.TabIndex = 5;
@ -98,18 +99,30 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown; buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(682, 388); buttonDown.Location = new Point(1037, 495);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(50, 50); buttonDown.Size = new Size(50, 50);
buttonDown.TabIndex = 6; buttonDown.TabIndex = 6;
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; buttonDown.Click += ButtonMove_Click;
// //
// buttonCreateSimpleBus
//
buttonCreateSimpleBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateSimpleBus.Location = new Point(428, 501);
buttonCreateSimpleBus.Name = "buttonCreateSimpleBus";
buttonCreateSimpleBus.Size = new Size(431, 46);
buttonCreateSimpleBus.TabIndex = 8;
buttonCreateSimpleBus.Text = "Создать обычный автобус";
buttonCreateSimpleBus.UseVisualStyleBackColor = true;
buttonCreateSimpleBus.Click += buttonCreateSimpleBus_Click;
//
// FormBus // FormBus
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(1155, 557);
Controls.Add(buttonCreateSimpleBus);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonRight); Controls.Add(buttonRight);
@ -129,5 +142,6 @@
private Button buttonRight; private Button buttonRight;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonCreateSimpleBus;
} }
} }

View File

@ -1,4 +1,6 @@
using System; using ProjectBus.Drawings;
using ProjectBus.Drawnings;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -12,7 +14,7 @@ namespace ProjectBus
{ {
public partial class FormBus : Form public partial class FormBus : Form
{ {
private DrawingBus? _drawingBus; private DrawningSimpleBus? _drawningSimpleBus;
public FormBus() public FormBus()
{ {
@ -21,36 +23,65 @@ namespace ProjectBus
private void Draw() private void Draw()
{ {
if (_drawingBus == null) if (_drawningSimpleBus == null)
{ {
return; return;
} }
Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height); Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawingBus.DrawTransport(gr); _drawningSimpleBus.DrawTransport(gr);
pictureBoxBus.Image = bmp; pictureBoxBus.Image = bmp;
} }
/// <summary>
private void ButtonCreate_Click(object sender, EventArgs e) /// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{ {
Random random = new(); Random random = new();
_drawingBus = new DrawingBus(); switch (type)
_drawingBus.Init(random.Next(100, 300), random.Next(1000, 3000), {
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), case nameof(DrawningSimpleBus):
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), _drawningSimpleBus = new DrawningSimpleBus(random.Next(100, 300), random.Next(1000, 3000),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
_drawingBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height); break;
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); case nameof(DrawningBus):
_drawningSimpleBus = new DrawningBus(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;
}
_drawningSimpleBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height);
_drawningSimpleBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
/// <summary>
/// Обработка нажатия кнопки "Создать автобус с доп отсеком"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus));
/// <summary>
/// Обработка нажатия кнопки "Создать обычный автобус"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus));
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawingBus == null) if (_drawningSimpleBus == null)
{ {
return; return;
} }
@ -61,19 +92,19 @@ namespace ProjectBus
{ {
case "buttonUp": case "buttonUp":
result = result =
_drawingBus.MoveTransport(DirectionType.Up); _drawningSimpleBus.MoveTransport(DirectionType.Up);
break; break;
case "buttonDown": case "buttonDown":
result = result =
_drawingBus.MoveTransport(DirectionType.Down); _drawningSimpleBus.MoveTransport(DirectionType.Down);
break; break;
case "buttonLeft": case "buttonLeft":
result = result =
_drawingBus.MoveTransport(DirectionType.Left); _drawningSimpleBus.MoveTransport(DirectionType.Left);
break; break;
case "buttonRight": case "buttonRight":
result = result =
_drawingBus.MoveTransport(DirectionType.Right); _drawningSimpleBus.MoveTransport(DirectionType.Right);
break; break;
} }
@ -81,7 +112,6 @@ namespace ProjectBus
{ {
Draw(); Draw();
} }
} }
} }
} }