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/DirectionType.cs b/Excavator/Excavator/Drawnings/DirectionType.cs similarity index 100% rename from Excavator/Excavator/DirectionType.cs rename to Excavator/Excavator/Drawnings/DirectionType.cs 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..cd4fb06 --- /dev/null +++ b/Excavator/Excavator/Drawnings/DrawningSimpleExcavator.cs @@ -0,0 +1,264 @@ +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; + + /// + /// Пустой конструктор + /// + 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..4bc84c9 100644 --- a/Excavator/Excavator/FormExcavator.Designer.cs +++ b/Excavator/Excavator/FormExcavator.Designer.cs @@ -34,6 +34,7 @@ buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); + buttonCreateSimpleExcavator = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit(); SuspendLayout(); // @@ -51,9 +52,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 +63,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 +75,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 +87,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 +99,30 @@ 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; + // // FormExcavator // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(923, 597); + Controls.Add(buttonCreateSimpleExcavator); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); @@ -130,5 +143,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button buttonCreateSimpleExcavator; } } \ No newline at end of file diff --git a/Excavator/Excavator/FormExcavator.cs b/Excavator/Excavator/FormExcavator.cs index f6cd833..d645e7d 100644 --- a/Excavator/Excavator/FormExcavator.cs +++ b/Excavator/Excavator/FormExcavator.cs @@ -1,4 +1,6 @@ -namespace Excavator; +using Excavator.Drawnings; + +namespace Excavator; /// /// Форма работы с объектом "Экскаватор" @@ -8,7 +10,7 @@ public partial class FormExcavator : Form /// /// Поле-объект для прорисовки объекта /// - private DrawningExcavator? _drawningExcavator; + private DrawningSimpleExcavator? _drawningSimpleExcavator; /// /// Конструктор формы @@ -17,39 +19,72 @@ public partial class FormExcavator : Form { InitializeComponent(); } - + /// /// Метод прорисовки экскаватора /// 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 +94,7 @@ public partial class FormExcavator : Form /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningExcavator == null) + if (_drawningSimpleExcavator == null) { return; } @@ -69,16 +104,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; }