diff --git a/Excavator/Excavator/DrawningExcavator.cs b/Excavator/Excavator/DrawningExcavator.cs deleted file mode 100644 index e2d84c7..0000000 --- a/Excavator/Excavator/DrawningExcavator.cs +++ /dev/null @@ -1,302 +0,0 @@ -using System.Net.Sockets; - -namespace Excavator; - -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawningExcavator -{ - /// - /// Класс-сущность - /// - public EntityExcavator? EntityExcavator { get; private set; } - - /// - /// Ширина окна - /// - private int? _pictureWidth; - - /// - /// Высота окна - /// - private int? _pictureHeight; - - /// - /// Левая координата прорисовки экскаваторя - /// - private int? _startPosX; - - /// - /// Верхняя кооридната прорисовки экскаваторя - /// - private int? _startPosY; - - /// - /// Ширина прорисовки экскаватора - /// - private readonly int _drawningExcavatorWidth = 145; - - /// - /// Высота прорисовки экскаватора - /// - private readonly int _drawningExcavatorHeight = 100; - - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - public void Init(int speed, double weight, Color bodyColor, Color additionalColor,bool supports, bool bucket) - { - EntityExcavator = new EntityExcavator(); - EntityExcavator.Init(speed, weight, bodyColor, additionalColor, supports, bucket); - _pictureWidth = null; - _pictureHeight = null; - _startPosX = null; - _startPosY = null; - } - - /// - /// Установка границ поля - /// - /// Ширина поля - /// Высота поля - /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах - - public bool SetPictureSize(int width, int height) - { - if (width > _drawningExcavatorWidth && height > _drawningExcavatorHeight) - { - _pictureWidth = width; - _pictureHeight = height; - if (_startPosX != null && _startPosY != null) - { - if (_startPosX.Value + _drawningExcavatorWidth > _pictureWidth) - { - _startPosX = _pictureWidth - _drawningExcavatorWidth; - } - if (_startPosY.Value + _drawningExcavatorHeight > _pictureHeight) - { - _startPosY = _pictureHeight - _drawningExcavatorHeight; - } - } - - return true; - } - return false; - } - - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return; - } - _startPosX = x; - _startPosY = y; - - if (_drawningExcavatorWidth + _startPosX > _pictureWidth) - { - _startPosX = _pictureWidth - _drawningExcavatorWidth; - } - if (_drawningExcavatorHeight + _startPosY > _pictureHeight) - { - _startPosY = _pictureHeight - _drawningExcavatorHeight; - } - } - - /// - /// Изменение направления перемещения - /// - /// Направление - /// true - перемещене выполнено, false - перемещение невозможно - public bool MoveTransport(DirectionType direction) - { - if (EntityExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue) - { - return false; - } - - switch (direction) - { - //влево - case DirectionType.Left: - if (_startPosX.Value - EntityExcavator.Step > 0) - { - _startPosX -= (int)EntityExcavator.Step; - } - return true; - //вверх - case DirectionType.Up: - if (_startPosY.Value - EntityExcavator.Step > 0) - { - _startPosY -= (int)EntityExcavator.Step; - } - return true; - // вправо - case DirectionType.Right: - if (_startPosX.Value + _drawningExcavatorWidth + EntityExcavator.Step < _pictureWidth) - { - _startPosX += (int)EntityExcavator.Step; - } - return true; - //вниз - case DirectionType.Down: - if (_startPosY.Value + _drawningExcavatorHeight + EntityExcavator.Step < _pictureHeight) - { - _startPosY += (int)EntityExcavator.Step; - } - return true; - default: - return false; - } - } - - /// - /// Прорисовка объекта - /// - /// - public void DrawTransport(Graphics g) - { - if (EntityExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue) - { - return; - } - - Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityExcavator.AdditionalColor); - - // Ковш - if(EntityExcavator.Bucket) - { - - Point[] pointBucket1 = - { - new Point(_startPosX.Value + 90, _startPosY.Value + 50), - new Point(_startPosX.Value + 90, _startPosY.Value), - new Point(_startPosX.Value + 135, _startPosY.Value), - new Point(_startPosX.Value + 135, _startPosY.Value + 30), - new Point(_startPosX.Value + 125, _startPosY.Value + 30), - new Point(_startPosX.Value + 125, _startPosY.Value + 10), - new Point(_startPosX.Value + 105, _startPosY.Value + 10), - new Point(_startPosX.Value + 105, _startPosY.Value + 45), - new Point(_startPosX.Value + 100, _startPosY.Value + 50), - new Point(_startPosX.Value + 90, _startPosY.Value + 50), - }; - g.FillPolygon(additionalBrush, pointBucket1); - g.DrawPolygon(pen, pointBucket1); - - Point[] pointBucket2 = - { - new Point(_startPosX.Value + 125, _startPosY.Value + 30), - new Point(_startPosX.Value + 135, _startPosY.Value+ 30), - new Point(_startPosX.Value + 145, _startPosY.Value + 40), - new Point(_startPosX.Value + 145, _startPosY.Value + 60), - new Point(_startPosX.Value + 140, _startPosY.Value + 70), - new Point(_startPosX.Value + 120, _startPosY.Value + 70), - new Point(_startPosX.Value + 125, _startPosY.Value + 60), - new Point(_startPosX.Value + 125, _startPosY.Value + 30), - }; - Brush br1 = new SolidBrush(Color.FromArgb(100, 100, 100)); - g.FillPolygon(br1, pointBucket2); - g.DrawPolygon(pen, pointBucket2); - } - - // Гусеницы - Brush brGrey = new SolidBrush(Color.FromArgb(100, 100, 100)); - Brush br = new SolidBrush(EntityExcavator.BodyColor); - - g.FillEllipse(brGrey, _startPosX.Value + 30, _startPosY.Value + 75, 25, 25); - g.FillEllipse(brGrey, _startPosX.Value + 75, _startPosY.Value + 75, 25, 25); - g.FillRectangle(brGrey, _startPosX.Value + 40, _startPosY.Value + 75, 50, 25); - - Rectangle rect1 = new Rectangle(_startPosX.Value + 30, _startPosY.Value + 75, 25, 25); - g.DrawArc(pen, rect1, 90, 180); - Rectangle rect2 = new Rectangle(_startPosX.Value + 75, _startPosY.Value + 75, 25, 25); - g.DrawArc(pen, rect2, 270, 180); - g.DrawLine(pen, _startPosX.Value + 40, _startPosY.Value + 100, _startPosX.Value + 90, _startPosY.Value + 100); - - - g.FillEllipse(br, _startPosX.Value + 33, _startPosY.Value + 78, 18, 18); - g.FillEllipse(br, _startPosX.Value + 78, _startPosY.Value + 78, 18, 18); - g.FillEllipse(br, _startPosX.Value + 51, _startPosY.Value + 89, 7, 7); - g.FillEllipse(br, _startPosX.Value + 61, _startPosY.Value + 89, 7, 7); - g.FillEllipse(br, _startPosX.Value + 71, _startPosY.Value + 89, 7, 7); - g.FillEllipse(br, _startPosX.Value + 57, _startPosY.Value + 81, 4, 4); - g.FillEllipse(br, _startPosX.Value + 69, _startPosY.Value + 81, 4, 4); - - g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 78, 18, 18); - g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 78, 18, 18); - g.DrawEllipse(pen, _startPosX.Value + 51, _startPosY.Value + 89, 7, 7); - g.DrawEllipse(pen, _startPosX.Value + 61, _startPosY.Value + 89, 7, 7); - g.DrawEllipse(pen, _startPosX.Value + 71, _startPosY.Value + 89, 7, 7); - g.DrawEllipse(pen, _startPosX.Value + 57, _startPosY.Value + 81, 4, 4); - g.DrawEllipse(pen, _startPosX.Value + 69, _startPosY.Value + 81, 4, 4); - - // Корпус - Point[] pointBody1 = - { - new Point(_startPosX.Value + 30, _startPosY.Value + 75), - new Point(_startPosX.Value + 30, _startPosY.Value + 50), - new Point(_startPosX.Value + 70, _startPosY.Value + 50), - new Point(_startPosX.Value + 70, _startPosY.Value + 20), - new Point(_startPosX.Value + 100, _startPosY.Value + 20), - new Point(_startPosX.Value + 100, _startPosY.Value + 75), - new Point(_startPosX.Value + 30, _startPosY.Value + 75), - }; - g.FillPolygon(br, pointBody1); - g.DrawPolygon(pen, pointBody1); - g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 25, 10, 25); - g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 25, 10, 25); - g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 25, 10, 25); - - // Окно - Brush brLBlue = new SolidBrush(Color.LightBlue); - - g.FillRectangle(brLBlue, _startPosX.Value + 72, _startPosY.Value + 22, 26, 26); - g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 22, 26, 26); - - // Опоры - if (EntityExcavator.Supports) - { - Point[] pointSupport1 = - { - new Point(_startPosX.Value + 10, _startPosY.Value + 100), - new Point(_startPosX.Value + 20, _startPosY.Value + 100), - new Point(_startPosX.Value + 50, _startPosY.Value + 70), - new Point(_startPosX.Value + 50, _startPosY.Value + 60), - new Point(_startPosX.Value + 30, _startPosY.Value + 60), - new Point(_startPosX.Value + 10, _startPosY.Value + 100), - }; - g.FillPolygon(additionalBrush, pointSupport1); - g.DrawPolygon(pen, pointSupport1); - g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 95, 30, 5); - g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 95, 30, 5); - - Point[] pointSupport2 = - { - new Point(_startPosX.Value + 120, _startPosY.Value + 100), - new Point(_startPosX.Value + 110, _startPosY.Value + 100), - new Point(_startPosX.Value + 80, _startPosY.Value + 70), - new Point(_startPosX.Value + 80, _startPosY.Value + 60), - new Point(_startPosX.Value + 100, _startPosY.Value + 60), - new Point(_startPosX.Value + 120, _startPosY.Value + 100), - }; - g.FillPolygon(additionalBrush, pointSupport2); - g.DrawPolygon(pen, pointSupport2); - g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5); - g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5); - } - - } -} \ No newline at end of file diff --git a/Excavator/Excavator/Drawnings/DirectionType.cs b/Excavator/Excavator/Drawnings/DirectionType.cs new file mode 100644 index 0000000..c1ae261 --- /dev/null +++ b/Excavator/Excavator/Drawnings/DirectionType.cs @@ -0,0 +1,32 @@ +namespace Excavator; + +/// +/// Направление перемещения +/// +public enum DirectionType +{ + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + /// Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4, + + /// + /// Неизвестное направление + /// + Unknow = -1 +} diff --git a/Excavator/Excavator/Drawnings/DrawningExcavator.cs b/Excavator/Excavator/Drawnings/DrawningExcavator.cs new file mode 100644 index 0000000..a4a5464 --- /dev/null +++ b/Excavator/Excavator/Drawnings/DrawningExcavator.cs @@ -0,0 +1,110 @@ +using System.Net.Sockets; +using System.Security.Cryptography.X509Certificates; +using Excavator.Drawnings; +using Excavator.Entities; + +namespace Excavator.Drawnings; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningExcavator : DrawningSimpleExcavator +{ + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + public DrawningExcavator(int speed, double weight, Color bodyColor, Color additionalColor,bool supports, bool bucket) : base(145, 100) + { + EntitySimpleExcavator = new EntityExcavator(speed, weight, bodyColor, additionalColor, supports, bucket); + + } + + public override void DrawTransport(Graphics g) + { + if (EntitySimpleExcavator == null || EntitySimpleExcavator is not EntityExcavator excavator || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(excavator.AdditionalColor); + + // Ковш + if (excavator.Bucket) + { + + Point[] pointBucket1 = + { + new Point(_startPosX.Value + 90, _startPosY.Value + 50), + new Point(_startPosX.Value + 90, _startPosY.Value), + new Point(_startPosX.Value + 135, _startPosY.Value), + new Point(_startPosX.Value + 135, _startPosY.Value + 30), + new Point(_startPosX.Value + 125, _startPosY.Value + 30), + new Point(_startPosX.Value + 125, _startPosY.Value + 10), + new Point(_startPosX.Value + 105, _startPosY.Value + 10), + new Point(_startPosX.Value + 105, _startPosY.Value + 45), + new Point(_startPosX.Value + 100, _startPosY.Value + 50), + new Point(_startPosX.Value + 90, _startPosY.Value + 50), + }; + g.FillPolygon(additionalBrush, pointBucket1); + g.DrawPolygon(pen, pointBucket1); + + Point[] pointBucket2 = + { + new Point(_startPosX.Value + 125, _startPosY.Value + 30), + new Point(_startPosX.Value + 135, _startPosY.Value+ 30), + new Point(_startPosX.Value + 145, _startPosY.Value + 40), + new Point(_startPosX.Value + 145, _startPosY.Value + 60), + new Point(_startPosX.Value + 140, _startPosY.Value + 70), + new Point(_startPosX.Value + 120, _startPosY.Value + 70), + new Point(_startPosX.Value + 125, _startPosY.Value + 60), + new Point(_startPosX.Value + 125, _startPosY.Value + 30), + }; + Brush br1 = new SolidBrush(Color.FromArgb(100, 100, 100)); + g.FillPolygon(br1, pointBucket2); + g.DrawPolygon(pen, pointBucket2); + } + // Опоры + if (excavator.Supports) + { + Point[] pointSupport1 = + { + new Point(_startPosX.Value + 10, _startPosY.Value + 100), + new Point(_startPosX.Value + 20, _startPosY.Value + 100), + new Point(_startPosX.Value + 50, _startPosY.Value + 70), + new Point(_startPosX.Value + 50, _startPosY.Value + 60), + new Point(_startPosX.Value + 30, _startPosY.Value + 60), + new Point(_startPosX.Value + 10, _startPosY.Value + 100), + }; + g.FillPolygon(additionalBrush, pointSupport1); + g.DrawPolygon(pen, pointSupport1); + g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 95, 30, 5); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 95, 30, 5); + + Point[] pointSupport2 = + { + new Point(_startPosX.Value + 120, _startPosY.Value + 100), + new Point(_startPosX.Value + 110, _startPosY.Value + 100), + new Point(_startPosX.Value + 80, _startPosY.Value + 70), + new Point(_startPosX.Value + 80, _startPosY.Value + 60), + new Point(_startPosX.Value + 100, _startPosY.Value + 60), + new Point(_startPosX.Value + 120, _startPosY.Value + 100), + }; + g.FillPolygon(additionalBrush, pointSupport2); + g.DrawPolygon(pen, pointSupport2); + g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5); + g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5); + } + _startPosY += 20; + _startPosX += 30; + base.DrawTransport(g); + _startPosY -= 20; + _startPosX -= 30; + } +} \ No newline at end of file diff --git a/Excavator/Excavator/Drawnings/DrawningSimpleExcavator.cs b/Excavator/Excavator/Drawnings/DrawningSimpleExcavator.cs new file mode 100644 index 0000000..1ad2b49 --- /dev/null +++ b/Excavator/Excavator/Drawnings/DrawningSimpleExcavator.cs @@ -0,0 +1,284 @@ +using Excavator.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excavator.Drawnings; + +public class DrawningSimpleExcavator +{ + + /// + /// Класс-сущность + /// + public EntitySimpleExcavator? EntitySimpleExcavator { get; protected set; } + + /// + /// Ширина окна + /// + private int? _pictureWidth; + + /// + /// Высота окна + /// + private int? _pictureHeight; + + /// + /// Левая координата прорисовки экскаваторя + /// + protected int? _startPosX; + + /// + /// Верхняя кооридната прорисовки экскаваторя + /// + protected int? _startPosY; + + /// + /// Ширина прорисовки экскаватора + /// + private readonly int _drawningExcavatorWidth = 70; + + /// + /// Высота прорисовки экскаватора + /// + private readonly int _drawningExcavatorHeight = 80; + + /// + /// Координата X объекта + /// + public int? GetPosX => _startPosX; + + /// + /// Координата Y объекта + /// + public int? GetPosY => _startPosY; + + /// + /// Ширина объекта + /// + public int GetWidth => _drawningExcavatorWidth; + + /// + /// Высота объекта + /// + public int GetHeight => _drawningExcavatorHeight; + + /// + /// Пустой конструктор + /// + private DrawningSimpleExcavator() + { + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningSimpleExcavator(int speed, double weight, Color bodyColor) : this() + { + EntitySimpleExcavator = new EntitySimpleExcavator(speed, weight, bodyColor); + + } + +/// +/// Конструктор для наследников +/// +/// Ширина прорисовки экскаватора +/// Высота прорисовки экскаватора + public DrawningSimpleExcavator(int drawningExcavatorWidth, int drawningExcavatorHeight) : this() + { + _drawningExcavatorWidth = drawningExcavatorWidth; + _drawningExcavatorHeight = drawningExcavatorHeight; + + } + + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + + public bool SetPictureSize(int width, int height) + { + if (width > _drawningExcavatorWidth && height > _drawningExcavatorHeight) + { + _pictureWidth = width; + _pictureHeight = height; + if (_startPosX != null && _startPosY != null) + { + if (_startPosX.Value + _drawningExcavatorWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _drawningExcavatorWidth; + } + if (_startPosY.Value + _drawningExcavatorHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawningExcavatorHeight; + } + } + + return true; + } + return false; + } + + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + _startPosX = x; + _startPosY = y; + + if (_drawningExcavatorWidth + _startPosX > _pictureWidth) + { + _startPosX = _pictureWidth - _drawningExcavatorWidth; + } + if (_drawningExcavatorHeight + _startPosY > _pictureHeight) + { + _startPosY = _pictureHeight - _drawningExcavatorHeight; + } + if (_startPosX < 0) + { + _startPosX = 0; + } + if (_startPosY < 0) + { + _startPosY = 0; + } + + } + + /// + /// Изменение направления перемещения + /// + /// Направление + /// true - перемещене выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntitySimpleExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntitySimpleExcavator.Step > 0) + { + _startPosX -= (int)EntitySimpleExcavator.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntitySimpleExcavator.Step > 0) + { + _startPosY -= (int)EntitySimpleExcavator.Step; + } + return true; + // вправо + case DirectionType.Right: + if (_startPosX.Value + _drawningExcavatorWidth + EntitySimpleExcavator.Step < _pictureWidth) + { + _startPosX += (int)EntitySimpleExcavator.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + _drawningExcavatorHeight + EntitySimpleExcavator.Step < _pictureHeight) + { + _startPosY += (int)EntitySimpleExcavator.Step; + } + return true; + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + public virtual void DrawTransport(Graphics g) + { + if (EntitySimpleExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + + + // Гусеницы + Brush brGrey = new SolidBrush(Color.FromArgb(100, 100, 100)); + Brush br = new SolidBrush(EntitySimpleExcavator.BodyColor); + + g.FillEllipse(brGrey, _startPosX.Value, _startPosY.Value + 55, 25, 25); + g.FillEllipse(brGrey, _startPosX.Value + 45, _startPosY.Value + 55, 25, 25); + g.FillRectangle(brGrey, _startPosX.Value + 10, _startPosY.Value + 55, 50, 25); + + Rectangle rect1 = new Rectangle(_startPosX.Value, _startPosY.Value + 55, 25, 25); + g.DrawArc(pen, rect1, 90, 180); + Rectangle rect2 = new Rectangle(_startPosX.Value + 45, _startPosY.Value + 55, 25, 25); + g.DrawArc(pen, rect2, 270, 180); + g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 80, _startPosX.Value + 60, _startPosY.Value + 80); + + + g.FillEllipse(br, _startPosX.Value + 3, _startPosY.Value + 58, 18, 18); + g.FillEllipse(br, _startPosX.Value + 48, _startPosY.Value + 58, 18, 18); + g.FillEllipse(br, _startPosX.Value + 21, _startPosY.Value + 69, 7, 7); + g.FillEllipse(br, _startPosX.Value + 31, _startPosY.Value + 69, 7, 7); + g.FillEllipse(br, _startPosX.Value + 41, _startPosY.Value + 69, 7, 7); + g.FillEllipse(br, _startPosX.Value + 27, _startPosY.Value + 61, 4, 4); + g.FillEllipse(br, _startPosX.Value + 39, _startPosY.Value + 61, 4, 4); + + g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 58, 18, 18); + g.DrawEllipse(pen, _startPosX.Value + 48, _startPosY.Value + 58, 18, 18); + g.DrawEllipse(pen, _startPosX.Value + 21, _startPosY.Value + 69, 7, 7); + g.DrawEllipse(pen, _startPosX.Value + 31, _startPosY.Value + 69, 7, 7); + g.DrawEllipse(pen, _startPosX.Value + 41, _startPosY.Value + 69, 7, 7); + g.DrawEllipse(pen, _startPosX.Value + 27, _startPosY.Value + 61, 4, 4); + g.DrawEllipse(pen, _startPosX.Value + 39, _startPosY.Value + 61, 4, 4); + + // Корпус + Point[] pointBody1 = + { + new Point(_startPosX.Value, _startPosY.Value + 55), + new Point(_startPosX.Value, _startPosY.Value + 30), + new Point(_startPosX.Value + 40, _startPosY.Value + 30), + new Point(_startPosX.Value + 40, _startPosY.Value), + new Point(_startPosX.Value + 70, _startPosY.Value), + new Point(_startPosX.Value + 70, _startPosY.Value + 55), + new Point(_startPosX.Value, _startPosY.Value + 55), + }; + g.FillPolygon(br, pointBody1); + g.DrawPolygon(pen, pointBody1); + g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 5, 10, 25); + g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 5, 10, 25); + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 5, 10, 25); + + // Окно + Brush brLBlue = new SolidBrush(Color.LightBlue); + + g.FillRectangle(brLBlue, _startPosX.Value + 42, _startPosY.Value + 2, 26, 26); + g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 2, 26, 26); + + + } + +} diff --git a/Excavator/Excavator/EntityExcavator.cs b/Excavator/Excavator/Entities/EntityExcavator.cs similarity index 51% rename from Excavator/Excavator/EntityExcavator.cs rename to Excavator/Excavator/Entities/EntityExcavator.cs index 2836c8f..f02217a 100644 --- a/Excavator/Excavator/EntityExcavator.cs +++ b/Excavator/Excavator/Entities/EntityExcavator.cs @@ -1,25 +1,11 @@ -namespace Excavator; +namespace Excavator.Entities; /// /// Класс-сущность "Экскаватор" /// -public class EntityExcavator +public class EntityExcavator : EntitySimpleExcavator { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - + /// /// Дополнительный цвет (для опциональных элементов) /// @@ -36,16 +22,17 @@ public class EntityExcavator public bool Bucket { get; private set; } /// - /// Шаг перемещения экскаватора + /// Конструктор сущности /// - public double Step => Speed * 100 / Weight; - - - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool supports, bool bucket) + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Опоры + /// Ковш + public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool supports, bool bucket) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; + AdditionalColor = additionalColor; Supports = supports; Bucket = bucket; diff --git a/Excavator/Excavator/Entities/EntitySimpleExcavator.cs b/Excavator/Excavator/Entities/EntitySimpleExcavator.cs new file mode 100644 index 0000000..26d3806 --- /dev/null +++ b/Excavator/Excavator/Entities/EntitySimpleExcavator.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; + +namespace Excavator.Entities; + +/// +/// Класс-сущность "Экскаватор" +/// +public class EntitySimpleExcavator +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Шаг перемещения экскаватора + /// + public double Step => Speed * 100 / Weight; + + /// + /// Конструктор сущности + /// + /// + /// + /// + public EntitySimpleExcavator(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/Excavator/Excavator/FormExcavator.Designer.cs b/Excavator/Excavator/FormExcavator.Designer.cs index d315652..a652b92 100644 --- a/Excavator/Excavator/FormExcavator.Designer.cs +++ b/Excavator/Excavator/FormExcavator.Designer.cs @@ -34,6 +34,9 @@ buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); + buttonCreateSimpleExcavator = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit(); SuspendLayout(); // @@ -51,9 +54,9 @@ buttonCreateExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateExcavator.Location = new Point(12, 562); buttonCreateExcavator.Name = "buttonCreateExcavator"; - buttonCreateExcavator.Size = new Size(75, 23); + buttonCreateExcavator.Size = new Size(217, 23); buttonCreateExcavator.TabIndex = 1; - buttonCreateExcavator.Text = "Создать"; + buttonCreateExcavator.Text = "Создать экскаватор с обвесами"; buttonCreateExcavator.UseVisualStyleBackColor = true; buttonCreateExcavator.Click += ButtonCreateExcavator_Click; // @@ -62,7 +65,7 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(740, 535); + buttonLeft.Location = new Point(749, 535); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(50, 50); buttonLeft.TabIndex = 2; @@ -74,7 +77,7 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.arrowUp; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(796, 479); + buttonUp.Location = new Point(805, 479); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(50, 50); buttonUp.TabIndex = 3; @@ -86,7 +89,7 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.arrowDown; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(796, 535); + buttonDown.Location = new Point(805, 535); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(50, 50); buttonDown.TabIndex = 4; @@ -98,18 +101,53 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.arrowRight; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(852, 535); + buttonRight.Location = new Point(861, 535); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(50, 50); buttonRight.TabIndex = 5; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // + // buttonCreateSimpleExcavator + // + buttonCreateSimpleExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateSimpleExcavator.Location = new Point(235, 562); + buttonCreateSimpleExcavator.Name = "buttonCreateSimpleExcavator"; + buttonCreateSimpleExcavator.Size = new Size(217, 23); + buttonCreateSimpleExcavator.TabIndex = 6; + buttonCreateSimpleExcavator.Text = "Создать экскаватор "; + buttonCreateSimpleExcavator.UseVisualStyleBackColor = true; + buttonCreateSimpleExcavator.Click += ButtonCreateSimpleExcavator_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю " }); + comboBoxStrategy.Location = new Point(790, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.TabIndex = 7; + // + // buttonStrategyStep + // + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStrategyStep.Location = new Point(790, 41); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(121, 23); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += ButtonStrategyStep_Click; + // // FormExcavator // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(923, 597); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonCreateSimpleExcavator); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); @@ -130,5 +168,8 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button buttonCreateSimpleExcavator; + private ComboBox comboBoxStrategy; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/Excavator/Excavator/FormExcavator.cs b/Excavator/Excavator/FormExcavator.cs index f6cd833..27aa00b 100644 --- a/Excavator/Excavator/FormExcavator.cs +++ b/Excavator/Excavator/FormExcavator.cs @@ -1,4 +1,8 @@ -namespace Excavator; +using Excavator.Drawnings; +using Excavator.Entities; +using Excavator.MovementSrtategy; + +namespace Excavator; /// /// Форма работы с объектом "Экскаватор" @@ -8,7 +12,9 @@ public partial class FormExcavator : Form /// /// Поле-объект для прорисовки объекта /// - private DrawningExcavator? _drawningExcavator; + private DrawningSimpleExcavator? _drawningSimpleExcavator; + + private AbstractStrategy? _strategy; /// /// Конструктор формы @@ -16,40 +22,74 @@ public partial class FormExcavator : Form public FormExcavator() { InitializeComponent(); + _strategy = null; } - + /// /// Метод прорисовки экскаватора /// private void Draw() { - if (_drawningExcavator == null) + if (_drawningSimpleExcavator == null) { return; } Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningExcavator.DrawTransport(gr); + _drawningSimpleExcavator.DrawTransport(gr); pictureBoxExcavator.Image = bmp; } /// - /// Обработка нажатия кнопки "Создать" + /// Создание объекта + /// + /// + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawningSimpleExcavator): + _drawningSimpleExcavator = new DrawningSimpleExcavator(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(DrawningExcavator): + _drawningSimpleExcavator = new DrawningExcavator(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(1, 2))); + break; + default: + return; + } + + _drawningSimpleExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height); + _drawningSimpleExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _strategy = null; + //comboBoxStrategy.Enabled = true; + Draw(); + + } + + /// + /// Обработка нажатия кнопки "Создать экскаватор с обвесами" /// /// /// private void ButtonCreateExcavator_Click(object sender, EventArgs e) { - Random random = new(); - _drawningExcavator = new DrawningExcavator(); - _drawningExcavator.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))); - _drawningExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height); - _drawningExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); + CreateObject(nameof(DrawningExcavator)); + } + + /// + /// Обработка нажатия кнопки "Создать экскаватор" + /// + /// + /// + private void ButtonCreateSimpleExcavator_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningSimpleExcavator)); } /// @@ -59,7 +99,7 @@ public partial class FormExcavator : Form /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningExcavator == null) + if (_drawningSimpleExcavator == null) { return; } @@ -69,16 +109,16 @@ public partial class FormExcavator : Form switch (name) { case "buttonUp": - result = _drawningExcavator.MoveTransport(DirectionType.Up); + result = _drawningSimpleExcavator.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningExcavator.MoveTransport(DirectionType.Down); + result = _drawningSimpleExcavator.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningExcavator.MoveTransport(DirectionType.Left); + result = _drawningSimpleExcavator.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningExcavator.MoveTransport(DirectionType.Right); + result = _drawningSimpleExcavator.MoveTransport(DirectionType.Right); break; } @@ -87,4 +127,47 @@ public partial class FormExcavator : Form Draw(); } } + /// + /// Обработка нажатия кнопки "Шаг" + /// + /// + /// + private void ButtonStrategyStep_Click(object sender, EventArgs e) + { + if (_drawningSimpleExcavator == null) + { + return; + } + + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) + { + return; + } + _strategy.SetData(new MoveableSimpleExcavator(_drawningSimpleExcavator), pictureBoxExcavator.Width, pictureBoxExcavator.Height); + } + + if (_strategy == null) + { + return; + } + + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + + if (_strategy.GetStatus() == StrategyStatus.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } + } \ No newline at end of file diff --git a/Excavator/Excavator/MovementSrtategy/AbstractStrategy.cs b/Excavator/Excavator/MovementSrtategy/AbstractStrategy.cs new file mode 100644 index 0000000..237a4b5 --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/AbstractStrategy.cs @@ -0,0 +1,139 @@ +using Excavator.MovementStrategy; + +namespace Excavator.MovementSrtategy; + +public abstract class AbstractStrategy +{ + /// + /// Перемещаемый объект + /// + private IMoveableObject? _moveableObject; + + /// + /// Статус перемещения + /// + private StrategyStatus _state = StrategyStatus.NotInit; + + /// + /// Ширина поля + /// + protected int FieldWidth { get; private set; } + + /// + /// Высота поля + /// + protected int FieldHeight { get; private set; } + + /// + /// Статус перемещения + /// + public StrategyStatus GetStatus() { return _state; } + + /// + /// Установка данных + /// + /// Перемещаемый объект + /// Ширина поля + /// Высота поля + 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; + } + + /// + /// Шаг перемещения + /// + public void MakeStep() + { + if (_state != StrategyStatus.InProgress) + { + return; + } + + if (IsTargetDestinaion()) + { + _state = StrategyStatus.Finish; + return; + } + + MoveToTarget(); + } + + /// + /// Перемещение влево + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveLeft() => MoveTo(MovementDirection.Left); + + /// + /// Перемещение вправо + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveRight() => MoveTo(MovementDirection.Right); + + /// + /// Перемещение вверх + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveUp() => MoveTo(MovementDirection.Up); + + /// + /// Перемещение вниз + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveDown() => MoveTo(MovementDirection.Down); + + /// + /// Параметры объекта + /// + protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectParameters; + + /// + /// Шаг объекта + /// + /// + protected int? GetStep() + { + if (_state != StrategyStatus.InProgress) + { + return null; + } + return _moveableObject?.GetStep; + } + + /// + /// Перемещение к цели + /// + protected abstract void MoveToTarget(); + + /// + /// Достигнута ли цель + /// + /// + protected abstract bool IsTargetDestinaion(); + + /// + /// Попытка перемещения в требуемом направлении + /// + /// Направление + /// Результат попытки (true - удалось переместиться, false - неудача) + private bool MoveTo(MovementDirection movementDirection) + { + if (_state != StrategyStatus.InProgress) + { + return false; + } + + return _moveableObject?.TryMoveObject(movementDirection) ?? false; + } +} + diff --git a/Excavator/Excavator/MovementSrtategy/IMoveableObject.cs b/Excavator/Excavator/MovementSrtategy/IMoveableObject.cs new file mode 100644 index 0000000..6e56817 --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/IMoveableObject.cs @@ -0,0 +1,24 @@ +using Excavator.MovementStrategy; + +namespace Excavator.MovementSrtategy; + +public interface IMoveableObject +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectParameters { get; } + + /// + /// Шаг + /// + int GetStep { get; } + + /// + /// Попытка перемстить объект + /// + /// Направление + /// + bool TryMoveObject(MovementDirection direction); + +} diff --git a/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs b/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs new file mode 100644 index 0000000..51ab69f --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs @@ -0,0 +1,39 @@ +namespace Excavator.MovementSrtategy; + +public class MoveToBorder : AbstractStrategy +{ + /// + /// Стратегия перемещения объекта к Краю экрана + /// + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder + GetStep() >= FieldWidth && + 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()) + { + MoveRight(); + } + + int diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + MoveDown(); + } + } +} + diff --git a/Excavator/Excavator/MovementSrtategy/MoveToCenter.cs b/Excavator/Excavator/MovementSrtategy/MoveToCenter.cs new file mode 100644 index 0000000..66cbae5 --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/MoveToCenter.cs @@ -0,0 +1,55 @@ +namespace Excavator.MovementSrtategy; + +/// +/// Стратегия перемещения объекта в центр экрана +/// +public class MoveToCenter : AbstractStrategy +{ + 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(); + } + } + } +} + diff --git a/Excavator/Excavator/MovementSrtategy/MoveableSimpleExcavator.cs b/Excavator/Excavator/MovementSrtategy/MoveableSimpleExcavator.cs new file mode 100644 index 0000000..e40dd29 --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/MoveableSimpleExcavator.cs @@ -0,0 +1,65 @@ +using Excavator.Drawnings; +using Excavator.MovementStrategy; + +namespace Excavator.MovementSrtategy; + +/// +/// Класс-реализация IMoveableObject с использованием Drawningexcavator +/// +public class MoveableSimpleExcavator : IMoveableObject +{ + /// + /// Поле-объект класса Drawningexcavator или его наследника + /// + private readonly DrawningSimpleExcavator? _excavator = null; + + /// + /// Конструктор + /// + /// Объект класса Drawningexcavator + public MoveableSimpleExcavator(DrawningSimpleExcavator excavator) + { + _excavator = excavator; + } + + public ObjectParameters? GetObjectParameters + { + get + { + if (_excavator == null || _excavator.EntitySimpleExcavator == null || !_excavator.GetPosX.HasValue || !_excavator.GetPosY.HasValue) + { + return null; + } + return new ObjectParameters(_excavator.GetPosX.Value, _excavator.GetPosY.Value, _excavator.GetWidth, _excavator.GetHeight); + } + } + + public int GetStep => (int)(_excavator?.EntitySimpleExcavator?.Step ?? 0); + + public bool TryMoveObject(MovementDirection direction) + { + if (_excavator == null || _excavator.EntitySimpleExcavator == null) + { + return false; + } + + return _excavator.MoveTransport(GetDirectionType(direction)); + } + + /// + /// Конвертация из MovementDirection в DirectionType + /// + /// MovementDirection + /// DirectionType + 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, + }; + } +} diff --git a/Excavator/Excavator/DirectionType.cs b/Excavator/Excavator/MovementSrtategy/MovementDirection.cs similarity index 83% rename from Excavator/Excavator/DirectionType.cs rename to Excavator/Excavator/MovementSrtategy/MovementDirection.cs index 9302014..68bbaee 100644 --- a/Excavator/Excavator/DirectionType.cs +++ b/Excavator/Excavator/MovementSrtategy/MovementDirection.cs @@ -1,9 +1,9 @@ -namespace Excavator; +namespace Excavator.MovementStrategy; /// /// Направление перемещения /// -public enum DirectionType +public enum MovementDirection { /// /// Вверх @@ -24,4 +24,4 @@ public enum DirectionType /// Вправо /// Right = 4 -} +} \ No newline at end of file diff --git a/Excavator/Excavator/MovementSrtategy/ObjectParameters.cs b/Excavator/Excavator/MovementSrtategy/ObjectParameters.cs new file mode 100644 index 0000000..6ac5eea --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/ObjectParameters.cs @@ -0,0 +1,70 @@ + +namespace Excavator.MovementSrtategy; + +public class ObjectParameters +{ + /// + /// Координата Х + /// + private readonly int _x; + + /// + /// Координата Y + /// + private readonly int _y; + + /// + /// Высота объекта + /// + private readonly int _width; + + /// + /// Ширина объекта + /// + private readonly int _height; + + /// + /// Левая граница + /// + public int LeftBorder => _x; + + /// + /// Верхняя граница + /// + public int TopBorder => _y; + + /// + /// Правая граница + /// + public int RightBorder => _x + _width; + + /// + /// Нижняя граница + /// + public int DownBorder => _y + _height; + + /// + /// Середина объекта + /// + public int ObjectMiddleHorizontal => _x + _width / 2; + + /// + /// Середина объекта + /// + public int ObjectMiddleVertical => _y + _height / 2; + + /// + /// Конструктор + /// + /// + /// + /// + /// + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } +} diff --git a/Excavator/Excavator/MovementSrtategy/StrategyStatus.cs b/Excavator/Excavator/MovementSrtategy/StrategyStatus.cs new file mode 100644 index 0000000..b94874d --- /dev/null +++ b/Excavator/Excavator/MovementSrtategy/StrategyStatus.cs @@ -0,0 +1,21 @@ +namespace Excavator.MovementSrtategy; + + +public enum StrategyStatus +{ + /// + /// Всё готово к началу + /// + NotInit, + + /// + /// Выполняется + /// + InProgress, + + /// + /// Завершено + /// + Finish + +}