예제 #1
0
    public void MakeDecision(SequenceChoice choice)
    {
        if (choice == null)
        {
            Debug.LogWarning("Sequence ended with null decision, Ending scene");
            sequenceOver = true;             // This sequence should no longer be playing
            parentScene.EndScene();          // No choice made, can't continue so end the scene
        }

        choice.eventsForChoice.Invoke();          // Invoke any handlers for this choice

        if (choice.nextSequence != null)
        {
            sequenceOver = true;             // This sequence should no longer be playing
            choice.nextSequence.Play();      // Start up the next sequence
        }
        else
        {
            defaultAction.eventsForChoice.Invoke();              // Invoke any default events
            if (defaultAction.nextSequence != null)
            {
                sequenceOver = true;
                defaultAction.nextSequence.Play();
            }
            else
            {
                sequenceOver = true;
                parentScene.EndScene();
            }
        }
    }
예제 #2
0
        public void Start(string[] args)
        {
            Log.Logger.Information($"Starting app");

            int from,
                to;

            while (_fibbonacciUserInterface.IsRun())
            {
                try
                {
                    Log.Logger.Information($"User is inputting parametrs");

                    if (args.Length != 0)
                    {
                        if (args.Length > SEQUENCE_PARAMETRS)
                        {
                            throw new ArgumentException();
                        }

                        from = ConvertInput(args[0]);
                        to   = ConvertInput(args[1]);

                        Array.Clear(args, 0, args.Length);
                    }
                    else
                    {
                        from = ConvertInput(_fibbonacciUserInterface.GetInputFromUser(UIMessages.INPUT_FROM_NUMBER));
                        to   = ConvertInput(_fibbonacciUserInterface.GetInputFromUser(UIMessages.INPUT_TO_NUMBER));
                    }

                    Log.Logger.Information($"Successfully converted parametrs into int");

                    SequenceChoice choice = _fibbonacciUserInterface.GetSequenceChoiceFromUser();

                    ISequence sequence = GetSequenceByChoice(choice, from, to);


                    _fibbonacciUserInterface.Display(sequence);
                }
                catch (ArgumentException ex)
                {
                    Log.Logger.Warning($"Exception {ex.Message}");
                    _fibbonacciUserInterface.DisplayErrorMessage(ex.Message);
                }
                catch (FormatException ex)
                {
                    _fibbonacciUserInterface.DisplayErrorMessage(ex.Message);
                    Log.Logger.Warning($"Exception {ex.Message}");
                }
            }
        }
예제 #3
0
        private ISequence GetSequenceByChoice(SequenceChoice choice, int from, int to)
        {
            Log.Logger.Information($"Creating a sequence");

            SequenceValidator validator = new SequenceValidator();

            ISequence fibbonacci = new FibbonacciSequence(from, to);
            ISequence square     = new SquareSequence(from, to);

            Log.Logger.Information($"Validating a sequence");
            switch (choice)
            {
            case SequenceChoice.Fibbonacci:
                if (validator.Validate(fibbonacci).IsValid)
                {
                    Log.Logger.Information($"Fibbonacci sequence created and validated");
                    return(fibbonacci);
                }

                Log.Logger.Information($"Validation error");
                throw new ArgumentException(UIMessages.INVALID_ARGUMENTS);

            case SequenceChoice.Square:
                if (validator.Validate(fibbonacci).IsValid)
                {
                    Log.Logger.Information($"Square sequence created and validated");
                    return(square);
                }
                Log.Logger.Information($"Validation error");
                throw new ArgumentException(UIMessages.INVALID_ARGUMENTS);

            default:
                Log.Logger.Information($"There is no sequene with this type");

                throw new ArgumentException(UIMessages.INVALID_TYPE_OFSEQUENCE);
            }
        }