Ejemplo n.º 1
0
        async Task UpdateCurrentTapsLeaderboardAndTapAchievements()
        {
            GKLeaderboard averageTapLeaderboard = new GKLeaderboard(new [] { GKLocalPlayer.LocalPlayer.PlayerID })
            {
                Identifier = AverageTapTimeId
            };
            var scores = await averageTapLeaderboard.LoadScoresAsync();

            GKScore currentScore;
            GKScore newScore = new GKScore(AverageTapTimeId);

            if (scores != null && scores.Length > 1)
            {
                currentScore = scores [0];
                int oldTaps = (int)currentScore.Context;
                int oldTime = (int)currentScore.Value * oldTaps;

                int newTime = oldTime + GameInfo.GameTimeInSeconds * 100;
                int newTaps = oldTaps + GameInfo.CurrentTaps;

                newScore.Value   = newTime / newTaps;
                newScore.Context = (ulong)newTaps;
            }
            else
            {
                newScore.Value   = GameInfo.GameTimeInSeconds / Math.Max(GameInfo.CurrentTaps, 1) * 100;
                newScore.Context = (ulong)GameInfo.CurrentTaps;
            }

            GKAchievement playAHundred = new GKAchievement(Tap100Id, GKLocalPlayer.LocalPlayer.PlayerID)
            {
                PercentComplete = (float)newScore.Context / 100f * 100f
            };

            GKAchievement playAThousand = new GKAchievement(Tap1000Id, GKLocalPlayer.LocalPlayer.PlayerID)
            {
                PercentComplete = (float)newScore.Context / 1000f * 100f
            };

            await GKAchievement.ReportAchievementsAsync(new [] { playAHundred, playAThousand });

            await GKScore.ReportScoresAsync(new [] { newScore });
        }
Ejemplo n.º 2
0
        async Task LoadLeaderboardScoresInfo(GKLeaderboard leaderboard)
        {
            leaderboard.Range       = new NSRange(1, 3);
            leaderboard.TimeScope   = GKLeaderboardTimeScope.AllTime;
            leaderboard.PlayerScope = GKLeaderboardPlayerScope.Global;
            var scores = await leaderboard.LoadScoresAsync();

            string [] identifiers = new string [scores.Length];
            int       n           = 0;

            foreach (var score in scores)
            {
                identifiers [n++] = score.Player.ToString();
            }

            GKPlayer.LoadPlayersForIdentifiers(identifiers, delegate(GKPlayer[] players, NSError error) {
                for (int i = 0; i < scores.Length; i++)
                {
                    DisplayScore(scores [i], i, players [i]);
                }
            });
        }
Ejemplo n.º 3
0
		async Task LoadLeaderboardScoresInfo (GKLeaderboard leaderboard)
		{
			leaderboard.Range = new NSRange (1, 3);
			leaderboard.TimeScope = GKLeaderboardTimeScope.AllTime;
			leaderboard.PlayerScope = GKLeaderboardPlayerScope.Global;
			var scores = await leaderboard.LoadScoresAsync ();

			string [] identifiers = new string [scores.Length];
			int n = 0;
			foreach (var score in scores)
				identifiers [n++] = score.Player;

			GKPlayer.LoadPlayersForIdentifiers (identifiers, delegate (GKPlayer[] players, NSError error) {
				for (int i = 0; i < scores.Length; i++)
					DisplayScore (scores [i], i, players [i]);
			});
		}
		async Task UpdateCurrentTapsLeaderboardAndTapAchievements ()
		{
			GKLeaderboard averageTapLeaderboard = new GKLeaderboard (new [] { GKLocalPlayer.LocalPlayer.PlayerID }) {
				Identifier = AverageTapTimeId
			};
			var scores = await averageTapLeaderboard.LoadScoresAsync ();

			GKScore currentScore;
			GKScore newScore = new GKScore (AverageTapTimeId);

			if (scores != null && scores.Length > 1) {
				currentScore = scores [0];
				int oldTaps = (int)currentScore.Context;
				int oldTime = (int)currentScore.Value * oldTaps;

				int newTime = oldTime + GameInfo.GameTimeInSeconds * 100;
				int newTaps = oldTaps + GameInfo.CurrentTaps;

				newScore.Value = newTime / newTaps;
				newScore.Context = (ulong)newTaps;
			} else {
				newScore.Value = GameInfo.GameTimeInSeconds / Math.Max (GameInfo.CurrentTaps, 1) * 100;
				newScore.Context = (ulong)GameInfo.CurrentTaps;
			}

			GKAchievement playAHundred = new GKAchievement (Tap100Id, GKLocalPlayer.LocalPlayer.PlayerID) {
				PercentComplete = (float) newScore.Context / 100f * 100f
			};

			GKAchievement playAThousand = new GKAchievement (Tap1000Id, GKLocalPlayer.LocalPlayer.PlayerID) {
				PercentComplete = (float) newScore.Context / 1000f * 100f
			};

			await GKAchievement.ReportAchievementsAsync (new [] { playAHundred, playAThousand });

			await GKScore.ReportScoresAsync (new [] { newScore });
		}