// :state-start: start local
 // OnPressLogin() passes the username to the RealmController,
 // ScoreCardManager, and LeaderboardManager
 private static void OnPressLogin()
 {
     try
     {
         HideAuthenticationUI();
         loggedInUser = userInput.value;
         RealmController.SetLoggedInUser(loggedInUser);
         ScoreCardManager.SetLoggedInUser(loggedInUser);
         LeaderboardManager.Instance.SetLoggedInUser(loggedInUser);
     }
     catch (Exception ex)
     {
         Debug.Log("an exception was thrown:" + ex.Message);
     }
 }
Beispiel #2
0
    // RestartGame() creates a new plathrough Stat object and shares this new
    // Stat object with the ScoreCardManager to update in the UI and listen for
    // changes to it
    public static void RestartGame()
    {
        var stat = new Stat();

        stat.StatOwner = currentPlayer;
        realm.Write(() =>
        {
            currentStat = realm.Add(stat);
            currentPlayer.Stats.Add(currentStat);
        });

        ScoreCardManager.SetCurrentStat(currentStat);     // call `SetCurrentStat()` to set the current stat in the UI using ScoreCardManager
        ScoreCardManager.WatchForChangesToCurrentStats(); // call `WatchForChangesToCurrentStats()` to register a listener on the new score in the ScoreCardManager

        StartGame();                                      // start the game by resetting the timer and officially starting a new run/playthrough
    }
Beispiel #3
0
 // DeleteCurrentStat() performs a write transaction to delete the current
 // playthrough Stat object and remove it from the current Player object's
 // Stats' list
 public static void DeleteCurrentStat()
 {
     ScoreCardManager.UnRegisterListener();
     // :state-start: start
     // TODO: within a write transaction, delete the current Stat object, and
     // its reference in the current Player object
     // :state-end:
     // :code-block-start: delete-current-stat-method
     // :state-start: local sync
     realm.Write(() =>
     {
         realm.Remove(currentStat);
         currentPlayer.Stats.Remove(currentStat);
     });
     // :state-end:
     // :code-block-end:
 }
    // :state-end:
    // :code-block-end:

    // :code-block-start: add-sync-register-click-handler
    // :state-start: sync
    // OnPressRegister() passes RealmController.OnPressRegister() the values of
    // the userInput and  passInput TextFields in order to register a user
    private static async void OnPressRegister()
    {
        try
        {
            var currentPlayer = await RealmController.OnPressRegister(userInput.value, passInput.value);

            if (currentPlayer != null)
            {
                HideAuthenticationUI();
            }
            ScoreCardManager.SetLoggedInUser(currentPlayer.Name);
            LeaderboardManager.Instance.SetLoggedInUser(currentPlayer.Name);
        }
        catch (Exception ex)
        {
            Debug.Log("an exception was thrown:" + ex.Message);
        }
    }