public void Start() { AchievementsTracker.Initialise(display); }
/// <summary> /// Method for updating player stats and achievements once a puzzle is fixed /// </summary> /// <param name="scores"></param> private void UpdatePlayerStats(PlayerStats scores) { if (mUsername != String.Empty) { Task.Factory.StartNew(() => { PlayerStats stats = new PlayerStats(); #region Update Player Stats if (DbConnector.OpenSQLConnection()) { // Connection opened PlayerStatsDA statsDA = new PlayerStatsDA(); if (statsDA.IsStatsExist(mUsername)) { // Stats exist, therefore update stats = statsDA.FindStats(mUsername); stats.XP += scores.XP; stats.SR += scores.SR; stats.PlayTime += TimeSpan.FromSeconds(mTimeInSeconds); stats.Golds += scores.Golds; stats.Silvers += scores.Silvers; stats.Bronzes += scores.Bronzes; DbConnector.CloseSQLConnection(); // Close connection to the database if (DbConnector.OpenSQLConnection()) { if (!statsDA.UpdateStats(stats)) { string error = "There was a problem updating your stats."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } } else { // Stats does not exist, therefore insert stats.Username = mUsername; stats.XP = scores.XP; stats.SR = scores.SR; stats.PlayTime = TimeSpan.FromSeconds(mTimeInSeconds); stats.Golds = scores.Golds; stats.Silvers = scores.Silvers; stats.Bronzes = scores.Bronzes; if (!statsDA.InsertStats(stats)) { string error = "There was a problem updating your stats."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database #endregion #region Update Achievements if (DbConnector.OpenSQLConnection()) { // Connection opened AchievementsDA achievementsDA = new AchievementsDA(); List <AchievementsCompleted> achievementsCompleted = new List <AchievementsCompleted>(); achievementsCompleted = achievementsDA.GetAllAchievements(mUsername); DbConnector.CloseSQLConnection(); // Close connection to the database if (achievementsCompleted != null) { // Achievements exist, therefore update achievementsCompleted = AchievementsTracker.UpdateAchievements(achievementsCompleted, mUsername, stats, mCurrentMode, sCurrentLvl); for (int i = 0; i < 19; i++) { if (achievementsCompleted[i].Title != String.Empty) { string title = achievementsCompleted[i].Title; string description = achievementsCompleted[i].Description; string image = achievementsCompleted[i].Image; // Pull up Achievement dialog FragmentTransaction transaction = FragmentManager.BeginTransaction(); AchDialog dialogFrag = new AchDialog(title, description, image); dialogFrag.Show(transaction, "dialog fragment"); } } if (DbConnector.OpenSQLConnection()) { if (!achievementsDA.UpdateAchievements(achievementsCompleted)) { string error = "There was a problem updating your stats."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } } else { // Achievements do not exist, therefore insert achievementsCompleted = AchievementsTracker.InsertAchievements(achievementsCompleted, mUsername, mCurrentMode); if (DbConnector.OpenSQLConnection()) { if (!achievementsDA.InsertAchievements(achievementsCompleted)) { string error = "There was a problem updating your stats."; RunOnUiThread(() => { AlertGenerator.ShowError(error, this); }); } } } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { //Enabling the controls back AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database #endregion }); } }