2024-03-15 00:32:50 +04:00

59 lines
1.7 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 ProjectDumpTruck.Drawnings;
namespace ProjectDumpTruck.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningTruck
/// </summary>
public class MoveableTruck : IMoveableObject
{
private DrawningTruck? _truck=null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="truck">Объект класса DrawningTruck</param>
public MoveableTruck(DrawningTruck? truck)
{
_truck = truck;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_truck == null||_truck.EntityTruck == null|| !_truck.GetPosX.HasValue|| !_truck.GetPosY.HasValue)
return null;
return new ObjectParameters(_truck.GetPosX.Value, _truck.GetPosY.Value, _truck.GetWidth, _truck.GetHeight);
}
}
public int GetStep => (int)(_truck?.EntityTruck?.Step ?? 0);
/// <summary>
/// Конвертация из MovementDirection в DirectionType
/// </summary>
/// <param name="direction">MovementDirection</param>
/// <returns>DirectionType</returns>
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
_ => DirectionType.Unknow
};
}
public bool TryMoveableObject(MovementDirection direction)
{
if (_truck == null || _truck.EntityTruck == null) return false;
return _truck.MoveTransport(GetDirectionType(direction));
}
}