Beispiel #1
0
    void EndRound()
    {
        // if the player beats their best score, update it and activate celebration on game over screen
        string bestScoreString = "";

        if (gameMode == Mode.Timed)
        {
            bestScoreString = "BestScoreTimed";
        }
        else if (gameMode == Mode.Lives)
        {
            bestScoreString = "BestScoreLives";
        }

        bool bestScoreWasBeaten = false;

        if ((int)score > PlayerPrefs.GetInt(bestScoreString, 0))
        {
            PlayerPrefs.SetInt(bestScoreString, (int)score);
            bestScoreWasBeaten = true;
            sfx.Play(sfx.wooHoo);
        }

        // increment total games played and games played of this mode
        PlayerPrefs.SetInt("TotalGamesPlayed", PlayerPrefs.GetInt("TotalGamesPlayed", 0) + 1);
        string mode = gameMode == Mode.Timed ? "Timed" : "Lives";

        PlayerPrefs.SetInt("GamesPlayed" + mode, PlayerPrefs.GetInt("GamesPlayed" + mode, 0) + 1);

        // track whether this is the user's first ever game
        PlayerPrefs.SetInt("HasCompletedARound", 1);

        // send analytics before modifying anything
        Analytics.CustomEvent("gameOver", new Dictionary <string, object>
        {
            { "ballsSpawned", ballsSpawned },
            { "roundLength", Time.time - roundStartTime },
            { "score", score },
            { "newHighScore", bestScoreWasBeaten },
            { "totalGamesPlayed", PlayerPrefs.GetInt("TotalGamesPlayed", 0) },
            { "gamesPlayedTimed", PlayerPrefs.GetInt("GamesPlayedTimed", 0) },
            { "gamesPlayedLives", PlayerPrefs.GetInt("GamesPlayedLives", 0) },
            { "adsShown", PlayerPrefs.GetInt("AdsShown", 0) }
        });

        // sort out social stuff
        UpdateLeaderboard();
        LBHandler.CheckForAchievements(true);

        // increment the ad countdown, but only if the player isn't doing particularly badly or well, to reduce frustration
        if ((int)score > minScoreForAds && !bestScoreWasBeaten)
        {
            PlayerPrefs.SetInt("GamesSinceAdShown", PlayerPrefs.GetInt("GamesSinceAdShown", 0) + 1);

            // if it's been long enough since the last once, show an ad
            if (PlayerPrefs.GetInt("GamesSinceAdShown", 0) >= minGamesAdInterval)
            {
                GetComponent <AdManager>().ShowAd();
                PlayerPrefs.SetInt("GamesSinceAdShown", 0);
                PlayerPrefs.SetInt("AdsShown", PlayerPrefs.GetInt("AdsShown", 0) + 1);                 // increment an ads shown counter for analytics
            }
        }

        roundInProgress = false;
        roundStartTime  = -1;
        StopCoroutine(ballSpawnTimer);

        UIController.ShowGameOverScreen(bestScoreWasBeaten);
    }