using lab1.Drawnings; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lab1.MovementStrategy; /// /// Класс-реализации IMoveableObject с использованием DrawingTrackedVenicle /// public class MoveableTrackedVehicle : IMoveableObject { /// /// Поле-объект класса DrawningTrackedVehicle или его наследников /// private readonly DrawningTrackedVehicle? _trackedVehicle = null; /// /// Конструктор /// /// Объект класса DrawningStormtrooperBase public MoveableTrackedVehicle(DrawningTrackedVehicle trackedVehicle) { _trackedVehicle = trackedVehicle; } public ObjectParameters? GetObjectPosition { get { if (_trackedVehicle == null || _trackedVehicle.EntityTrackedVehicle == null || !_trackedVehicle.GetPosX.HasValue || !_trackedVehicle.GetPosY.HasValue) { return null; } return new ObjectParameters(_trackedVehicle.GetPosX.Value, _trackedVehicle.GetPosY.Value, _trackedVehicle.GetWidth, _trackedVehicle.GetHeight); } } public int GetStep => (int)(_trackedVehicle?.EntityTrackedVehicle?.Step ?? 0); public bool TryMoveObject(MovementDirection direction) { if (_trackedVehicle == null || _trackedVehicle.EntityTrackedVehicle == null) { return false; } return _trackedVehicle.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, }; } }