示例#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);
        }
    }
示例#2
0
    public static void PlayWord()
    {
        SubmitWordLogEntry dbEntry = new SubmitWordLogEntry();

        dbEntry.parentKey = "BNW_Action";
        dbEntry.key       = "BNW_Submit";
        bool valid = UpdateScore(dbEntry);

        // Firebase logging
        if (GameManagerScript.logging)
        {
            //Debug.Log("Attempts to log data");
            Logger.LogKeyFrame("pre");

            string            json      = JsonUtility.ToJson(dbEntry);
            DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference(GameManagerScript.LOGGING_VERSION);
            DatabaseReference child     = reference.Push();
            child.SetRawJsonValueAsync(json);
            ++totalInteractions;
        }

        //=========Screen animations based on if word was valid or not==========

        // shake the camera
        CameraShaker.instance.ShakeOnce(5f, 5f, .1f, .6f);


        if (valid)
        {
            // temporarily turn off input until all boxes fall!
            TouchInputHandler.inputEnabled = false;

            // keep track of how many words have been successfully played
            ++wordsPlayed;

            // ANIMATE JUICY SUCCESS AND SOUNDS!!
            if (GameManagerScript.juiceProductive || GameManagerScript.juiceUnproductive)
            {
                ParticleSystem particleSystem = celebrationParticleSystem.GetComponent <ParticleSystem>();
                particleSystem.Play();

                AudioManager.instance.Play("Explosion");
            }
            else
            {
                // default sound effect
                AudioManager.instance.Play("WaterSwirl");
            }
        }
        else
        {
            // Error sound
            AudioManager.instance.Play("Error");

            // JUICY SOUND FX
            if (GameManagerScript.juiceProductive || GameManagerScript.juiceUnproductive)
            {
                AudioManager.instance.Play("Explosion");
            }
        }
    }