Merge branch 'lab_3' into lab_4

This commit is contained in:
SooNooClose 2023-11-04 13:45:06 +04:00
commit 4dc6007cc5

View File

@ -65,16 +65,19 @@ namespace ProjectExcavator.DrawningObjects
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
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);
}
/// <summary>
/// Конструктор
@ -86,9 +89,9 @@ namespace ProjectExcavator.DrawningObjects
/// <param name="height">Высота картинки</param>
/// <param name="excavatorWidth">Ширина прорисовки экскаватора</param>
/// <param name="excavatorHeight">Высота прорисовки экскаватора</param>
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
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
_startPosX = Math.Min(x,_pictureWidth - _excavatorWidth);
_startPosY = Math.Min(y,_pictureHeight - _excavatorHeight);
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
@ -118,14 +124,14 @@ namespace ProjectExcavator.DrawningObjects
/// <returns>true - можно переместится по указанному направлению</returns>
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);
}
}
}