예제 #1
0
    public void AddNewScores(string world, string chap, string difficulty, string userid, StudentScores studentscore)
    {
        Debug.Log("Add user score into database");
        Debug.Log("Call Score manager to add data");
        crudscore.AddNewScores(world, chap, difficulty, userid, studentscore);

        crudscore.getUserScore(world, chap, difficulty, userid, printSuccessMsg);
    }
예제 #2
0
    // Start is called before the first frame update
    //
    IEnumerator Start()
    {
        chapter1Panel.SetActive(false);
        chapter2Panel.SetActive(false);
        chapter3Panel.SetActive(false);
        chapter4Panel.SetActive(false);
        lockedOrNot();
        var difficultyLevel = new List <string> {
            "easy", "medium", "hard"
        };
        var chapterLevel = new List <string> {
            "chap1", "chap2", "chap3", "chap4"
        };

        world  = StaticVariable.world;
        userid = StaticVariable.UserID;

        crudscore = GetComponent <CRUDScores>();
        foreach (string i in chapterLevel)
        {
            foreach (string d in difficultyLevel)
            {
                Debug.Log(i + " " + d);
                chap         = i;
                difficulty   = d;
                callbackdone = false;
                crudscore.getUserScore(world, chap, difficulty, userid, myCallbackFunction);
                yield return(new WaitUntil(() => callbackdone == true));

                Debug.Log(callbackdone);
                //Debug.Log(studentScores.scores);
                //getStudentScores(world, i, userid, d);
            }
        }
        lockedOrNot();

        /*
         * chap = "chap1";
         * world = "world1";
         * difficulty = "easy";
         * userid = "userid1159";
         * crudscore = GetComponent<CRUDScores>();
         * crudscore.getUserScore(world, chap, difficulty, userid, myCallbackFunction);
         *
         * getStudentScores(world, chap, userid, difficulty);
         * callbackdone = false;
         */
    }
예제 #3
0
    string userID = StaticVariable.UserID;//"userid1159";


    // Start is called before the first frame update
    IEnumerator Start()
    {
        character = StaticVariable.characterSelect;
        setCharacterMovement(character, false);
        Time.timeScale = 0;
        crudscore      = GetComponent <CRUDScores>();
        crudscore.getUserScore(world, chap, difficulty, userID, callbackFunc);
        yield return(new WaitUntil(() => call == true));

        // Debug.Log(scoreList.scores);
        // Set this before calling into the realtime database.
        // FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://ssadpancake.firebaseio.com/");
        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://ssad-c9270.firebaseio.com/");
        // Get the root reference location of the database.
        mDatabaseRef = FirebaseDatabase.DefaultInstance.RootReference;
        Score.text   = "0";
        // point = GetComponent<AudioSource>();

        coroutine = GenerateQuestions();
        StartCoroutine(coroutine);
    }
예제 #4
0
 public void Test_getUserScores_WithValidValue(string world, string chap, string difficulty, string userid)
 {
     crudscore.getUserScore(world, chap, difficulty, userid, CallBackFunction_WithTrue);
 }
