Compare commits
2 Commits
de539f3881
...
1f2abb6c1f
Author | SHA1 | Date | |
---|---|---|---|
|
1f2abb6c1f | ||
|
bf2857c8ca |
3
.gitignore
vendored
3
.gitignore
vendored
@ -398,3 +398,6 @@ FodyWeavers.xsd
|
|||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
|
/ProjectDumpTruck/ProjectDumpTruck/DirectionType.cs
|
||||||
|
/ProjectDumpTruck/ProjectDumpTruck/DrawningDumpTrack.cs
|
||||||
|
/ProjectDumpTruck/ProjectDumpTruck/EntityDumpTruck.cs
|
||||||
|
8
ProjectDumpTruck/DirectionType.cs
Normal file
8
ProjectDumpTruck/DirectionType.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
public Class1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
8
ProjectDumpTruck/DrawningDumpTrack.cs
Normal file
8
ProjectDumpTruck/DrawningDumpTrack.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
public Class1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
8
ProjectDumpTruck/DrawningTrack.cs
Normal file
8
ProjectDumpTruck/DrawningTrack.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
public Class1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
8
ProjectDumpTruck/EntityDampTrack.cs
Normal file
8
ProjectDumpTruck/EntityDampTrack.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
public Class1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
8
ProjectDumpTruck/EntityTrack.cs
Normal file
8
ProjectDumpTruck/EntityTrack.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
public Class1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,15 @@
|
|||||||
namespace ProjectDumpTruck;
|
namespace ProjectDumpTrack.Drawnings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неизвестное направление
|
||||||
|
/// </summary>
|
||||||
|
Unknow = -1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
/// </summary>
|
/// </summary>
|
106
ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
Normal file
106
ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
using ProjectDumpTrack.Entities;
|
||||||
|
|
||||||
|
namespace ProjectDumpTrack.Drawnings;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningDumpTrack : DrawningTrack
|
||||||
|
{
|
||||||
|
////2 задание
|
||||||
|
//public override bool MoveTransport(DirectionType direction)
|
||||||
|
//{
|
||||||
|
// if (EntityTrack == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
// {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// switch (direction)
|
||||||
|
// {
|
||||||
|
// //влево
|
||||||
|
// case DirectionType.Left:
|
||||||
|
// if (_startPosX.Value - EntityTrack.Step > 0)
|
||||||
|
// {
|
||||||
|
// _startPosX -= (int)EntityTrack.Step;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
|
||||||
|
// //вверх
|
||||||
|
// case DirectionType.Up:
|
||||||
|
// if (_startPosY.Value - EntityTrack.Step > 0)
|
||||||
|
// {
|
||||||
|
// _startPosY -= (int)EntityTrack.Step;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
|
||||||
|
// //вправо
|
||||||
|
// case DirectionType.Right:
|
||||||
|
// if (_startPosX.Value + EntityTrack.Step + _drawningTrackWidth < _pictureWidth)
|
||||||
|
// {
|
||||||
|
// _startPosX += (int)EntityTrack.Step;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
|
||||||
|
// //вниз
|
||||||
|
// case DirectionType.Down:
|
||||||
|
// if (_startPosY.Value + EntityTrack.Step + _drawningTrackHeight < _pictureHeight)
|
||||||
|
// {
|
||||||
|
// _startPosY += (int)EntityTrack.Step;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// default:
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="bodywork">Признак наличия кузова</param>
|
||||||
|
/// <param name="awning">Признак наличия тента</param>
|
||||||
|
|
||||||
|
|
||||||
|
public DrawningDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning) : base(130, 100)
|
||||||
|
{
|
||||||
|
EntityTrack = new EntityDumpTrack(speed, weight, bodyColor, additionalColor, bodywork, awning);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityTrack == null || EntityTrack is not EntityDumpTrack dumpTrack || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(dumpTrack.AdditionalColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
//Отрисовка кузова
|
||||||
|
if (dumpTrack.Bodywork)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 90, 35);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Отрисовка тента
|
||||||
|
if (dumpTrack.Bodywork & dumpTrack.Awning)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 95, 10);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 95, 3);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value, 3, 40);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value, 3, 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,62 +1,71 @@
|
|||||||
namespace ProjectDumpTruck;
|
|
||||||
|
using ProjectDumpTrack.Entities;
|
||||||
|
|
||||||
/// <summary>
|
namespace ProjectDumpTrack.Drawnings;
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
public class DrawningTrack
|
||||||
/// </summary>
|
|
||||||
public class DrawningDumpTrack
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityDumpTruck? EntityDumpTruck { get; private set; }
|
public EntityTrack? EntityTrack { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureWidth;
|
private int? _pictureWidth;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота окна
|
/// Высота окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight;
|
private int? _pictureHeight;
|
||||||
|
|
||||||
|
|
||||||
/// <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 _drawningDumpTrackWidth = 130;
|
private readonly int _drawningTrackWidth = 130;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки самосвала
|
/// Высота прорисовки самосвала
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningDumpTrackHeight = 90;
|
private readonly int _drawningTrackHeight = 100;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Координата X объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
public int? GetPosX => _startPosX;
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="bodywork">Признак наличия кузова</param>
|
|
||||||
/// <param name="awning">Признак наличия тента</param>
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int? GetPosY => _startPosY;
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning)
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _drawningTrackWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _drawningTrackHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой конструктор
|
||||||
|
/// </summary>
|
||||||
|
private DrawningTrack()
|
||||||
{
|
{
|
||||||
EntityDumpTruck = new EntityDumpTruck();
|
|
||||||
EntityDumpTruck.Init(speed, weight, bodyColor, additionalColor, bodywork, awning);
|
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
@ -64,6 +73,35 @@ public class DrawningDumpTrack
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
|
||||||
|
|
||||||
|
public DrawningTrack(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityTrack = new EntityTrack(speed, weight, bodyColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningTrackWidth">Ширина прорисовки автомобиля</param>
|
||||||
|
/// <param name="drawningTrackHeight">Высота прорисовки автомобиля</param>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected DrawningTrack(int drawningTrackWidth, int drawningTrackHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningTrackWidth = drawningTrackWidth;
|
||||||
|
_drawningTrackHeight = drawningTrackHeight;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -76,13 +114,14 @@ public class DrawningDumpTrack
|
|||||||
{
|
{
|
||||||
// TODO проверка, что объект "влезает" в размеры поля
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||||
if (_drawningDumpTrackWidth > width || _drawningDumpTrackHeight > height)
|
if (_drawningTrackWidth > width || _drawningTrackHeight > height)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,13 +138,13 @@ public class DrawningDumpTrack
|
|||||||
}
|
}
|
||||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||||
if (x + _drawningDumpTrackWidth > _pictureWidth )
|
if (x + _drawningTrackWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
x = (int)_pictureWidth-_drawningDumpTrackWidth;
|
x -= _drawningTrackWidth;
|
||||||
}
|
}
|
||||||
if (y + _drawningDumpTrackHeight > _pictureHeight)
|
if (y + _drawningTrackHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
y = (int)_pictureHeight-_drawningDumpTrackHeight;
|
y -= _drawningTrackHeight;
|
||||||
}
|
}
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
@ -128,7 +167,7 @@ public class DrawningDumpTrack
|
|||||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityDumpTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityTrack == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -137,33 +176,33 @@ public class DrawningDumpTrack
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityDumpTruck.Step > 0)
|
if (_startPosX.Value - EntityTrack.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityDumpTruck.Step;
|
_startPosX -= (int)EntityTrack.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityDumpTruck.Step > 0)
|
if (_startPosY.Value - EntityTrack.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityDumpTruck.Step;
|
_startPosY -= (int)EntityTrack.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//вправо
|
//вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + EntityDumpTruck.Step + _drawningDumpTrackWidth < _pictureWidth)
|
if (_startPosX.Value + EntityTrack.Step + _drawningTrackWidth < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityDumpTruck.Step;
|
_startPosX += (int)EntityTrack.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + EntityDumpTruck.Step + _drawningDumpTrackHeight < _pictureHeight)
|
if (_startPosY.Value + EntityTrack.Step + _drawningTrackHeight < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityDumpTruck.Step;
|
_startPosY += (int)EntityTrack.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -172,18 +211,18 @@ public class DrawningDumpTrack
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityDumpTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityTrack == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new SolidBrush(EntityDumpTruck.AdditionalColor);
|
|
||||||
|
|
||||||
//Отрисовка основы (кабины водителя и днища)
|
//Отрисовка основы (кабины водителя и днища)
|
||||||
Brush body = new SolidBrush(EntityDumpTruck.BodyColor);
|
Brush body = new SolidBrush(EntityTrack.BodyColor);
|
||||||
g.FillRectangle(body, _startPosX.Value + 100, _startPosY.Value, 30, 35);
|
g.FillRectangle(body, _startPosX.Value + 100, _startPosY.Value, 30, 35);
|
||||||
g.FillRectangle(body, _startPosX.Value, _startPosY.Value + 40, 130, 20);
|
g.FillRectangle(body, _startPosX.Value, _startPosY.Value + 40, 130, 20);
|
||||||
|
|
||||||
@ -201,21 +240,7 @@ public class DrawningDumpTrack
|
|||||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 60, 30, 30);
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 60, 30, 30);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 60, 30, 30);
|
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 60, 30, 30);
|
||||||
|
|
||||||
//Отрисовка кузова
|
|
||||||
if (EntityDumpTruck.Bodywork)
|
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 90, 35);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Отрисовка тента
|
|
||||||
if (EntityDumpTruck.Bodywork & EntityDumpTruck.Awning)
|
|
||||||
{
|
|
||||||
g.FillRectangle(border, _startPosX.Value, _startPosY.Value, 95, 10);
|
|
||||||
g.FillRectangle(border, _startPosX.Value, _startPosY.Value, 95, 3);
|
|
||||||
g.FillRectangle(border, _startPosX.Value+30, _startPosY.Value, 3, 40);
|
|
||||||
g.FillRectangle(border, _startPosX.Value+70, _startPosY.Value, 3, 40);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,25 +1,10 @@
|
|||||||
namespace ProjectDumpTruck;
|
namespace ProjectDumpTrack.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Самосвал"
|
/// Класс-сущность "Самосвал"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityDumpTruck
|
public class EntityDumpTrack : EntityTrack
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Скорость
|
|
||||||
/// </summary>
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вес
|
|
||||||
/// </summary>
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Основной цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -35,10 +20,7 @@ public class EntityDumpTruck
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Awning { get; private set; }
|
public bool Awning { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения самосвала
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса самосвала
|
/// Инициализация полей объекта-класса самосвала
|
||||||
@ -50,11 +32,8 @@ public class EntityDumpTruck
|
|||||||
/// <param name="bodywork">Признак наличия кузова</param>
|
/// <param name="bodywork">Признак наличия кузова</param>
|
||||||
/// <param name="awning">Признак наличия тента</param>
|
/// <param name="awning">Признак наличия тента</param>
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning)
|
public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning) : base(5, 45, Color.Black)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Bodywork = bodywork;
|
Bodywork = bodywork;
|
||||||
Awning = awning;
|
Awning = awning;
|
45
ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTrack.cs
Normal file
45
ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTrack.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTrack.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Грузовик"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityTrack
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private 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 EntityTrack(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,6 +34,9 @@
|
|||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
|
buttonCreateTrack = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTrack).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTrack).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -51,9 +54,9 @@
|
|||||||
buttonCreateDumpTrack.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateDumpTrack.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateDumpTrack.Location = new Point(12, 409);
|
buttonCreateDumpTrack.Location = new Point(12, 409);
|
||||||
buttonCreateDumpTrack.Name = "buttonCreateDumpTrack";
|
buttonCreateDumpTrack.Name = "buttonCreateDumpTrack";
|
||||||
buttonCreateDumpTrack.Size = new Size(94, 29);
|
buttonCreateDumpTrack.Size = new Size(210, 29);
|
||||||
buttonCreateDumpTrack.TabIndex = 1;
|
buttonCreateDumpTrack.TabIndex = 1;
|
||||||
buttonCreateDumpTrack.Text = "Создать";
|
buttonCreateDumpTrack.Text = "Создать грузовик с кузовом";
|
||||||
buttonCreateDumpTrack.UseVisualStyleBackColor = true;
|
buttonCreateDumpTrack.UseVisualStyleBackColor = true;
|
||||||
buttonCreateDumpTrack.Click += buttonCreateDumpTrack_Click;
|
buttonCreateDumpTrack.Click += buttonCreateDumpTrack_Click;
|
||||||
//
|
//
|
||||||
@ -105,11 +108,45 @@
|
|||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
buttonDown.Click += buttonMove_Click;
|
buttonDown.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateTrack
|
||||||
|
//
|
||||||
|
buttonCreateTrack.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateTrack.Location = new Point(238, 409);
|
||||||
|
buttonCreateTrack.Name = "buttonCreateTrack";
|
||||||
|
buttonCreateTrack.Size = new Size(210, 29);
|
||||||
|
buttonCreateTrack.TabIndex = 6;
|
||||||
|
buttonCreateTrack.Text = "Создать грузовик";
|
||||||
|
buttonCreateTrack.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateTrack.Click += buttonCreateTrack_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||||
|
comboBoxStrategy.Location = new Point(670, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(112, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
buttonStrategyStep.Location = new Point(721, 41);
|
||||||
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
buttonStrategyStep.Size = new Size(61, 22);
|
||||||
|
buttonStrategyStep.TabIndex = 8;
|
||||||
|
buttonStrategyStep.Text = "Шаг";
|
||||||
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||||
|
//
|
||||||
// FormTransport
|
// FormTransport
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonStrategyStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonCreateTrack);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
@ -130,5 +167,8 @@
|
|||||||
internal Button buttonRight;
|
internal Button buttonRight;
|
||||||
internal Button buttonUp;
|
internal Button buttonUp;
|
||||||
internal Button buttonDown;
|
internal Button buttonDown;
|
||||||
|
private Button buttonCreateTrack;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,8 @@
|
|||||||
/// <summary>
|
|
||||||
|
using ProjectDumpTrack.Drawnings;
|
||||||
|
using ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
/// Форма работы с объектом "Самосвал"
|
/// Форма работы с объектом "Самосвал"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
namespace ProjectDumpTruck
|
namespace ProjectDumpTruck
|
||||||
@ -8,14 +12,19 @@ namespace ProjectDumpTruck
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningDumpTrack? _drawningDumpTrack;
|
private DrawningTrack? _drawningTrack;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormTransport()
|
public FormTransport()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,36 +32,63 @@ namespace ProjectDumpTruck
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningDumpTrack == null)
|
if (_drawningTrack == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
|
Bitmap bmp = new(pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningDumpTrack.DrawTransport(gr);
|
_drawningTrack.DrawTransport(gr);
|
||||||
pictureBoxDumpTrack.Image = bmp;
|
pictureBoxDumpTrack.Image = bmp;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningTrack):
|
||||||
|
_drawningTrack = new DrawningTrack(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||||
|
break;
|
||||||
|
case nameof(DrawningDumpTrack):
|
||||||
|
_drawningTrack = new DrawningDumpTrack(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(1, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawningTrack.SetPictureSize(pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
|
||||||
|
_drawningTrack.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
_strategy = null;
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать грузовик с кузовом"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonCreateDumpTrack_Click(object sender, EventArgs e)
|
private void buttonCreateDumpTrack_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTrack));
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
_drawningDumpTrack = new DrawningDumpTrack();
|
|
||||||
_drawningDumpTrack.Init(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
|
|
||||||
_drawningDumpTrack.SetPictureSize(pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
|
/// <summary>
|
||||||
_drawningDumpTrack.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
/// Обработка нажатия кнопки "Создать грузовик"
|
||||||
|
/// </summary>
|
||||||
Draw();
|
/// <param name="sender"></param>
|
||||||
}
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateTrack_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrack));
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,7 +98,7 @@ namespace ProjectDumpTruck
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningDumpTrack == null)
|
if (_drawningTrack == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,16 +108,16 @@ namespace ProjectDumpTruck
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningDumpTrack.MoveTransport(DirectionType.Up);
|
result = _drawningTrack.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningDumpTrack.MoveTransport(DirectionType.Down);
|
result = _drawningTrack.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawningDumpTrack.MoveTransport(DirectionType.Left);
|
result = _drawningTrack.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningDumpTrack.MoveTransport(DirectionType.Right);
|
result = _drawningTrack.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
@ -89,5 +125,48 @@ namespace ProjectDumpTruck
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningTrack == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableTrack(_drawningTrack), pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,143 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-стратегия перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
////Абстрактный метод 3 задание
|
||||||
|
//public abstract void MyAbstractMethod();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObject? _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>
|
||||||
|
public StrategyStatus GetStatus() { return _state; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка данных
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
public void SetData(IMoveableObject 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 MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры объекта
|
||||||
|
/// </summary>
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Достигнута ли цель
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="movementDirection">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(MovementDirection movementDirection)
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс для работы с перемещаемым объектом
|
||||||
|
/// </summary>
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка переместить объект в указанном направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||||
|
bool TryMoveObject(MovementDirection direction);
|
||||||
|
|
||||||
|
////Интерфейс - задание 1
|
||||||
|
//void MyMethod();
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
////Абстрактный метод 3 задание
|
||||||
|
//public override void MyAbstractMethod()
|
||||||
|
//{
|
||||||
|
// Console.WriteLine("Implementation of abstract method in derived class");
|
||||||
|
//}
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
|
/// </summary>
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
////Абстрактный метод 3 задание
|
||||||
|
//public override void MyAbstractMethod()
|
||||||
|
//{
|
||||||
|
// Console.WriteLine("Implementation of abstract method in derived class");
|
||||||
|
//}
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
using ProjectDumpTrack.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-реализация IMoveableObject с использованием DrawningTrack
|
||||||
|
/// </summary>
|
||||||
|
public class MoveableTrack : IMoveableObject
|
||||||
|
{
|
||||||
|
////Интерфейс-задание 1
|
||||||
|
//public void MyMethod()
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект класса DrawningCar или его наследника
|
||||||
|
/// </summary>
|
||||||
|
private readonly DrawningTrack? _track = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="car">Объект класса DrawningCar</param>
|
||||||
|
public MoveableTrack(DrawningTrack track)
|
||||||
|
{
|
||||||
|
_track = track;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_track == null || _track.EntityTrack == null || !_track.GetPosX.HasValue || !_track.GetPosY.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_track.GetPosX.Value, _track.GetPosY.Value, _track.GetWidth, _track.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep => (int)(_track?.EntityTrack?.Step ?? 0);
|
||||||
|
|
||||||
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
|
{
|
||||||
|
if (_track == null || _track.EntityTrack == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _track.MoveTransport(GetDirectionType(direction));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертация из MovementDirection в DirectionType
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">MovementDirection</param>
|
||||||
|
/// <returns>DirectionType</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,25 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры-координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X
|
||||||
|
/// </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>
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int TopBorder => _y;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата 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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
namespace ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Все готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выполняется
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
using ProjectDumpTruck.MovementStrategy;
|
||||||
|
|
||||||
namespace ProjectDumpTruck
|
namespace ProjectDumpTruck
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -13,6 +15,14 @@ namespace ProjectDumpTruck
|
|||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormTransport());
|
Application.Run(new FormTransport());
|
||||||
|
|
||||||
|
|
||||||
|
////Àáñòðàêòíûé ìåòîä 3 çàäàíèå
|
||||||
|
//AbstractStrategy myObject1 = new MoveToBorder();
|
||||||
|
//myObject1.MyAbstractMethod();
|
||||||
|
|
||||||
|
//AbstractStrategy myObject2 = new MoveToCenter();
|
||||||
|
//myObject2.MyAbstractMethod();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user