PIbd-11_Permyakov_R.G._AccordionBus_Simple_Lab2 #2
@@ -4,13 +4,17 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AccordionBus
|
namespace AccordionBus.Drawnings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление премещения
|
/// Направление премещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неизвестное направление
|
||||||
|
/// </summary>
|
||||||
|
Unknow = -1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
/// </summary>
|
/// </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.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AccordionBus
|
namespace AccordionBus.Drawnings
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class DrawningBus
|
||||||
/// Класс, отвечающий за перемещение и прорисовку объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawningAccordionBus
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAccordionBus? EntityAccordionBus { get; private set; }
|
public EntityBus? EntityBus { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,39 +25,70 @@ namespace AccordionBus
|
|||||||
/// <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 _drawningBusWeight = 130;
|
private readonly int _drawningBusWeight = 60;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки авто
|
/// Высота прорисовки авто
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningBusHeight = 20;
|
private readonly int _drawningBusHeight = 20;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Координата Х объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed"></param>
|
/// <returns></returns>
|
||||||
/// <param name="weight"></param>
|
public int? GetPosX() => _startPosX;
|
||||||
/// <param name="bodyColor"></param>
|
/// <summary>
|
||||||
/// <param name="additionalColor"></param>
|
/// Координата Y объекта
|
||||||
/// <param name="threeDoors"></param>
|
/// </summary>
|
||||||
/// <param name="fourDoors"></param>
|
/// <returns></returns>
|
||||||
/// <param name="fiveDoors"></param>
|
public int? GetPosY() => _startPosY;
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
/// <summary>
|
||||||
additionalColor, bool onePart, bool fiveDoors)
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int GetWidth() => _drawningBusWeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int GetHeight() => _drawningBusHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой конструктор
|
||||||
|
/// </summary>
|
||||||
|
private DrawningBus()
|
||||||
{
|
{
|
||||||
EntityAccordionBus = new EntityAccordionBus();
|
|
||||||
EntityAccordionBus.Init(speed, weight, bodyColor, additionalColor, onePart, fiveDoors);
|
|
||||||
_pictureWeight = null;
|
_pictureWeight = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = 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>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -101,7 +131,7 @@ namespace AccordionBus
|
|||||||
|
|
||||||
if (x + _drawningBusWeight > _pictureWeight)
|
if (x + _drawningBusWeight > _pictureWeight)
|
||||||
{
|
{
|
||||||
_startPosX = x - ( x + _drawningBusWeight - _pictureWeight);
|
_startPosX = x - (x + _drawningBusWeight - _pictureWeight);
|
||||||
}
|
}
|
||||||
else if (x < 0)
|
else if (x < 0)
|
||||||
{
|
{
|
||||||
@@ -114,7 +144,7 @@ namespace AccordionBus
|
|||||||
|
|
||||||
if (y + _drawningBusHeight > _pictureHeight)
|
if (y + _drawningBusHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY = y - ( y + _drawningBusHeight - _pictureHeight);
|
_startPosY = y - (y + _drawningBusHeight - _pictureHeight);
|
||||||
}
|
}
|
||||||
else if (y < 0)
|
else if (y < 0)
|
||||||
{
|
{
|
||||||
@@ -132,7 +162,7 @@ namespace AccordionBus
|
|||||||
/// <returns>true - перемещение выполнено, false - перемещение невозможнор</returns>
|
/// <returns>true - перемещение выполнено, false - перемещение невозможнор</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityAccordionBus == null || !_startPosX.HasValue ||
|
if (EntityBus == null || !_startPosX.HasValue ||
|
||||||
!_startPosY.HasValue)
|
!_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -142,9 +172,9 @@ namespace AccordionBus
|
|||||||
{
|
{
|
||||||
|
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityAccordionBus.Step > 0)
|
if (_startPosX.Value - EntityBus.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityAccordionBus.Step;
|
_startPosX -= (int)EntityBus.Step;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -153,9 +183,9 @@ namespace AccordionBus
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case DirectionType.Right:
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -164,9 +194,9 @@ namespace AccordionBus
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityAccordionBus.Step > 0)
|
if (_startPosY.Value - EntityBus.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityAccordionBus.Step;
|
_startPosY -= (int)EntityBus.Step;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -175,9 +205,9 @@ namespace AccordionBus
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case DirectionType.Down:
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -193,19 +223,19 @@ namespace AccordionBus
|
|||||||
/// Отрисовка транспорта
|
/// Отрисовка транспорта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityAccordionBus == null || !_startPosX.HasValue ||
|
if (EntityBus == null || !_startPosX.HasValue ||
|
||||||
!_startPosY.HasValue)
|
!_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
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.FillRectangle(br, _startPosX.Value, _startPosY.Value, 60, 15);
|
||||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 60, 15);
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 60, 15);
|
||||||
|
|
||||||
@@ -228,59 +258,8 @@ namespace AccordionBus
|
|||||||
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 3, 5, 5);
|
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);
|
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.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AccordionBus
|
namespace AccordionBus.Entities
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// класс-сущность "автобус с гормошкой"
|
/// класс-сущность "автобус с гормошкой"
|
||||||
/// </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>
|
||||||
/// Дополнительный цвет
|
/// Дополнительный цвет
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,25 +24,17 @@ namespace AccordionBus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool FiveDoors { get; set; }
|
public bool FiveDoors { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
/// <summary>
|
|
||||||
/// инициализация полей объекта-класса
|
/// инициализация полей объекта-класса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">вес</param>
|
/// <param name="weight">вес</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="threeDoors">3 двери</param>
|
/// <param name="onePart">1 часть</param>
|
||||||
/// <param name="fourDoors">4 двери</param>
|
|
||||||
/// <param name="fiveDoors">5 дверей</param>
|
/// <param name="fiveDoors">5 дверей</param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
public EntityAccordionBus(int speed, double weight, Color bodyColor,
|
||||||
additionalColor, bool onePart, bool fiveDoors)
|
Color additionalColor, bool onePart, bool fiveDoors) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
OnePart = onePart;
|
OnePart = onePart;
|
||||||
FiveDoors = fiveDoors;
|
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,20 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxAccordionBus = new PictureBox();
|
pictureBoxAccordionBus = new PictureBox();
|
||||||
buttonCreate = new Button();
|
buttonCreateAccordionBus = new Button();
|
||||||
ButtonUp = new Button();
|
ButtonUp = new Button();
|
||||||
ButtonRight = new Button();
|
ButtonRight = new Button();
|
||||||
ButtonLeft = new Button();
|
ButtonLeft = new Button();
|
||||||
ButtonDown = new Button();
|
ButtonDown = new Button();
|
||||||
|
buttonCreateBus = new Button();
|
||||||
|
comboBoxStratregy = new ComboBox();
|
||||||
|
buttonStrategyStap = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxAccordionBus
|
// pictureBoxAccordionBus
|
||||||
//
|
//
|
||||||
pictureBoxAccordionBus.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
pictureBoxAccordionBus.Dock = DockStyle.Fill;
|
||||||
pictureBoxAccordionBus.Location = new Point(0, 0);
|
pictureBoxAccordionBus.Location = new Point(0, 0);
|
||||||
pictureBoxAccordionBus.Name = "pictureBoxAccordionBus";
|
pictureBoxAccordionBus.Name = "pictureBoxAccordionBus";
|
||||||
pictureBoxAccordionBus.Size = new Size(882, 453);
|
pictureBoxAccordionBus.Size = new Size(882, 453);
|
||||||
@@ -47,16 +50,16 @@
|
|||||||
pictureBoxAccordionBus.TabIndex = 0;
|
pictureBoxAccordionBus.TabIndex = 0;
|
||||||
pictureBoxAccordionBus.TabStop = false;
|
pictureBoxAccordionBus.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreateAccordionBus
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateAccordionBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(12, 412);
|
buttonCreateAccordionBus.Location = new Point(12, 412);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreateAccordionBus.Name = "buttonCreateAccordionBus";
|
||||||
buttonCreate.Size = new Size(94, 29);
|
buttonCreateAccordionBus.Size = new Size(235, 29);
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreateAccordionBus.TabIndex = 1;
|
||||||
buttonCreate.Text = "создать";
|
buttonCreateAccordionBus.Text = "создать автобус с гормошкой";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreateAccordionBus.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += ButtonCreate_Click;
|
buttonCreateAccordionBus.Click += ButtonCreate_Click;
|
||||||
//
|
//
|
||||||
// ButtonUp
|
// ButtonUp
|
||||||
//
|
//
|
||||||
@@ -110,16 +113,50 @@
|
|||||||
ButtonDown.UseVisualStyleBackColor = true;
|
ButtonDown.UseVisualStyleBackColor = true;
|
||||||
ButtonDown.Click += ButtonMove_Click;
|
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;
|
||||||
|
//
|
||||||
|
// comboBoxStratregy
|
||||||
|
//
|
||||||
|
comboBoxStratregy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStratregy.FormattingEnabled = true;
|
||||||
|
comboBoxStratregy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||||
|
comboBoxStratregy.Location = new Point(688, 12);
|
||||||
|
comboBoxStratregy.Name = "comboBoxStratregy";
|
||||||
|
comboBoxStratregy.Size = new Size(151, 28);
|
||||||
|
comboBoxStratregy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStrategyStap
|
||||||
|
//
|
||||||
|
buttonStrategyStap.Location = new Point(761, 46);
|
||||||
|
buttonStrategyStap.Name = "buttonStrategyStap";
|
||||||
|
buttonStrategyStap.Size = new Size(78, 29);
|
||||||
|
buttonStrategyStap.TabIndex = 8;
|
||||||
|
buttonStrategyStap.Text = "Шаг";
|
||||||
|
buttonStrategyStap.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStap.Click += buttonStrategyStap_Click;
|
||||||
|
//
|
||||||
// FormAccordionBus
|
// FormAccordionBus
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(882, 453);
|
ClientSize = new Size(882, 453);
|
||||||
|
Controls.Add(buttonStrategyStap);
|
||||||
|
Controls.Add(comboBoxStratregy);
|
||||||
|
Controls.Add(buttonCreateBus);
|
||||||
Controls.Add(ButtonDown);
|
Controls.Add(ButtonDown);
|
||||||
Controls.Add(ButtonLeft);
|
Controls.Add(ButtonLeft);
|
||||||
Controls.Add(ButtonRight);
|
Controls.Add(ButtonRight);
|
||||||
Controls.Add(ButtonUp);
|
Controls.Add(ButtonUp);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonCreateAccordionBus);
|
||||||
Controls.Add(pictureBoxAccordionBus);
|
Controls.Add(pictureBoxAccordionBus);
|
||||||
Name = "FormAccordionBus";
|
Name = "FormAccordionBus";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
@@ -132,10 +169,13 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxAccordionBus;
|
private PictureBox pictureBoxAccordionBus;
|
||||||
private Button buttonCreate;
|
private Button buttonCreateAccordionBus;
|
||||||
private Button ButtonUp;
|
private Button ButtonUp;
|
||||||
private Button ButtonRight;
|
private Button ButtonRight;
|
||||||
private Button ButtonLeft;
|
private Button ButtonLeft;
|
||||||
private Button ButtonDown;
|
private Button ButtonDown;
|
||||||
|
private Button buttonCreateBus;
|
||||||
|
private ComboBox comboBoxStratregy;
|
||||||
|
private Button buttonStrategyStap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,44 +7,71 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using AccordionBus.Drawnings;
|
||||||
|
using AccordionBus.MovementStrategy;
|
||||||
|
|
||||||
namespace AccordionBus
|
namespace AccordionBus
|
||||||
{
|
{
|
||||||
public partial class FormAccordionBus : Form
|
public partial class FormAccordionBus : Form
|
||||||
{
|
{
|
||||||
private DrawningAccordionBus? _drawningAccordionBus;
|
private DrawningBus? _drawningBus;
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
public FormAccordionBus()
|
public FormAccordionBus()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningAccordionBus == null)
|
if (_drawningBus == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
Bitmap bmp = new(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningAccordionBus.DrawTransport(gr);
|
_drawningBus.DrawTransport(gr);
|
||||||
pictureBoxAccordionBus.Image = bmp;
|
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));
|
||||||
|
_strategy = null;
|
||||||
|
comboBoxStratregy.Enabled = true;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
CreateObject(nameof(DrawningAccordionBus));
|
||||||
_drawningAccordionBus = new DrawningAccordionBus();
|
}
|
||||||
_drawningAccordionBus.Init(random.Next(100, 300), random.Next(1000, 3000),
|
private void ButtonCreateBus_Click(object sender, EventArgs e)
|
||||||
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)));
|
CreateObject(nameof(DrawningBus));
|
||||||
_drawningAccordionBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
|
||||||
_drawningAccordionBus.SetPosition(random.Next(50, 300), random.Next(50, 300));
|
|
||||||
Draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningAccordionBus == null)
|
if (_drawningBus == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -54,16 +81,16 @@ namespace AccordionBus
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "ButtonUp":
|
case "ButtonUp":
|
||||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Up);
|
result = _drawningBus.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "ButtonDown":
|
case "ButtonDown":
|
||||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Down);
|
result = _drawningBus.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "ButtonLeft":
|
case "ButtonLeft":
|
||||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Left);
|
result = _drawningBus.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "ButtonRight":
|
case "ButtonRight":
|
||||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Right);
|
result = _drawningBus.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,5 +99,32 @@ namespace AccordionBus
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonStrategyStap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningBus == null) return;
|
||||||
|
if (comboBoxStratregy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStratregy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
if (_strategy == null) return;
|
||||||
|
_strategy.SetData(new MoveableBus(_drawningBus), pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_strategy == null) return;
|
||||||
|
comboBoxStratregy.Enabled = false;
|
||||||
|
_strategy.MakeStap();
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStratregy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
125
AccordionBus/AccordionBus/MovementStrategy/AbstractStrategy.cs
Normal file
125
AccordionBus/AccordionBus/MovementStrategy/AbstractStrategy.cs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObjects? _moveableObject;
|
||||||
|
/// <summary>
|
||||||
|
/// Статус стратегии
|
||||||
|
/// </summary>
|
||||||
|
private StrategyStatus? _state = StrategyStatus.NotInit;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Высота
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Получение статуса
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public StrategyStatus? GetStatus() { return _state; }
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="moveableObject"></param>
|
||||||
|
/// <param name="width"></param>
|
||||||
|
/// <param name="height"></param>
|
||||||
|
public void SetData(IMoveableObjects moveableObject, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_state = StrategyStatus.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Напавление
|
||||||
|
/// </summary>
|
||||||
|
public void MakeStap()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress) return;
|
||||||
|
if (IsTargetDestination())
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение параметров
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected ObjectParameters? GetObjectParameters() => _moveableObject?.GetObjectPosition;
|
||||||
|
/// <summary>
|
||||||
|
/// Получение шага
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStap()
|
||||||
|
{
|
||||||
|
if(_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
/// <summary>
|
||||||
|
/// Достижение цели
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestination();
|
||||||
|
/// <summary>
|
||||||
|
/// Сделать шаг
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="movementDirection"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool MoveTo(MovementDirection movementDirection)
|
||||||
|
{
|
||||||
|
if(_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс для работы с пперемещаемым объектом
|
||||||
|
/// </summary>
|
||||||
|
public interface IMoveableObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// попытка переместить объект в указаном направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - перемещение удалось false - перемещение невозможно</returns>
|
||||||
|
bool TryMoveObject(MovementDirection direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs
Normal file
33
AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestination()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters();
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder() == FieldWidth && objParams.DownBorder() == FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters();
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objParams.RightBorder() < FieldWidth) MoveRight();
|
||||||
|
if (objParams.DownBorder() < FieldHeight) MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs
Normal file
56
AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestination()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters();
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal() - GetStap() <= FieldWidth / 2
|
||||||
|
&& objParams.ObjectMiddleHorizontal() + GetStap() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical() - GetStap() <= FieldHeight / 2
|
||||||
|
&& objParams.ObjectMiddleVertical() + GetStap() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters();
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStap())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStap())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
67
AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs
Normal file
67
AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using AccordionBus.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-реализация IMoveableObjects с использованием DrawningBus
|
||||||
|
/// </summary>
|
||||||
|
public class MoveableBus : IMoveableObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект DrawningBus
|
||||||
|
/// </summary>
|
||||||
|
private readonly DrawningBus? _car;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="car">Объект класса DrawningBus</param>
|
||||||
|
public MoveableBus(DrawningBus? car)
|
||||||
|
{
|
||||||
|
_car = car;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_car == null || _car.EntityBus == null || _car.GetPosX() == null || _car.GetPosY() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_car.GetPosX().Value, _car.GetPosY().Value, _car.GetWidth(), _car.GetHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep => (int)(_car?.EntityBus?.Step ?? 0);
|
||||||
|
|
||||||
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
|
{
|
||||||
|
if (_car == null || _car.EntityBus == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return _car.MoveTransport(GetDirectionType(direction));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертация из MovementDirection в DirectionType
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры-координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Х
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _x;
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _y;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _width;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Левая граница
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int LeftBorder() => _x;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int TopBorder() => _y;
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int RightBorder() => _x + _width;
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int DownBorder() => _y + _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int ObjectMiddleHorizontal() => _x + _width / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int ObjectMiddleVertical() => _y + _height / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата Х</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width"Ширина></param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
AccordionBus/AccordionBus/MovementStrategy/StrategyStatus.cs
Normal file
24
AccordionBus/AccordionBus/MovementStrategy/StrategyStatus.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccordionBus.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// всё готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
/// <summary>
|
||||||
|
/// В процессе
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
/// <summary>
|
||||||
|
/// Завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user