52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
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,
|
||
};
|
||
}
|
||
}
|