using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun.MovementStrategy;
public class MoveableAircraftGun: IMoveableObject
{
///
/// Поле-объект класса DrawningAircraftGun или его наследника
///
private readonly DrawningAircraftGun? _drawningAircraftGun = null;
///
/// Конструктор
///
/// Объект класса DrawningTrans
public MoveableAircraftGun(DrawningAircraftGun trans)
{
_drawningAircraftGun = trans;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null ||
!_drawningAircraftGun.GetPosX.HasValue || !_drawningAircraftGun.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_drawningAircraftGun.GetPosX.Value,
_drawningAircraftGun.GetPosY.Value, _drawningAircraftGun.GetWidth, _drawningAircraftGun.GetHeight);
}
}
public int GetStep => (int)(_drawningAircraftGun?.EntityAircraftGun?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null)
{
return false;
}
return _drawningAircraftGun.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,
};
}
}