Пример #1
0
        private void OnUpdate(float obj)
        {
            Service();

            if (!(_createdRoom || _joinedRoom))
            {
                return;
            }

            Debug.Log(CurrentRoom);

            if (!_gameActive && CurrentRoom != null && CurrentRoom.PlayerCount == 2)
            {
                _gameActive = true;
                if (_createdRoom)
                {
                    CreatedGame.Dispatch();
                }
                if (_joinedRoom)
                {
                    JoinedGame.Dispatch();
                }
            }
            if (_gameActive && (CurrentRoom == null || CurrentRoom.PlayerCount < 2))
            {
                Disconnected.Dispatch();
            }
        }
    /*
     * Gets entry count
     */
    void uploadToFirebase(CreatedGame game)
    {
        int gameNumber;

        FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("entryCount").GetValueAsync().ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.Log("Faulted");
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;
                gameNumber            = int.Parse(snapshot.Value.ToString()) + 1;
                FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("entryCount").SetValueAsync(gameNumber);
                checkForEqualGames(gameNumber - 2, gameNumber, game);
            }
        });
    }
Пример #3
0
    public void addToGameList()
    {
        Debug.Log(isNameUsed);

        foreach (string n in GameControl.control.allGamesNames)
        {
            if (name.Equals(n))
            {
                isNameUsed = true;
            }
            else
            {
                isNameUsed = false;
            }
        }
        Debug.Log(isNameUsed);
        if (name != "" && !isNameUsed)
        {
            CreatedGame game = new CreatedGame(name, bugs, finalWC, gameScore);
            GameControl.control.allGames.Add(game);
            GameControl.control.allGamesNames.Add(name);
            gameScore = 0;
            GameControl.control.isGameOver = false;
            isNameUsed = false;
            GameControl.control.wordStarted = false;

            GameControl.control.changeScene(fadePanel);
        }
        else
        {
            TextMeshProUGUI[] textArray = nameGamePanel.GetComponentsInChildren <TextMeshProUGUI>();
            foreach (TextMeshProUGUI text in textArray)
            {
                if (text.text == "Name your Game:")
                {
                    text.color = Color.red;
                    text.text  = "Invalid Name";
                }
            }
        }
        nameInput.Select();
        nameInput.ActivateInputField();
    }
    /*
     * Phase 2 detects if there is agame in leaderboard with same name, if so add an asterik
     * to the submitted game name and change the identifier to that new modified name.
     * This solves issue of duplicate entries. Then submit game
     *
     */
    void checkForEqualGamesTwo(int gameNumber, CreatedGame game)
    {
        string gameIdentifier = game.name;

        GameControl.control.topGameIdentifier = game.name;


        GameControl.control.topGameName = game.name;
        for (int x = 0; x < allEntries.Count; x++)
        {
            if (allEntries[x].name == gameIdentifier)
            {
                gameIdentifier += "*";
                x = -1;
            }
        }
        GameControl.control.topGameIdentifier = gameIdentifier;
        LeaderboardEntry entry = new LeaderboardEntry(gameIdentifier, game.rating);

        FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("Scores").Child((gameNumber - 1).ToString()).SetRawJsonValueAsync(JsonUtility.ToJson(entry));
        canSubmit = true;
    }
 /*
  * This is the first phase for checking equal games, first it adds all games
  * using recursion, and then it calls phase 2
  */
 void checkForEqualGames(int recursionCount, int gameNumber, CreatedGame game)
 {
     FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("Scores").Child(recursionCount.ToString()).GetValueAsync().ContinueWith(task => {
         if (task.IsFaulted)
         {
             Debug.Log("fauted");
         }
         else if (task.IsCompleted)
         {
             DataSnapshot snapshot = task.Result;
             allEntries.Add(JsonUtility.FromJson <LeaderboardEntry>(snapshot.GetRawJsonValue()));
             if (recursionCount > 0)
             {
                 checkForEqualGames(recursionCount - 1, gameNumber, game);
             }
             else
             {
                 checkForEqualGamesTwo(gameNumber, game);
             }
         }
     });
 }
