using ProjectStormtrooper.Drawnings; namespace ProjectStormtrooper.MovementStrategy; /// /// Класс-реализации IMoveableObject с использованием DrawingStormtrooperBase /// public class MoveableStormtrooperBase : IMoveableObject { /// /// Поле-объект класса DrawningStormtrooperBase или его наследников /// private readonly DrawningStormtrooperBase? _stormtrooper = null; /// /// Конструктор /// /// Объект класса DrawningStormtrooperBase public MoveableStormtrooperBase(DrawningStormtrooperBase Stormtrooper) { _stormtrooper = Stormtrooper; } public ObjectParameters? GetObjectPosition { get { if (_stormtrooper == null || _stormtrooper.EntityStormtrooperBase == null || !_stormtrooper.GetPosX.HasValue || !_stormtrooper.GetPosY.HasValue) { return null; } return new ObjectParameters(_stormtrooper.GetPosX.Value,_stormtrooper.GetPosY.Value,_stormtrooper.GetWidth,_stormtrooper.GetHeight); } } public int GetStep => (int)(_stormtrooper?.EntityStormtrooperBase?.Step ?? 0); public bool TryMoveObject(MovementDirection direction) { if (_stormtrooper == null || _stormtrooper.EntityStormtrooperBase == null) { return false; } return _stormtrooper.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, }; } }