예제 #5
0
    IEnumerator GenerateQuestions()
    {
        var getTask = FirebaseDatabase.DefaultInstance
                      .GetReference("question").Child(world).Child(chap).Child(difficulty)
                      .GetValueAsync();

        yield return(new WaitUntil(() => getTask.IsCompleted || getTask.IsFaulted));

        DataSnapshot snapshot = null;

        if (getTask.IsCompleted)
        {
            snapshot = getTask.Result;
        }

        if (difficulty == "easy")
        {
            NumQuestions = 10;
        }
        else if (difficulty == "normal")
        {
            NumQuestions = 15;
        }
        else
        {
            NumQuestions = 20;
        }

        int totalQuestion = int.Parse(snapshot.ChildrenCount.ToString());

        if (NumQuestions > totalQuestion) //If not enough questions from the database
        {
            question.text  = "The lecturer has not set enough question for this chapter.";
            Time.timeScale = 0;
        }
        else
        {
            GetQuestion[] questionList = new GetQuestion[snapshot.ChildrenCount];
            int           index        = 0;
            //Get question list
            foreach (DataSnapshot s in snapshot.Children)
            {
                questionList[index]            = new GetQuestion();
                questionList[index].UniqueKey  = s.Key;
                questionList[index++].question = JsonUtility.FromJson <UploadQuestion>(s.GetRawJsonValue());
            }

            GetQuestion[] randomQuestion = new GetQuestion[NumQuestions];
            for (int i = 0; i < NumQuestions; i++)
            {
                randomQuestion[i] = questionList[i];
                while (randomQuestion[i] == null)
                {
                    int random = Random.Range(0, NumQuestions - 1);
                    if (questionList[random] != null)
                    {
                        randomQuestion[i]    = questionList[random];
                        questionList[random] = null;
                    }
                }
            }


            int rightOption = 0;
            for (int i = 0; i < NumQuestions; i++)
            {
                question.text = randomQuestion[i].question.question;
                int random = Random.Range(1, 4);
                if (random == 1)
                {
                    answer1.text = randomQuestion[i].question.ans1;
                    answer2.text = randomQuestion[i].question.ans2;
                    answer3.text = randomQuestion[i].question.ans3;
                    answer4.text = randomQuestion[i].question.ans4;
                }
                else if (random == 2)
                {
                    answer1.text = randomQuestion[i].question.ans2;
                    answer2.text = randomQuestion[i].question.ans3;
                    answer3.text = randomQuestion[i].question.ans1;
                    answer4.text = randomQuestion[i].question.ans4;
                }
                else if (random == 3)
                {
                    answer1.text = randomQuestion[i].question.ans3;
                    answer2.text = randomQuestion[i].question.ans2;
                    answer3.text = randomQuestion[i].question.ans4;
                    answer4.text = randomQuestion[i].question.ans1;
                }
                else
                {
                    answer1.text = randomQuestion[i].question.ans3;
                    answer2.text = randomQuestion[i].question.ans1;
                    answer3.text = randomQuestion[i].question.ans4;
                    answer4.text = randomQuestion[i].question.ans2;
                }

                string rightAnswer = randomQuestion[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)
                {
                    score++;
                    Score.text = score.ToString();
                    point.Play();
                    // playSound();
                    yield return(new WaitForSeconds(1.8f));
                }
                else
                {
                    setCharacterMovement(character, true);

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

                    setCharacterMovement(character, false);
                    yield return(new WaitForSeconds(1.2f));
                }
            }
            // GETTING attempt  from scores

            int latestAttempt = 0;

            /* var task = FirebaseDatabase.DefaultInstance
             * .GetReference("scores").Child(world).Child(chap).Child(difficulty).Child(userID)
             * .GetValueAsync();
             *
             * yield return new WaitUntil(() => task.IsCompleted || task.IsFaulted);
             *
             *
             * if (task.IsFaulted)
             * {
             *   Debug.Log("Failed to connect");
             *   // Handle the error...
             * }
             * else if (task.IsCompleted)
             * {
             *
             *   Debug.Log("Code Runs");
             *   snapshot = task.Result;
             *
             *
             *   index = 0;
             *
             *   //currently order is ascending
             *   StudentScores[] scoresList = new StudentScores[snapshot.ChildrenCount];
             *
             *   foreach (DataSnapshot s in snapshot.Children)
             *   {
             *       scoresList[index] = new StudentScores();
             *       scoresList[index++] = JsonUtility.FromJson<StudentScores>(s.GetRawJsonValue());
             *   }
             *
             *   Debug.Log("Total record found " + snapshot.ChildrenCount);
             *
             *
             *   foreach (var item in scoresList)
             *   {
             *       if (item != null)
             *       {
             *           //get the student name here
             *           if (item.attempt > latestAttempt)
             *           {
             *               latestAttempt = item.attempt;
             *           }
             *
             *           if (item.scores > score)
             *           {
             *               score = item.scores;
             *           }
             *       }
             *   }
             * //}*/
            // To Insert student score into DB
            Debug.Log(scoreList.scores);
            if (scoreList != null)
            {
                if (scoreList.scores > score)
                {
                    score = scoreList.scores;
                }
                latestAttempt = scoreList.attempt;
            }


            crudscore.getUserScore(world, chap, difficulty, userID, callbackFunc);


            StudentScores sc = new StudentScores();

            sc.name    = "";
            sc.attempt = latestAttempt + 1;
            sc.scores  = score;
            crudscore.updateUserScore(world, chap, difficulty, userID, sc);

            Time.timeScale = 0;
            question.text  = "Game Completed! Click back to attempt another game!";
        }
    }
 public void Preformancetest_getUserScores(string world, string chap, string difficulty, string userid)
 {
     Debug.Log("Calling getUserScores at: " + System.DateTime.Now);
     crudscore.getUserScore(world, chap, difficulty, userid, printgetUserScoresTime);
 }