Beispiel #1
0
    public static bool UpdateScore(SubmitWordLogEntry dbEntry)
    {
        // firebase logging
        SubmitWordLogEntry.SubmitWordPayload payload = new SubmitWordLogEntry.SubmitWordPayload();
        payload.word    = currentWord;
        payload.letters = GetLetterPayloadsFromCurrentWord();
        dbEntry.payload = payload;

        if (IsValidWord(currentWord))
        {
            // Update the score based on the word
            long submittedScore = GetScore(currentWord, payload);
            score += submittedScore;
            if (scoreText != null)
            {
                scoreText.text = "Points: " + score;
            }

            payload.success    = true;
            payload.scoreTotal = submittedScore;

            // update the highest scoring word if necessary
            if (submittedScore > GameManagerScript.myHighestScoringWordScore)
            {
                GameManagerScript.myHighestScoringWord      = currentWord;
                GameManagerScript.myHighestScoringWordScore = (int)submittedScore;
            }

            if (score > GameManagerScript.myHighScore)
            {
                GameManagerScript.myHighScore        = score;
                GameManagerScript.myHighScoreUpdated = true;
            }

            // Do something celebratory! highlight in green briefly before removing from screen
            // and also display a congratulatory message depending on how rare the word was
            instance.StartCoroutine(instance.AnimateSelectedTiles(GetWordFreq(currentWord), submittedScore));

            // Update the high score, if applicable
            // TODO: debug this
            //DBManager.instance.LogScore(score);

            return(true);
        }
        else
        {
            // firebase logging
            payload.success    = false;
            payload.rarity     = -1;
            payload.scoreBase  = -1;
            payload.scoreTotal = -1;

            ClearAllSelectedTiles();

            return(false);
        }
    }
Beispiel #2
0
    public static long GetScore(string word, SubmitWordLogEntry.SubmitWordPayload payload)
    {
        // base score is based on length of word (if word is 3 letters long, base is 1 + 2 + 3 points, etc)
        long baseScore = CalculateBaseScore(word.Length);

        // TODO: do more balance testing of scoring function to make sure it is balanced?
        float wordRank = GetWordRank(word);

        if (wordRank < 0)
        {
            // word does not exist in dictionary
            return(0);
        }

        // update the rarest word if necessary
        if (wordRank > GameManagerScript.myRarestWordRarity)
        {
            GameManagerScript.myRarestWord       = currentWord;
            GameManagerScript.myRarestWordRarity = wordRank;
        }

        // record scores and freq into log if necessary
        if (payload != null)
        {
            payload.rarity    = wordRank;
            payload.scoreBase = baseScore;
        }

        // scoring function based on freq of word + freq of letters

        // based on the rarity of the word, Uncommon, Rare, Super Rare, Ultra Rare?
        // give the user a fixed bonus points amount and display an animation
        int bonus = GetBonus(wordRank) / 2;

        return((long)(baseScore * (1 + wordRank * 4)) + bonus);
    }