using ProjectCruiser.DrawningSamples;
namespace ProjectCruiser.MoveStrategy;
// Класс-реализация IMoveableObject с использованием DrawningBase
public class MoveableTransport : IMoveableObj
{
// Поле-объект класса Drawning(Transport) или его наследника
private readonly DrawningBase? _car = null;
public MoveableTransport(DrawningBase car)
{
_car = car;
}
public ObjParameters? GetObjectPosition
{
get
{
if (_car == null || _car.EntityTransport == null ||
!_car.GetPosX.HasValue || !_car.GetPosY.HasValue)
{
return null;
}
return new ObjParameters(_car.GetPosX.Value,
_car.GetPosY.Value, _car.GetWidth, _car.GetHeight);
}
}
public int GetStep => (int)(_car?.EntityTransport?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_car == null || _car.EntityTransport == null)
{
return false;
}
return _car.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.Unknown,
};
}
}