ISEbd-12_Sinelnikova_A.V._S.../ProjectCruiser/MovementStrategy/MoveableCruiser.cs

63 lines
2.2 KiB
C#
Raw Permalink Normal View History

2024-03-07 09:46:27 +04:00
using ProjectCruiser.Drawnings;
namespace ProjectCruiser.MovementStrategy
{
/// <summary>
/// класс реалтзация для IMoveableObject с использованием DrawningCruiser
/// </summary>
public class MoveableCruiser : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningCruiser или его наследника
/// </summary>
private readonly DrawningCruiser? _cruiser = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="cruiser">Объект класса DrawningCruiser</param>
public MoveableCruiser(DrawningCruiser cruiser)
{
_cruiser = cruiser;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_cruiser == null || _cruiser.EntityCruiser == null ||
!_cruiser.GetPosX.HasValue || !_cruiser.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_cruiser.GetPosX.Value,
_cruiser.GetPosY.Value, _cruiser.GetWidth, _cruiser.GetHeight);
}
}
public int GetStep => (int)(_cruiser?.EntityCruiser?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_cruiser == null || _cruiser.EntityCruiser == null)
{
return false;
}
return _cruiser.MoveTransport(GetDirectionType(direction));
}
/// <summary>
/// Конвертация из MovementDirection в DirectionType
/// </summary>
/// <param name="direction">MovementDirection</param>
/// <returns>DirectionType</returns>
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
_ => DirectionType.Unknow,
};
}
}
}