using ProjectElectroTrans.Drawnings; using ProjectSportCar.Drawnings; namespace ProjectElectroTrans.MovementStrategy; public class MoveableTrans : IMoveableObject { /// /// Поле-объект класса DrawningTrans или его наследника /// private readonly DrawingTrans? _trans = null; /// /// Конструктор /// /// Объект класса DrawningTrans public MoveableTrans(DrawingTrans trans) { _trans = trans; } public ObjectParameters? GetObjectPosition { get { if (_trans == null || _trans.EntityTrans == null || !_trans.GetPosX.HasValue || !_trans.GetPosY.HasValue) { return null; } return new ObjectParameters(_trans.GetPosX.Value, _trans.GetPosY.Value, _trans.GetWidth, _trans.GetHeight); } } public int GetStep => (int)(_trans?.EntityTrans?.Step ?? 0); public bool TryMoveObject(MovementDirection direction) { if (_trans == null || _trans.EntityTrans == null) { return false; } return _trans.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.Unknow, }; } }