PIbd-13_Ladyagin_P.D._Simple/AirplaneWithRadar/ProjectAirplaneWithRadar/MovementStrategy/MoveablePlane.cs

65 lines
2.2 KiB
C#
Raw Permalink Normal View History

using ProjectAirplaneWithRadar.Drawnings;
namespace ProjectAirplaneWithRadar.MovementStrategy
{
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningAirplane
/// </summary>
public class MoveablePlane : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningAirplane или его наследника
/// </summary>
private readonly DrawningAirplane? _airplane = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="airplane">Объект класса DrawningAirplane</param>
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));
}
/// <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,
2024-03-23 15:58:03 +04:00
_ => DirectionType.Unknow
};
}
}
}