2024-03-13 14:11:20 +04:00

67 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ProjectSeaplane.Drawnings;
namespace ProjectSeaplane.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием Seaplane
/// </summary>
public class MoveableSeaplane : IMoveableObject
{
/// <summary>
/// Поле-объект класса Seaplane или его наследника
/// </summary>
private readonly DrawingBasicSeaplane? _seaplane = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="seaplane">Объект класса Seaplane</param>
public MoveableSeaplane(DrawingBasicSeaplane Seaplane)
{
_seaplane = Seaplane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_seaplane == null || _seaplane.EntityBasicSeaplane == null || !_seaplane.GetPosX.HasValue || !_seaplane.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_seaplane.GetPosX.Value, _seaplane.GetPosY.Value, _seaplane.GetWidth, _seaplane.GetHeight);
}
}
public int GetStep => (int)(_seaplane?.EntityBasicSeaplane?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_seaplane == null || _seaplane.EntityBasicSeaplane == null)
{
return false;
}
return _seaplane.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.Unknown,
};
}
}