2024-06-12 19:21:59 +04:00
|
|
|
|
using ProjectCruiser.DrawningSamples;
|
|
|
|
|
|
|
|
|
|
namespace ProjectCruiser.MoveStrategy;
|
2024-06-12 16:25:55 +04:00
|
|
|
|
|
|
|
|
|
// Класс-реализация 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
|
|
|
|
|
/// <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.Unknown,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|