PIbd-23 Yakobchuk S.V. LabWork_02 #2

Closed
sofia7ya wants to merge 13 commits from LabWork_02 into LabWork_01
Showing only changes of commit 810b4f70a6 - Show all commits

View File

@ -48,9 +48,21 @@ namespace Sailboat.DrawingObjects
/// </summary>
private readonly int _boatHeight = 160;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _boatWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _boatHeight;
/// <summary>
@ -114,6 +126,11 @@ namespace Sailboat.DrawingObjects
_startPosY = y;
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (EntityBoat == null)
@ -146,24 +163,28 @@ namespace Sailboat.DrawingObjects
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityBoat.Step > 0)
{
_startPosX -= (int)EntityBoat.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityBoat.Step > 0)
{
_startPosY -= (int)EntityBoat.Step;
}
break;
//вправо
case DirectionType.Right:
if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
{
_startPosX += (int)EntityBoat.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
{