diff --git a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs index 1e4298e..96bc3fc 100644 --- a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs @@ -38,40 +38,6 @@ namespace ProjectExcavator.DrawningObjects /// protected readonly int _excavatorHeight = 80; /// - /// Координата X объекта - /// - public int GetPosX => _startPosX; - /// - /// Координата Y объекта - /// - public int GetPosY => _startPosY; - /// Ширина объекта - /// - public int GetWidth => _excavatorWidth; - /// - /// Высота объекта - /// - public int GetHeight => _excavatorHeight; - /// - /// Конструктор - /// - /// Скорость - /// Вес - /// Основной цвет - /// Ширина картинки - /// Высота картинки - public DrawningExcavator(int speed, double weight, Color bodyColor, int - width, int height) - { - if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth) - { - return; - } - _pictureWidth = width; - _pictureHeight = height; - EntityExcavator = new EntityExcavator(speed, weight, bodyColor); - } - /// /// Конструктор /// /// Скорость @@ -88,13 +54,13 @@ namespace ProjectExcavator.DrawningObjects { _pictureWidth = width; _pictureHeight = height; - _excavatorWidth = excavatorWidth; - _excavatorHeight = excavatorHeight; - if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth) + if(_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth) { - return; + return false; } - EntityExcavator = new EntityExcavator(speed, weight, bodyColor); + EntityExcavator = new EntityExcavator(); + EntityExcavator.Init(speed, weight, bodyColor, additionalColor, bodyKit, backet); + return true; } /// /// Установка позиции @@ -103,32 +69,11 @@ namespace ProjectExcavator.DrawningObjects /// Координата Y public void SetPosition(int x, int y) { + _startPosX = Math.Min(x,_pictureWidth - _excavatorWidth); _startPosY = Math.Min(y,_pictureHeight - _excavatorHeight); - } - /// - /// Проверка, что объект может переместится по указанному направлению - /// - /// Направление - /// true - можно переместится по указанному направлению - public bool CanMove(DirectionType direction) - { - if(EntityExcavator == null) - { - return false; - } - return direction switch - { - //влево - DirectionType.Left => _startPosX - EntityExcavator.Step >0, - //вверх - DirectionType.Up => _startPosY - EntityExcavator.Step > 0, - //вправо - DirectionType.Right => _startPosX + EntityExcavator.Step < _pictureWidth - _excavatorWidth, - //вниз - DirectionType.Down => _startPosY + EntityExcavator.Step < _pictureHeight - _excavatorHeight, - _ => false, - }; + + } /// /// Изменение направления перемещения @@ -148,7 +93,10 @@ namespace ProjectExcavator.DrawningObjects break; //вверх case DirectionType.Up: - _startPosY -= (int)EntityExcavator.Step; + if (_startPosY - EntityExcavator.Step > 0) + { + _startPosY -= (int)EntityExcavator.Step; + } break; // вправо case DirectionType.Right: @@ -156,7 +104,10 @@ namespace ProjectExcavator.DrawningObjects break; //вниз case DirectionType.Down: - _startPosY += (int)EntityExcavator.Step; + if (_startPosY + EntityExcavator.Step < _pictureHeight - _excavatorHeight) + { + _startPosY += (int)EntityExcavator.Step; + } break; } } @@ -171,6 +122,12 @@ namespace ProjectExcavator.DrawningObjects return; } Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityExcavator.AdditionalColor); + if (EntityExcavator.BodyKit) + { + g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 70, 130, 10); + g.DrawLine(pen, _startPosX + 20, _startPosY + 70, _startPosX + 150, _startPosY + 70); + } //корпус Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor); g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 60, 130, 20); @@ -196,7 +153,17 @@ namespace ProjectExcavator.DrawningObjects g.DrawEllipse(pen, _startPosX + 80, _startPosY + 80, 20, 20); g.DrawEllipse(pen, _startPosX + 100, _startPosY + 80, 20, 20); g.DrawEllipse(pen, _startPosX + 120, _startPosY + 80, 20, 20); - + //ковш + if (EntityExcavator.Backet) + { + Point[] pointsBacket = { + new Point(_startPosX + 150, _startPosY + 25), + new Point(_startPosX + 150, _startPosY + 85), + new Point(_startPosX + 195, _startPosY + 85), + }; + g.FillPolygon(additionalBrush, pointsBacket); + g.DrawPolygon(pen, pointsBacket); + } } } } diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs index 4a0a157..c2acec2 100644 --- a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs @@ -30,7 +30,11 @@ namespace ProjectExcavator.Entities /// Скорость /// Вес экскаватора /// Основной цвет - public EntityExcavator(int speed, double weight, Color bodyColor) + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool bodyKit, bool backet) { Speed = speed; Weight = weight;