Esempio n. 1
0
    private void Update()
    {
        LeaderboardStructure tmp = new LeaderboardStructure();

        tmp = currentLeaderboard;

        currentLeaderboard = dataController.GetLeaderboardModuleData();

        if (tmp != currentLeaderboard)
        {
            highscoreEntryList.Clear();
            EmptyHighScoreEntryTransformList();
            RefillLeaderboard();
        }
    }
Esempio n. 2
0
    private void Awake()
    {
        entryContainer = transform.Find("highScoreContainer");
        entryTemplate  = entryContainer.Find("highScoreEntryTemplate");

        entryTemplate.gameObject.SetActive(false);

        dataController     = FindObjectOfType <DataController>();
        currentLeaderboard = dataController.GetLeaderboardModuleData();

        highscoreEntryList = new List <HighscoreEntry>();
        for (int i = 0; i < currentLeaderboard.score.Count; i++)
        {
            int scoreParsed;
            Int32.TryParse(currentLeaderboard.score[i], out scoreParsed);
            HighscoreEntry newEntry = new HighscoreEntry {
                score = scoreParsed, name = currentLeaderboard.user[i]
            };
            highscoreEntryList.Add(newEntry);
        }


        // Sort table
        for (int i = 0; i < highscoreEntryList.Count; i++)
        {
            for (int j = 0; j < highscoreEntryList.Count; j++)
            {
                if (highscoreEntryList[j].score < highscoreEntryList[i].score)
                {
                    // swap
                    HighscoreEntry tmp = highscoreEntryList[i];
                    highscoreEntryList[i] = highscoreEntryList[j];
                    highscoreEntryList[j] = tmp;
                }
            }
        }

        highscoreEntryTransformList = new List <Transform>();


        for (int i = 0; i < 10 && i < highscoreEntryList.Count; i++)
        {
            CreateHighscoreEntryTransform(highscoreEntryList[i], entryContainer, highscoreEntryTransformList);
        }

        string json = JsonUtility.ToJson(highscoreEntryList);
    }
Esempio n. 3
0
 public void NewLeaderboardWanted(LeaderboardStructure newLeaderboardWanted)
 {
     leaderboardWanted = newLeaderboardWanted;
 }
