Beispiel #1
0
    /// <summary>
    /// reduces the amount of answers in each question to the specified amount
    /// </summary>
    /// <param name="questionCatalog"></param>
    /// <param name="newAnswerCount"></param>
    /// <returns></returns>
    public List <QuestionCard> TrimQuestions(List <QuestionCard> questionCatalog, int newAnswerCount, bool shuffleAnswers)
    {
        List <QuestionCard> newQuestionCatalog = new List <QuestionCard>(questionCatalog.Count);

        for (int i = 0; i < questionCatalog.Count; i++)
        {
            Debug.Log("before clone: " + questionCatalog[i].ToString());
            QuestionCard currentCard = (QuestionCard)questionCatalog[i].Clone();
            Debug.Log("after clone: " + currentCard.ToString());
            List <string> answers        = currentCard.Answers;
            int           amountToRemove = answers.Count - newAnswerCount;

            for (int removed = 0; removed < amountToRemove;)
            {
                int r = UnityEngine.Random.Range(0, answers.Count);

                if (r != currentCard.TrueAnswer)
                {
                    answers.RemoveAt(r);
                    removed++;
                }
            }

            if (shuffleAnswers)
            {
                currentCard.Reshuffle();
            }
            newQuestionCatalog.Add(currentCard);
        }

        return(newQuestionCatalog);
    }
Beispiel #2
0
    /// <summary>
    /// The Lamps glow for the set "glowTime" while reading the available Answers.
    /// The mesh filter changes from glowing to normal after the glowTime is finished.
    /// The User has the set time "answerTime" to think what the right answer is.
    /// The Lamp corresponding to the right answer glows up and the other Lamps and answers disappear (are disabled).
    /// </summary>
    /// <param name="q"></param>
    /// <returns></returns>
    IEnumerator AskQuestion(QuestionCard q)
    {
        q.Reshuffle();
        InitQuestionUI(q);

        yield return(new WaitForSeconds(conf.questionTime));

        bool correct = false;

        switch (conf.answeringMode)
        {
        case AnsweringMode.MOVE_X_AXIS:
        {
            Vector3 playerPosition = Vector3.zero;

            ToggleSlider(true);

            float remainingTime = conf.answerTime;
            countDownBar.enabled = true;
            countDownMask.gameObject.SetActive(true);
            while (remainingTime > 0f)
            {
                playerPosition = BodyDisplay.Instance.GetBodyPosition();
                float adjustedX = Mathf.Clamp(playerPosition.x, -1, 1f);

                if (conf.flipX)
                {
                    adjustedX *= -1;
                }

                adjustedX   *= 0.5f;
                adjustedX   += 0.5f;
                slider.value = adjustedX;

                remainingTime           -= Time.deltaTime;
                countDownMask.fillAmount = 1 - remainingTime / conf.answerTime;
                countDownText.text       = Mathf.RoundToInt(remainingTime).ToString();
                yield return(null);
            }

            //yield return timer.UITimer(answerTime, countDownMask, countDownText);

            countDownText.text   = "";
            countDownBar.enabled = false;
            countDownMask.gameObject.SetActive(false);
            ToggleSlider(false);

            correct = (q.TrueAnswer == 0) ?
                      playerPosition.x <= 0f :
                      playerPosition.x > 0f;
            break;
        }

        case AnsweringMode.RAISE_HANDS:
        {
            float remainingTime = conf.answerTime / 2f;
            countDownBar.enabled = true;
            countDownMask.gameObject.SetActive(true);
            while (remainingTime > 0f)
            {
                remainingTime           -= Time.deltaTime;
                countDownMask.fillAmount = 1 - remainingTime / conf.answerTime;
                countDownText.text       = Mathf.RoundToInt(remainingTime).ToString();
                yield return(null);
            }

            //yield return timer.UITimer(answerTime, countDownMask, countDownText);

            countDownText.text   = "";
            countDownBar.enabled = false;
            countDownMask.gameObject.SetActive(false);

            bool leftHandRaised  = BodyDisplay.Instance.JointCompare(JointId.Head, JointId.HandLeft, hRC);
            bool rightHandRaised = BodyDisplay.Instance.JointCompare(JointId.Head, JointId.HandRight, hRC);

            //Debug.Log("Left" + leftHandRaised);
            //Debug.Log("Right" + rightHandRaised);

            correct = (q.TrueAnswer == 0) ?
                      leftHandRaised && !rightHandRaised :
                      rightHandRaised && !leftHandRaised;

            break;
        }
        }

        answerFeedback.gameObject.SetActive(true);
        countDownBar.gameObject.SetActive(false);
        countDownText.gameObject.SetActive(false);

        if (correct)
        {
            answerFeedback.text = StringRes.Get("_RightAnswer");
            ConfettiBurst();
        }
        else
        {
            answerFeedback.text = StringRes.Get("_WrongAnswer");
        }

        for (int i = 0; i < q.Answers.Count; i++)
        {
            AnswerPanel p = panels[i];
            if (i != q.TrueAnswer)
            {
                p.gameObject.SetActive(false);
            }
        }

        centerImg.gameObject.SetActive(false);

        yield return(new WaitForSeconds(conf.showCorrectAnswerTime));

        answerFeedback.gameObject.SetActive(false);
        countDownBar.gameObject.SetActive(true);
        countDownText.gameObject.SetActive(true);
    }