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