Esempio n. 4
0
    // Start is called before the first frame update
    async void Awake()
    {
        //PlayerPrefs.DeleteAll();          // RUN THIS ONCE TO CLEAR PLAYERPREFS
        SetupPlayerPrefs();

        Debug.Log("Start");

        DontDestroyOnLoad(gameObject);
        isFinishedFetching = false;
        Loader.Load(Loader.Scene.LoginScene);
        // Get login
        // PlayerPrefs.SetString("username", "elliott");
        string gameUser = PlayerPrefs.GetString("username");

        // Fetch class in which participates
        // Blocked async function
        interfaceLink = new Interface();
        var classesJson = await interfaceLink.GetSignUpClasses(gameUser);

        Debug.Log(classesJson);
        UserSpecs specs = JsonConvert.DeserializeObject <UserSpecs>(classesJson);



        // Fetch leaderboard from each corresponding classTag

        // Need to fetch leaderboard for each classTag user is on
        // At every iteration we pick the score from N entry of score
        try
        {
            int z = 0;
            foreach (string _class in specs.docs[0].classTag)
            {
                // fetch Leaderboard
                var leaderboardJson = await interfaceLink.GetLeaderboard(_class, specs.docs[0].school);

                Thread.Sleep(1100);

                Leaderboard leaderboard = new Leaderboard();
                leaderboard = JsonConvert.DeserializeObject <Leaderboard>(leaderboardJson);

                leaderboardList.Add(leaderboard);
                leaderboardList[z].module = _class;
                z++;
                Debug.Log(leaderboardJson);
            }
        }
        catch
        {
            Debug.Log("Login failed");
            Destroy(gameObject);
            SceneManager.LoadScene(Loader.Scene.LoginScene.ToString());
            return;
        }

        foreach (string _class in specs.docs[0].classTag)
        {
            // fetch Question
            var questionJson = await interfaceLink.GetQuestions(_class, specs.docs[0].school);

            Thread.Sleep(1100);
            QuestionStructure questionData = new QuestionStructure();
            questionData        = JsonConvert.DeserializeObject <QuestionStructure>(questionJson);
            questionData.module = _class;
            questionList.Add(questionData);
            Debug.Log(questionJson);
        }

        // Size of RoundData array
        int moduleSize = questionList.Count;

        // Initialize RoundData for Elliot and Array of set

        questionSet = new RoundData[moduleSize];

        for (int i = 0; i < moduleSize; i++)
        {
            questionSet[i]        = new RoundData();
            questionSet[i].module = specs.docs[0].classTag[i];

            // Initialize array of easy and hard questions
            questionSet[i].hardOrEasy    = new DifficultyData[2];
            questionSet[i].hardOrEasy[0] = new DifficultyData();
            questionSet[i].hardOrEasy[1] = new DifficultyData();

            questionSet[i].hardOrEasy[0].isHard = true;
            questionSet[i].hardOrEasy[1].isHard = false;

            // Get number of "Easy" and "Hard" questions
            int[] diffCount = GetEasyNumber(questionList[i].docs);

            // Define number of questions per module
            questionSet[i].hardOrEasy[0].questions = new QuestionsList[diffCount[0]];
            questionSet[i].hardOrEasy[1].questions = new QuestionsList[diffCount[1]];

            int easyCount = 0;
            int hardCount = 0;

            for (int j = 0; j < questionList[i].docs.Count; j++)
            {
                // Check number of options for question
                int numberAnswers = GetNumberAnswers(questionList[i].docs[j]);

                // Fill easy questions with difficulty == hard
                if (questionList[i].docs[j].difficulty == "Hard")
                {
                    // Create question instance
                    questionSet[i].hardOrEasy[0].questions[hardCount] = new QuestionsList();
                    // Fill question
                    questionSet[i].hardOrEasy[0].questions[hardCount].question = questionList[i].docs[j].question;
                    // Fill answers for the question
                    questionSet[i].hardOrEasy[0].questions[hardCount].answers = new AnswersList[numberAnswers];
                    FillEasyAnswers(numberAnswers, questionSet[i].hardOrEasy[0].questions[hardCount].answers, i, j);

                    hardCount++;
                }

                // Fill hard questions with difficulty == easy
                else if (questionList[i].docs[j].difficulty == "Easy")
                {
                    // Create question instance
                    questionSet[i].hardOrEasy[1].questions[easyCount] = new QuestionsList();

                    // Fill question
                    questionSet[i].hardOrEasy[1].questions[easyCount].question = questionList[i].docs[j].question;
                    // Fill answers for the question
                    questionSet[i].hardOrEasy[1].questions[easyCount].answers = new AnswersList[numberAnswers];
                    FillEasyAnswers(numberAnswers, questionSet[i].hardOrEasy[1].questions[easyCount].answers, i, j);

                    easyCount++;
                }
            }
        }

        questionSetWanted = questionSet[0];

        // Transform Leaderboard List into Leaderboard Array Object

        // Create Leaderboard Array Object
        leaderboardArray = new LeaderboardStructure[specs.docs[0].classTag.Count];

        for (int i = 0; i < specs.docs[0].classTag.Count; i++)
        {
            leaderboardArray[i]        = new LeaderboardStructure();
            leaderboardArray[i].module = leaderboardList[i].module;
            leaderboardArray[i].score  = new List <string>();
            leaderboardArray[i].user   = new List <string>();

            // Initialize string list
            for (int j = 0; j < leaderboardList[i].docs.Count; j++)
            {
                // Iterate through users found
                // Assign each module its scores and users corresponding
                for (int k = 0; k < leaderboardList[i].docs[j].classTag.Count; k++)
                {
                    if (leaderboardList[i].docs[j].classTag[k] == leaderboardList[i].module)
                    {
                        leaderboardArray[i].score.Add(leaderboardList[i].docs[j].score[k]);
                        leaderboardArray[i].user.Add(leaderboardList[i].docs[j]._id);
                    }
                }
            }
        }
        leaderboardWanted = leaderboardArray[0];
        // The Fetching is done
        isFinishedFetching = true;
        var responseMessage = interfaceLink.UpdateHighScore(specs.docs[0]);

        Loader.Load(Loader.Scene.MainMenu);
    }
Esempio n. 5
0
 public void LeaderboardButtonClicked(LeaderboardStructure leaderboardDataWanted)
 {
     dataController.NewLeaderboardWanted(leaderboardDataWanted);
     SoundManager.PlaySound(SoundManager.Sound.ButtonClick);
 }
Esempio n. 6
0
 public void SetUpLeaderboard(LeaderboardStructure data)
 {
     leaderboardStructure = data;
     moduleText.text      = leaderboardStructure.module;
 }