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