diff --git a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs index 89bb3aa..24ec2c8 100644 --- a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs @@ -65,16 +65,19 @@ namespace ProjectExcavator.DrawningObjects /// Основной цвет /// Ширина картинки /// Высота картинки - public DrawningExcavator(int speed, double weight, Color bodyColor, int - width, int height) + public DrawningExcavator(int speed, double weight, + Color bodyColor, + int width, int height) { - if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth) + _pictureWidth = width; + _pictureHeight = height; + if(_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth) { return; } _pictureWidth = width; _pictureHeight = height; - EntityExcavator = new EntityExcavator(speed, weight, bodyColor); + EntityExcavator = new EntityExcavator(speed,weight,bodyColor); } /// /// Конструктор @@ -86,9 +89,9 @@ namespace ProjectExcavator.DrawningObjects /// Высота картинки /// Ширина прорисовки экскаватора /// Высота прорисовки экскаватора - protected DrawningExcavator(int speed, double weight, - Color bodyColor, - int width, int height, + protected DrawningExcavator(int speed, double weight, + Color bodyColor, + int width, int height, int excavatorWidth, int excavatorHeight) { _pictureWidth = width; @@ -108,8 +111,11 @@ namespace ProjectExcavator.DrawningObjects /// Координата Y public void SetPosition(int x, int y) { + _startPosX = Math.Min(x,_pictureWidth - _excavatorWidth); _startPosY = Math.Min(y,_pictureHeight - _excavatorHeight); + + } /// /// Проверка, что объект может переместится по указанному направлению @@ -118,14 +124,14 @@ namespace ProjectExcavator.DrawningObjects /// true - можно переместится по указанному направлению public bool CanMove(DirectionType direction) { - if(EntityExcavator == null) + if (EntityExcavator == null) { return false; } return direction switch { //влево - DirectionType.Left => _startPosX - EntityExcavator.Step >0, + DirectionType.Left => _startPosX - EntityExcavator.Step > 0, //вверх DirectionType.Up => _startPosY - EntityExcavator.Step > 0, //вправо @@ -153,7 +159,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: @@ -161,7 +170,10 @@ namespace ProjectExcavator.DrawningObjects break; //вниз case DirectionType.Down: - _startPosY += (int)EntityExcavator.Step; + if (_startPosY + EntityExcavator.Step < _pictureHeight - _excavatorHeight) + { + _startPosY += (int)EntityExcavator.Step; + } break; } } @@ -201,7 +213,7 @@ 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); - + } } }