PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/MoveStrategy/MoveableTransport.cs
2024-06-12 19:21:59 +04:00

57 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 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
/// <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,
};
}
}