ISEbd-11_Rozhkova_D.S./ProjectStormtrooper/MovementStrategy/MoveableAirplane.cs
2024-05-07 01:50:39 +04:00

52 lines
1.8 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 ProjectStormtrooper.Drawnings;
namespace ProjectStormtrooper.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningCar
/// </summary>
public class MoveableAirplane : IMoveableObject
{
private DrawningAirplane? _drawningairplane;
public MoveableAirplane(DrawningAirplane? drawningairplane)
{
_drawningairplane = drawningairplane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningairplane == null || _drawningairplane.EntityAirplane == null || !_drawningairplane.GetPosX.HasValue || !_drawningairplane.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_drawningairplane.GetPosX.Value, _drawningairplane.GetPosY.Value, _drawningairplane.GetWidth, _drawningairplane.GetHeight);
}
}
public int GetStep => (int)(_drawningairplane?.EntityAirplane?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_drawningairplane == null || _drawningairplane.EntityAirplane == null)
{
return false;
}
return _drawningairplane.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.Unknow,
};
}
}