реализация наследования и конструкторов
This commit is contained in:
parent
d1eb7efad4
commit
4adc299af9
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus
|
||||
namespace AccordionBus.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление премещения
|
100
AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs
Normal file
100
AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AccordionBus.Entities;
|
||||
|
||||
namespace AccordionBus.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за перемещение и прорисовку объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAccordionBus : DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="additionalColor"></param>
|
||||
/// <param name="onePart"></param>
|
||||
/// <param name="fiveDoors"></param>
|
||||
public DrawningAccordionBus(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool onePart, bool fiveDoors): base(130, 20)
|
||||
{
|
||||
EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor, onePart, fiveDoors);
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка транспорта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || EntityBus is not EntityAccordionBus accordionBus || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (!accordionBus.OnePart)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brWhite = new SolidBrush(Color.White);
|
||||
Brush br = new SolidBrush(accordionBus.BodyColor);
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
Brush additionalBrush = new SolidBrush(accordionBus.AdditionalColor);
|
||||
//корпус
|
||||
g.FillRectangle(br, _startPosX.Value + 70, _startPosY.Value, 60, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value, 60, 15);
|
||||
|
||||
//колёса
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10);
|
||||
|
||||
//стёкла
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5);
|
||||
|
||||
//гормошка
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value, _startPosX.Value + 62, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 65, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 67, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 70, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 62, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 12, _startPosX.Value + 65, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 12, _startPosX.Value + 70, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 62, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 67, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 65, _startPosY.Value + 15);
|
||||
|
||||
//двери
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10);
|
||||
if (accordionBus.FiveDoors)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,19 @@
|
||||
using System;
|
||||
using AccordionBus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus
|
||||
namespace AccordionBus.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за перемещение и прорисовку объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAccordionBus
|
||||
public class DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAccordionBus? EntityAccordionBus { get; private set; }
|
||||
public EntityBus? EntityBus { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -26,39 +25,50 @@ namespace AccordionBus
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки авто
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки авто
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки авто
|
||||
/// </summary>
|
||||
private readonly int _drawningBusWeight = 130;
|
||||
private readonly int _drawningBusWeight = 60;
|
||||
/// <summary>
|
||||
/// Высота прорисовки авто
|
||||
/// </summary>
|
||||
private readonly int _drawningBusHeight = 20;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="additionalColor"></param>
|
||||
/// <param name="threeDoors"></param>
|
||||
/// <param name="fourDoors"></param>
|
||||
/// <param name="fiveDoors"></param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool onePart, bool fiveDoors)
|
||||
private DrawningBus()
|
||||
{
|
||||
EntityAccordionBus = new EntityAccordionBus();
|
||||
EntityAccordionBus.Init(speed, weight, bodyColor, additionalColor, onePart, fiveDoors);
|
||||
_pictureWeight = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор границ объекта
|
||||
/// </summary>
|
||||
/// <param name="drawningBusWeight">Ширина</param>
|
||||
/// <param name="drawningBusHeight">Высота</param>
|
||||
protected DrawningBus(int drawningBusWeight, int drawningBusHeight) : this()
|
||||
{
|
||||
_drawningBusWeight = drawningBusWeight;
|
||||
_drawningBusHeight = drawningBusHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор пораметров
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBus(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBus = new EntityBus(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -85,7 +95,7 @@ namespace AccordionBus
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -101,7 +111,7 @@ namespace AccordionBus
|
||||
|
||||
if (x + _drawningBusWeight > _pictureWeight)
|
||||
{
|
||||
_startPosX = x - ( x + _drawningBusWeight - _pictureWeight);
|
||||
_startPosX = x - (x + _drawningBusWeight - _pictureWeight);
|
||||
}
|
||||
else if (x < 0)
|
||||
{
|
||||
@ -114,7 +124,7 @@ namespace AccordionBus
|
||||
|
||||
if (y + _drawningBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = y - ( y + _drawningBusHeight - _pictureHeight);
|
||||
_startPosY = y - (y + _drawningBusHeight - _pictureHeight);
|
||||
}
|
||||
else if (y < 0)
|
||||
{
|
||||
@ -132,7 +142,7 @@ namespace AccordionBus
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможнор</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAccordionBus == null || !_startPosX.HasValue ||
|
||||
if (EntityBus == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
@ -142,9 +152,9 @@ namespace AccordionBus
|
||||
{
|
||||
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAccordionBus.Step > 0)
|
||||
if (_startPosX.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAccordionBus.Step;
|
||||
_startPosX -= (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -153,9 +163,9 @@ namespace AccordionBus
|
||||
return true;
|
||||
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityAccordionBus.Step + _drawningBusWeight < _pictureWeight)
|
||||
if (_startPosX.Value + EntityBus.Step + _drawningBusWeight < _pictureWeight)
|
||||
{
|
||||
_startPosX += (int)EntityAccordionBus.Step;
|
||||
_startPosX += (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -164,9 +174,9 @@ namespace AccordionBus
|
||||
return true;
|
||||
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAccordionBus.Step > 0)
|
||||
if (_startPosY.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAccordionBus.Step;
|
||||
_startPosY -= (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -175,9 +185,9 @@ namespace AccordionBus
|
||||
return true;
|
||||
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityAccordionBus.Step + _drawningBusHeight < _pictureHeight)
|
||||
if (_startPosY.Value + EntityBus.Step + _drawningBusHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAccordionBus.Step;
|
||||
_startPosY += (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -193,19 +203,19 @@ namespace AccordionBus
|
||||
/// Отрисовка транспорта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAccordionBus == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
if (EntityBus == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAccordionBus.AdditionalColor);
|
||||
Brush brDoor = new SolidBrush(Color.Gray);
|
||||
|
||||
//корпус
|
||||
Brush br = new SolidBrush(EntityAccordionBus.BodyColor);
|
||||
Brush br = new SolidBrush(EntityBus.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value, 60, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 60, 15);
|
||||
|
||||
@ -228,59 +238,8 @@ namespace AccordionBus
|
||||
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 3, 5, 5);
|
||||
|
||||
//дверь
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10);
|
||||
|
||||
if (!EntityAccordionBus.OnePart)
|
||||
{
|
||||
//корпус
|
||||
g.FillRectangle(br, _startPosX.Value + 70, _startPosY.Value, 60, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value, 60, 15);
|
||||
|
||||
//колёса
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10);
|
||||
|
||||
//стёкла
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5);
|
||||
|
||||
//гормошка
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value, _startPosX.Value + 62, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 65, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 67, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 70, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 62, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 12, _startPosX.Value + 65, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 12, _startPosX.Value + 70, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 62, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 67, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 65, _startPosY.Value + 15);
|
||||
|
||||
//двери
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10);
|
||||
if (EntityAccordionBus.FiveDoors)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,25 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus
|
||||
namespace AccordionBus.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// класс-сущность "автобус с гормошкой"
|
||||
/// </summary>
|
||||
public class EntityAccordionBus
|
||||
public class EntityAccordionBus : EntityBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
@ -36,25 +24,17 @@ namespace AccordionBus
|
||||
/// </summary>
|
||||
public bool FiveDoors { get; set; }
|
||||
/// <summary>
|
||||
/// Шаг
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// инициализация полей объекта-класса
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="threeDoors">3 двери</param>
|
||||
/// <param name="fourDoors">4 двери</param>
|
||||
/// <param name="onePart">1 часть</param>
|
||||
/// <param name="fiveDoors">5 дверей</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool onePart, bool fiveDoors)
|
||||
public EntityAccordionBus(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, bool onePart, bool fiveDoors) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
OnePart = onePart;
|
||||
FiveDoors = fiveDoors;
|
43
AccordionBus/AccordionBus/Entities/EntityBus.cs
Normal file
43
AccordionBus/AccordionBus/Entities/EntityBus.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// класс-сущность "Автобус"
|
||||
/// </summary>
|
||||
public class EntityBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; set; }
|
||||
/// <summary>
|
||||
/// Шаг
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityBus(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,17 +29,18 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxAccordionBus = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateAccordionBus = new Button();
|
||||
ButtonUp = new Button();
|
||||
ButtonRight = new Button();
|
||||
ButtonLeft = new Button();
|
||||
ButtonDown = new Button();
|
||||
buttonCreateBus = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxAccordionBus
|
||||
//
|
||||
pictureBoxAccordionBus.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
pictureBoxAccordionBus.Dock = DockStyle.Fill;
|
||||
pictureBoxAccordionBus.Location = new Point(0, 0);
|
||||
pictureBoxAccordionBus.Name = "pictureBoxAccordionBus";
|
||||
pictureBoxAccordionBus.Size = new Size(882, 453);
|
||||
@ -47,16 +48,16 @@
|
||||
pictureBoxAccordionBus.TabIndex = 0;
|
||||
pictureBoxAccordionBus.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateAccordionBus
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 412);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
buttonCreateAccordionBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAccordionBus.Location = new Point(12, 412);
|
||||
buttonCreateAccordionBus.Name = "buttonCreateAccordionBus";
|
||||
buttonCreateAccordionBus.Size = new Size(235, 29);
|
||||
buttonCreateAccordionBus.TabIndex = 1;
|
||||
buttonCreateAccordionBus.Text = "создать автобус с гормошкой";
|
||||
buttonCreateAccordionBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateAccordionBus.Click += ButtonCreate_Click;
|
||||
//
|
||||
// ButtonUp
|
||||
//
|
||||
@ -110,16 +111,28 @@
|
||||
ButtonDown.UseVisualStyleBackColor = true;
|
||||
ButtonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBus
|
||||
//
|
||||
buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBus.Location = new Point(253, 411);
|
||||
buttonCreateBus.Name = "buttonCreateBus";
|
||||
buttonCreateBus.Size = new Size(235, 29);
|
||||
buttonCreateBus.TabIndex = 6;
|
||||
buttonCreateBus.Text = "создать автобус";
|
||||
buttonCreateBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateBus.Click += ButtonCreateBus_Click;
|
||||
//
|
||||
// FormAccordionBus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(buttonCreateBus);
|
||||
Controls.Add(ButtonDown);
|
||||
Controls.Add(ButtonLeft);
|
||||
Controls.Add(ButtonRight);
|
||||
Controls.Add(ButtonUp);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonCreateAccordionBus);
|
||||
Controls.Add(pictureBoxAccordionBus);
|
||||
Name = "FormAccordionBus";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
@ -132,10 +145,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAccordionBus;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateAccordionBus;
|
||||
private Button ButtonUp;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonDown;
|
||||
private Button buttonCreateBus;
|
||||
}
|
||||
}
|
@ -7,12 +7,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AccordionBus.Drawnings;
|
||||
|
||||
namespace AccordionBus
|
||||
{
|
||||
public partial class FormAccordionBus : Form
|
||||
{
|
||||
private DrawningAccordionBus? _drawningAccordionBus;
|
||||
private DrawningBus? _drawningBus;
|
||||
public FormAccordionBus()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -20,31 +21,52 @@ namespace AccordionBus
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAccordionBus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAccordionBus.DrawTransport(gr);
|
||||
_drawningBus.DrawTransport(gr);
|
||||
pictureBoxAccordionBus.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, 255), random.Next(0, 255), random.Next(0, 255)));
|
||||
break;
|
||||
case nameof(DrawningAccordionBus):
|
||||
_drawningBus = new DrawningAccordionBus(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
||||
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
_drawningBus.SetPosition(random.Next(50, 300), random.Next(50, 300));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAccordionBus = new DrawningAccordionBus();
|
||||
_drawningAccordionBus.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
||||
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAccordionBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
_drawningAccordionBus.SetPosition(random.Next(50, 300), random.Next(50, 300));
|
||||
Draw();
|
||||
CreateObject(nameof(DrawningAccordionBus));
|
||||
}
|
||||
private void ButtonCreateBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningBus));
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAccordionBus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -54,16 +76,16 @@ namespace AccordionBus
|
||||
switch (name)
|
||||
{
|
||||
case "ButtonUp":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Up);
|
||||
result = _drawningBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "ButtonDown":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Down);
|
||||
result = _drawningBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "ButtonLeft":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Left);
|
||||
result = _drawningBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "ButtonRight":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Right);
|
||||
result = _drawningBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user