Example #1
0
    private void QuestionPhase()
    {
        _animationManager.PlayIdleAnimation();
        if (_questionRepeats.Count > 0)
        {
            _currentAnswerElements.Clear();
            Random randomQuestionIndex = new Random();
            Random randomAnswersIndex  = new Random();
            _currentQuestion         = _questionRepeats[randomQuestionIndex.Next(_questionRepeats.Count)].Question;
            QuestionText.text        = _currentQuestion.QuestionText;
            _currentQuestion.Answers = _currentQuestion.Answers.OrderBy(answer => randomAnswersIndex.Next()).ToList();
            foreach (Transform child in Content)
            {
                Destroy(child.gameObject);
            }
            foreach (Answer answer in _currentQuestion.Answers)
            {
                GameObject answerGameObject          = Instantiate(AnswerContentElementPrefab, Content);
                AnswerScrollViewElement answerScript = answerGameObject.GetComponent <AnswerScrollViewElement>();
                answerScript.SetAnswer(answer);
                _currentAnswerElements.Add(answerScript);
            }

            StartCoroutine(DecreaseQuestionTimer());

            SelectButton.onClick.RemoveAllListeners();
            SelectButton.onClick.AddListener(CheckAnswersPhase);
            SelectButtonText.text = "Wybierz Odpowiedzi";
        }
    }
Example #2
0
    private void CheckAnswersPhase()
    {
        foreach (AnswerScrollViewElement answer in _currentAnswerElements)
        {
            answer.AnswerToggle.interactable = false;
        }
        StopAllCoroutines();
        int numberOfAnswers        = _currentQuestion.Answers.Count;
        int numberOfMatchedAnswers = 0;
        int repeatsStructIndex     =
            _questionRepeats.FindIndex(_struct => _struct.Question == _currentQuestion);
        QuestionRepeatsStruct repeatsStruct = _questionRepeats[repeatsStructIndex];

        foreach (Answer answer in _currentQuestion.Answers)
        {
            AnswerScrollViewElement answerElement =
                _currentAnswerElements.Find(_answerElement => _answerElement.Answer == answer);
            if (answerElement.IsSelected == answer.IsCorrect)
            {
                numberOfMatchedAnswers++;
                if (answer.IsCorrect)
                {
                    answerElement.BackgroundImage.color = Color.green;
                }
                else
                {
                    answerElement.BackgroundImage.color = Color.white;
                }
            }
            else
            {
                answerElement.BackgroundImage.color = Color.red;
            }
        }

        if (numberOfAnswers == numberOfMatchedAnswers)
        {
            AudioManager.Instance.PlayCorrectSFX();
            _animationManager.PlayGoodAnswerAnimation();
            _goodAnswersNumber++;
            repeatsStruct.RepeatsLeft--;
        }
        else
        {
            if (OptionsManager.Instance.Vibrations)
            {
                Handheld.Vibrate();
            }
            AudioManager.Instance.PlayWrongSFX();
            _animationManager.PlayBadAnswerAnimation();
            repeatsStruct.RepeatsLeft = repeatsStruct.RepeatsLeft + OptionsManager.Instance.RepeatsPerQuestionsAtMistakeNumber;
            _allQuestionRepeats      += OptionsManager.Instance.RepeatsPerQuestionsAtMistakeNumber;
        }

        _questionRepeats[repeatsStructIndex] = repeatsStruct;

        if (_questionRepeats[repeatsStructIndex].RepeatsLeft == 0)
        {
            _questionRepeats.RemoveAt(repeatsStructIndex);
            _answeredQuestionsNumber++;
            _currentQuestion.IsAnswered = true;
            QuestionDataBaseManager.Instance.UpdateQuestionToAnswered(_selectedQuestionDataBase, _currentQuestion);
        }

        UpdateProgress();
        CheckIfWon();

        SelectButton.onClick.RemoveAllListeners();
        SelectButton.onClick.AddListener(QuestionPhase);
        SelectButtonText.text = "Kolejne Pytanie";
    }