示例#1
0
        public void Move(VehicleActions action)
        {
            if (!Enum.IsDefined(typeof(VehicleActions), action))
            {
                throw new NotValidException($"Vehicle action is not valid ({action.ToString()})", null);
            }

            switch (action)
            {
            case VehicleActions.L:
                Vehicle.Turn(RelativeDirections.Left);
                break;

            case VehicleActions.R:
                Vehicle.Turn(RelativeDirections.Right);
                break;

            case VehicleActions.M:
                Vehicle.Forward();
                CheckPosition();
                break;

            default:
                throw new Exception($"Vehicle action is not implemented [{action.ToString()}]");
            }
        }
示例#2
0
        public void Move(VehicleActions vehicleAction)
        {
            if (!Enum.IsDefined(typeof(VehicleActions), vehicleAction))
            {
                throw new VehicleActionIsNotValidException(vehicleAction.ToString());
            }

            switch (vehicleAction)
            {
            case VehicleActions.L:
                Vehicle.Turn(RelativeDirections.Left);
                break;

            case VehicleActions.R:
                Vehicle.Turn(RelativeDirections.Right);
                break;

            case VehicleActions.M:
                Vehicle.GoForward();
                bool positionIsInSurface = Surface.Contains(Vehicle.CurrentPoint);
                if (!positionIsInSurface)
                {
                    throw new VehicleConnectionLostException();
                }
                break;

            default:
                throw new DevelopmentException($"There is uncovered switch-case state [{vehicleAction.ToString()}]");
            }
        }