Пример #6
0
    void updateBoardDisplay()
    {
        //The first entry in the sorted list will always equ
        allEntries [0].setRank(1);

        /*
         * This loop is key for assigning ranks because it deals with ties.
         * If two ratings are equal, the next element in the list acquires rank of previous, else
         * then it equals rank of previous plus 1
         */
        for (int x = 1; x < allEntries.Count; x++)
        {
            if (allEntries [x - 1].rating == allEntries [x].rating)
            {
                allEntries [x].setRank(allEntries [x - 1].getRank());
            }
            else
            {
                allEntries[x].setRank((allEntries [x - 1].getRank() + 1));
            }
        }

        /*
         * This loop assigns the display values for the entry that matches your top submission. If your entry is a top 5,
         * then assign top 5 values regularly. If it isn't a top 5 and there are only 5 display elements, make another and
         * assign values. Else, just update 6th display value
         */
        for (int x = 0; x < allEntries.Count; x++)
        {
            if (allEntries [x].name == GameControl.control.topGameIdentifier)
            {
                if (x < 5 && displayValues.Count < 6)
                {
                    displayValues [x].rank.text      = allEntries[x].getRank().ToString() + ".";
                    displayValues [x].rank.color     = Color.yellow;
                    displayValues [x].nameText.text  = allEntries [x].getName();
                    displayValues [x].nameText.color = Color.yellow;
                    displayValues [x].rating.text    = string.Format("{0:N1}", allEntries [x].getRating().ToString()) + "/10";
                    displayValues [x].rating.color   = Color.yellow;
                }
                else if (displayValues.Count < 6)
                {
                    GameObject   entry       = Instantiate(entryPrefab, new Vector3(0, 0), Quaternion.identity, leaderboardDisplay.transform);
                    EntryDisplay entryScript = entry.GetComponent <EntryDisplay> ();
                    entryScript.rank.text     = allEntries[x].getRank().ToString();
                    entryScript.nameText.text = allEntries [x].name;

                    entryScript.rating.text = string.Format("{0:N1}", allEntries [x].getRating().ToString()) + "/10";
                    displayValues.Add(entryScript);

                    displayValues [displayValues.Count - 1].rank.color     = Color.yellow;
                    displayValues [displayValues.Count - 1].nameText.color = Color.yellow;
                    displayValues [displayValues.Count - 1].rating.color   = Color.yellow;
                }
                else
                {
                    displayValues[displayValues.Count - 1].rank.text     = allEntries[x].getRank().ToString() + ".";
                    displayValues[displayValues.Count - 1].nameText.text = allEntries [x].name;
                    displayValues [displayValues.Count - 1].rating.text  = allEntries [x].getRating().ToString();
                }
            }
        }

        /*
         * Assings values regularly for top 5 display values
         */
        for (int x = 0; x < 5 && x < allEntries.Count; x++)
        {
            displayValues[x].rank.text     = allEntries[x].getRank().ToString() + ".";
            displayValues[x].nameText.text = allEntries[x].getName();
            Debug.Log(allEntries [x].rating);

            displayValues[x].rating.text = string.Format("{0:N1}", allEntries[x].getRating().ToString()) + "/10";
        }
        text.alpha = 0;

        /*
         * This list searches through create games and finds which one matches your topgame submission,
         * and then asssign topGame to it
         */
        CreatedGame topGame = new CreatedGame("NULL", -1);

        foreach (CreatedGame x in GameControl.control.allGames)
        {
            if (x.name == GameControl.control.topGameName)
            {
                topGame = x;
            }
        }

        /*This updates the score of top game entry by checking when gC = your top game index
         * if rating is not equal betweene entry pulled and your own, update it.*/
        int gC = 0;

        if (allEntries [gC].name == GameControl.control.topGameIdentifier)
        {
            Debug.Log(GameControl.control.topGameIdentifier);
            Debug.Log(allEntries [gC].name);
            if (allEntries [gC].rating != topGame.rating)
            {
                FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("Scores").Child(gC.ToString()).Child("rating").SetValueAsync(topGame.rating);
                FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("Scores").Child("placeholder").SetValueAsync(topGame.rating);
            }
        }
        gC++;
    }