using ProjectCruiser.Drawnings;
namespace ProjectCruiser.MovementStrategy
{
///
/// класс реалтзация для IMoveableObject с использованием DrawningCruiser
///
public class MoveableCruiser : IMoveableObject
{
///
/// Поле-объект класса DrawningCruiser или его наследника
///
private readonly DrawningCruiser? _cruiser = null;
///
/// Конструктор
///
/// Объект класса DrawningCruiser
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));
}
///
/// Конвертация из MovementDirection в DirectionType
///
/// MovementDirection
/// DirectionType
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,
};
}
}
}