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