67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
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,
|
||
};
|
||
}
|
||
}
|