예제 #1
0
    /* private void EndGame() */

    /// <name>
    /// CheckAnswer
    /// </name>
    /// <summary>
    /// Checks the answer to the math problem given by the user.
    /// If correct, a new math problem is generated.
    /// </summary>
    /// <author>
    /// Sabrina Hemming
    /// </author>
    /// <date>
    /// 4/22/18
    /// </date>
    private void CheckAnswer()
    {
        // get the number entered by the user.
        // don't really need to validate it's a number because the input
        // field only allows integers
        int input;

        int.TryParse(inputFieldCO.text, out input);

        if (input == equation.Sum)
        {
            // generate a new math problem & update display
            correctAnswers++;
            equation.GenerateNewEquation();
            mathProblem.text  = equation.EquationString;
            inputFieldCO.text = string.Empty;
            inputFieldCO.ActivateInputField();

            // update score on the screen
            currentScore.text = correctAnswers.ToString();
        }
        else
        {
            // highlights incorrect input so user can immediately type new answer
            inputFieldCO.ActivateInputField();
        }
    }
예제 #2
0
    /* void Update () */

    /// <name>
    /// CheckAnswer
    /// </name>
    /// <summary>
    /// Checks the answer to the math problem given by the user.
    /// If correct, a new math problem is generated.
    /// </summary>
    /// <author>
    /// Sabrina Hemming
    /// </author>
    /// <date>
    /// 3/2/18
    /// </date>
    void CheckAnswer()
    {
        // get the number entered by the user.
        // don't really need to validate it's a number because the input
        // field only allows integers
        int input;

        int.TryParse(InputFieldCO.text, out input);

        if (input == equation.Sum)
        {
            // user answered correctly

            // play animation of treasure chest opening & coin going into scor
            chestScript.Animate(Constants.Addition.CHEST_OPEN_ANIMATION);

            // play animation of coin going into score - wait until animation finishes
            StartCoroutine(coinScript.AnimateAndWait(Constants.Addition.COIN_EARNED_ANIMATION));

            // generate a new math problem & update display
            additionGame.correctAnswers++;
            equation.GenerateNewEquation();
            mathProblem.text  = equation.EquationString;
            InputFieldCO.text = string.Empty;
            InputFieldCO.ActivateInputField();

            // if player answers 10 questions right, they move to the next level
            if (additionGame.correctAnswers % 10 == 0)
            {
                equation.IncreaseLevel();
                additionGame.level = equation.Level;
            }

            // update score on the screen
            score.text = additionGame.correctAnswers.ToString();
        }
        else
        {
            // user answered incorrectly
            InputFieldCO.ActivateInputField();
            chestScript.Animate(Constants.Addition.CHEST_LOCKED_ANIMATION);
        }
    }