Exemplo n.º 1
0
    public void AddStudentGameNewScores(string GameOwneruserid, string userid, string UniqueQuestionId, StudentScores studentscore)
    {
        Debug.Log("Add student's game user score into database");
        Debug.Log("Call Score manager to add data");
        crudscore.AddStudentGameNewScores(GameOwneruserid, userid, UniqueQuestionId, studentscore);

        crudscore.getUserScoreForStudentGame(GameOwneruserid, userid, UniqueQuestionId, printSuccessMsg);
    }
    IEnumerator GenerateQuestions()
    {
        call = false;
        crudquestion.getStudentGameQuestion(gameID, callbackFunc2);

        yield return(new WaitUntil(() => call == true));


        int totalQuestion = questionList.Length;

        NumQuestions = 10;
        if (NumQuestions > totalQuestion) //If not enough questions from the database
        {
            question.text  = "Not enough question set for this chapter.";
            Time.timeScale = 0;
        }
        else
        {
            int rightOption = 0;
            for (int i = 0; i < NumQuestions; i++)
            {
                question.text = questionList[i].question.question;
                int random = Random.Range(1, 4);
                if (random == 1)
                {
                    answer1.text = questionList[i].question.ans1;
                    answer2.text = questionList[i].question.ans2;
                    answer3.text = questionList[i].question.ans3;
                    answer4.text = questionList[i].question.ans4;
                }
                else if (random == 2)
                {
                    answer1.text = questionList[i].question.ans2;
                    answer2.text = questionList[i].question.ans3;
                    answer3.text = questionList[i].question.ans1;
                    answer4.text = questionList[i].question.ans4;
                }
                else if (random == 3)
                {
                    answer1.text = questionList[i].question.ans3;
                    answer2.text = questionList[i].question.ans2;
                    answer3.text = questionList[i].question.ans4;
                    answer4.text = questionList[i].question.ans1;
                }
                else
                {
                    answer1.text = questionList[i].question.ans3;
                    answer2.text = questionList[i].question.ans1;
                    answer3.text = questionList[i].question.ans4;
                    answer4.text = questionList[i].question.ans2;
                }

                string rightAnswer = questionList[i].question.correctAns;

                if (rightAnswer == answer1.text)
                {
                    rightOption = 1;
                }
                else if (rightAnswer == answer2.text)
                {
                    rightOption = 2;
                }
                else if (rightAnswer == answer3.text)
                {
                    rightOption = 3;
                }
                else if (rightAnswer == answer4.text)
                {
                    rightOption = 4;
                }
                yield return(new WaitForSeconds(4.2f));

                if (rightOption == userChoice)
                {
                    Debug.Log("Correct.");
                    score++;
                    Score.text = score.ToString();
                    point.Play();
                    yield return(new WaitForSeconds(1.8f));
                }
                else
                {
                    Debug.Log("Wrong. Right Option " + rightOption);
                    setCharacterMovement(character, true);

                    fail.Play();
                    yield return(new WaitForSeconds(0.6f));

                    setCharacterMovement(character, false);
                    yield return(new WaitForSeconds(1.2f));
                }
                Debug.Log("Total Marks " + score);
            }
            // GETTING attempt  from scores

            int latestAttempt = 0;

            // To Insert student score into DB
            //
            if (scoreList != null)
            {
                Debug.Log(scoreList.scores);
                if (scoreList.scores > score)
                {
                    score = scoreList.scores;
                }
                latestAttempt = scoreList.attempt;
            }

            StudentScores sc = new StudentScores();

            sc.name    = "";
            sc.attempt = latestAttempt + 1;
            sc.scores  = score;
            crudscore.AddStudentGameNewScores(ownerID, userID, gameID, sc);

            Time.timeScale = 0;
            question.text  = "Game Completed! Click back to attempt another game!";

            shareButton.SetActive(true);
        }
    }