using ProjectMonorail.Drawings; namespace ProjectMonorail.MovementStrategy; /// /// Класс-реализация IMoveableObject с использованием DrawingTrain /// public class MoveableTrain : IMovableObjects { /// /// Поле-объект класса DrawingTrain или его наследника /// private readonly DrawingTrain? _train = null; /// /// Конструктор /// /// Объект класса DrawingTrain public MoveableTrain(DrawingTrain train) { _train = train; } public ObjectParameters? GetObjectPosition { get { if(_train == null || _train.EntityTrain == null || !_train.GetPosX.HasValue || !_train.GetPosY.HasValue) { return null; } return new ObjectParameters(_train.GetPosX.Value, _train.GetPosY.Value, _train.GetWidth, _train.GetHeight); } } public int GetStep => (int)(_train?.EntityTrain?.Step ?? 0); public bool TryMoveObject(MovementDirection direction) { if (_train == null || _train.EntityTrain == null) { return false; } return _train.MoveTransport(GetDirectionType(direction)); } /// /// Конвертация из MovementDirection в DirectionType /// /// MovementDirection /// DirectionType 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.Unknown, }; } }