void Check(GKLeaderboard lb)
        {
#if !__TVOS__
            Assert.Null(lb.Category, "Category");
#endif
            if (TestRuntime.CheckSystemAndSDKVersion(6, 0))
            {
                Assert.Null(lb.GroupIdentifier, "GroupIdentifier");
                if (TestRuntime.CheckSystemAndSDKVersion(7, 0))
                {
                    Assert.Null(lb.Identifier, "Identifier");
                }
            }
            Assert.Null(lb.LocalPlayerScore, "LocalPlayerScore");
            Assert.That(lb.MaxRange, Is.EqualTo((nint)0), "MaxRange");
            Assert.That(lb.PlayerScope, Is.EqualTo(GKLeaderboardPlayerScope.Global), "PlayerScope");
            if (TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                // depending on the ctor 1,10 (or 0,0) is returned before iOS7 - but 1,25 is documented (in iOS7)
                Assert.That(lb.Range.Location, Is.EqualTo((nint)1), "Range.Location");
                Assert.That(lb.Range.Length, Is.EqualTo((nint)25), "Range.Length");
            }
            Assert.Null(lb.Scores, "Scores");
            Assert.That(lb.TimeScope, Is.EqualTo(GKLeaderboardTimeScope.AllTime), "TimeScope");
            Assert.Null(lb.Title, "Title");
        }
        private Task <IEnumerable <LeaderboardScore> > InternalGetScores(string leaderboardCode, int count, bool socialOnly, bool centered)
        {
            var tcs = new TaskCompletionSource <IEnumerable <LeaderboardScore> >();

            UIKit.UIApplication.SharedApplication.InvokeOnMainThread(async() =>
            {
                var result = Enumerable.Empty <LeaderboardScore>();

                var leaderboards        = await GKLeaderboard.LoadLeaderboardsAsync() ?? new GKLeaderboard[] { };
                var selectedLeaderboard = leaderboards.FirstOrDefault(l => l.Identifier == leaderboardCode);

                if (selectedLeaderboard != null)
                {
                    selectedLeaderboard.PlayerScope = socialOnly ? GKLeaderboardPlayerScope.FriendsOnly : GKLeaderboardPlayerScope.Global;
                    selectedLeaderboard.Range       = new Foundation.NSRange(1, count);
                    var scores = await selectedLeaderboard.LoadScoresAsync();

                    if (centered && selectedLeaderboard.LocalPlayerScore != null)
                    {
                        var playerRank = selectedLeaderboard.LocalPlayerScore.Rank;
                        var fromIndex  = playerRank - (count / 2);
                        fromIndex      = fromIndex < 1 ? 1 : fromIndex;

                        selectedLeaderboard.Range = new Foundation.NSRange(fromIndex, count);
                        scores = await selectedLeaderboard.LoadScoresAsync();
                    }

                    result = await IOSMapper.MapLeaderBoards(scores);
                }

                tcs.SetResult(result);
            });

            return(tcs.Task);
        }
 public void PlayersCtor()
 {
     // note: Mavericks does not like (respond to) this selector - but it did work with ML and is documented
     using (var lb = new GKLeaderboard(new string [0])) {
         Check(lb);
     }
 }
        public void DefaultCtor()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 8, throwIfOtherPlatform: false);

            using (var lb = new GKLeaderboard()) {
                Check(lb);
            }
        }
        public void PlayersCtor()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 8, throwIfOtherPlatform: false);

            // note: Mavericks does not like (respond to) this selector - but it did work with ML and is documented
            using (var lb = new GKLeaderboard(new string [0])) {
                Check(lb);
            }
        }
        public GKLeaderboard reloadLeaderboard(string category)
        {
            GKLeaderboard leaderboard = new GKLeaderboard();

            leaderboard.Category  = category;
            leaderboard.TimeScope = GKLeaderboardTimeScope.AllTime;
            leaderboard.Range     = new NSRange(1, 1);
            return(leaderboard);
        }
		public GKLeaderboard reloadLeaderboard(string category)
		{
			GKLeaderboard leaderboard = new GKLeaderboard ();
			leaderboard.Category = category;
			leaderboard.TimeScope = GKLeaderboardTimeScope.AllTime;
			leaderboard.Range = new NSRange (1, 1);
			return leaderboard;

		}
        void Check(GKLeaderboard lb)
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 8, throwIfOtherPlatform: false);

#if !__TVOS__
            Assert.Null(lb.Category, "Category");
#endif
#if __MACOS__
            var hasGroupIdentifier = TestRuntime.CheckSystemVersion(ApplePlatform.MacOSX, 10, 9);
            var hasIdentifier      = TestRuntime.CheckSystemVersion(ApplePlatform.MacOSX, 10, 10);
            var hasRange           = TestRuntime.CheckSystemVersion(ApplePlatform.MacOSX, 10, 10);
#elif __IOS__
            var hasGroupIdentifier = TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 6, 0);
            var hasIdentifier      = TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 7, 0);
            var hasRange           = TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 7, 0);
#elif __TVOS__
            var hasGroupIdentifier = true;
            var hasIdentifier      = true;
            var hasRange           = true;
#elif __WATCHOS__
            var hasGroupIdentifier = true;
            var hasIdentifier      = true;
            var hasRange           = TestRuntime.CheckSystemVersion(ApplePlatform.WatchOS, 3, 0);
#endif
            if (hasGroupIdentifier)
            {
                Assert.Null(lb.GroupIdentifier, "GroupIdentifier");
                if (hasIdentifier)
                {
                    Assert.Null(lb.Identifier, "Identifier");
                }
            }
            Assert.Null(lb.LocalPlayerScore, "LocalPlayerScore");
            Assert.That(lb.MaxRange, Is.EqualTo((nint)0), "MaxRange");
            Assert.That(lb.PlayerScope, Is.EqualTo(GKLeaderboardPlayerScope.Global), "PlayerScope");
            if (hasRange)
            {
                // depending on the ctor 1,10 (or 0,0) is returned before iOS7 - but 1,25 is documented (in iOS7)
                Assert.That(lb.Range.Location, Is.EqualTo((nint)1), "Range.Location");
                Assert.That(lb.Range.Length, Is.EqualTo((nint)25), "Range.Length");
            }
            Assert.Null(lb.Scores, "Scores");
            Assert.That(lb.TimeScope, Is.EqualTo(GKLeaderboardTimeScope.AllTime), "TimeScope");
            Assert.Null(lb.Title, "Title");
        }
示例#9
0
    void RetrieveTopTenScores()
    {
        GKLeaderboard leaderboardRequest = new GKLeaderboard();

        if (leaderboardRequest != null)
        {
            // configure request
            leaderboardRequest.playerScope = GKLeaderboardPlayerScope.Global;
            leaderboardRequest.timeScope   = GKLeaderboardTimeScope.AllTime;
            leaderboardRequest.category    = leaderboardID;
            Log("Getting leaderboard identifier: " + leaderboardRequest.identifier);
            Log("Getting leaderboard category: " + leaderboardRequest.category);
            Log("Getting leaderboard group identifier: " + leaderboardRequest.groupIdentifier);
            leaderboardRequest.range = new NSRange(1, 10);

            // load scores; it calls delegate back when done
            leaderboardRequest.LoadScores(delegate(object[] scores, NSError error) {
                if (error != null)
                {
                    Log("Error retrieving scores: " + error.LocalizedDescription());
                }
                else if (scores != null)
                {
                    // got the scores, but the low-level GKScore only has player ID.
                    // if you want player display name, you need to combine it with
                    // the high-level API to load the players
                    string[] playerIDs = scores.Cast <GKScore>().Select(x => x.playerID).ToArray();
                    Player.LoadPlayersByIDs(playerIDs, delegate(Player[] players) {
                        // print localized title of leaderboard
                        Log("Top 10 for " + leaderboardRequest.title);

                        for (int i = 0; i < scores.Length; i++)
                        {
                            GKScore score = scores[i] as GKScore;

                            result += score.formattedValue + System.Environment.NewLine;

                            Player player = players[i];
                            Log(score.rank + ". " + score.formattedValue + ", " + score.date + ", " + player.displayName);
                        }
                    });
                }
            });
        }
    }
 void setAuthenticateHandler()
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0))
     {
         GKLocalPlayer.LocalPlayer.AuthenticateHandler = (ui, error) =>
         {
             if (ui != null)
             {
                 this.PresentViewController(ui, true, null);
             }
             else if (GKLocalPlayer.LocalPlayer.Authenticated)
             {
                 currentLeaderBoard = gameCenterManager.reloadLeaderboard(currentCategory);
                 updateHighScore();
             }
             else
             {
                 var alert = new UIAlertView("Game Center Account Required", "Need login the game center!", null, "Retry", null);
                 alert.Clicked += (sender, e) => {
                     //GKLocalPlayer.LocalPlayer.Authenticated();
                 };
                 alert.Show();
             }
         };
     }
     else
     {
         GKLocalPlayer.LocalPlayer.Authenticate(new GKNotificationHandler(delegate(NSError error) {
             if (GKLocalPlayer.LocalPlayer.Authenticated)
             {
                 currentLeaderBoard = gameCenterManager.reloadLeaderboard(currentCategory);
                 updateHighScore();
             }
             else
             {
                 var alert      = new UIAlertView("Game Center Account Required", "Need login the game center!", null, "Retry", null);
                 alert.Clicked += (sender, e) => {
                     setAuthenticateHandler();
                 };
                 alert.Show();
             }
         }));
     }
 }
示例#11
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 });
        }
示例#12
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]);
                }
            });
        }
 void SetAuthenticateHandler()
 {
     GKLocalPlayer.LocalPlayer.AuthenticateHandler = (ui, error) => {
         if (ui != null)
         {
             PresentViewController(ui, true, null);
         }
         else if (GKLocalPlayer.LocalPlayer.Authenticated)
         {
             currentLeaderBoard = gameCenterManager.ReloadLeaderboard(currentCategory);
             UpdateHighScore();
         }
         else
         {
             var alert = new UIAlertView("Game Center Account Required", "Need login the game center!", null, "Retry", null);
             alert.Clicked += (sender, e) => {
                 //GKLocalPlayer.LocalPlayer.Authenticated();
             };
             alert.Show();
         }
     };
 }
示例#14
0
        /// <summary>
        /// Gets the top scores from leaderboard.
        /// </summary>
        /// <param name="leaderboardCode">The leaderboard code.</param>
        /// <returns>
        /// Task
        /// </returns>
        public async Task <Dictionary <string, List <WaveEngine.Social.LeaderboardScore> > > GetTopScoresFromLeaderboard(string leaderboardCode)
        {
            var scores = new Dictionary <string, List <GKScore> >();

            var leaderboards = await GKLeaderboard.LoadLeaderboardsAsync() ?? new GKLeaderboard[]
            {
            };

            foreach (var leaderboard in leaderboards)
            {
                var leaderboardScores = await leaderboard.LoadScoresAsync() ?? new GKScore[]
                {
                };
                var leaderboardScoresList = leaderboardScores.ToList();

                var boardId = leaderboard.Identifier;

                scores.Add(boardId, leaderboardScoresList);
            }

            var waveScores = Mapper.MapLeaderBoards(scores);

            return(waveScores);
        }
		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 });
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			// Perform any additional setup after loading the view, typically from a nib.
			initGameCenter ();

			string[] categories = { "Easy", "Hard", "Awesome" };
			UIActionSheet selectCategory = new UIActionSheet ("Choose Leaderboard", null, "Cancel", null, categories);
			selectCategory.Dismissed += (sender, e) => {
				switch (e.ButtonIndex) {
				case 0:
					currentCategory = EasyLeaderboardID;
					this.selectLeaderBoardButton.SetTitle ("Leaderboard: Easy", UIControlState.Normal);
					currentScore = 0;
					currentScoreTextField.Text = "0";
					break;
				case 1:
					currentCategory = HardLeaderboardID;
					this.selectLeaderBoardButton.SetTitle ("Leaderboard: Hard", UIControlState.Normal);
					currentScore = 0;
					currentScoreTextField.Text = "0";
					break;
				case 2:
					currentCategory = AwesomeLeaderboardID;
					this.selectLeaderBoardButton.SetTitle ("Leaderboard: Awesome", UIControlState.Normal);
					currentScore = 0;
					currentScoreTextField.Text = "0";
					break;
				default:
					break;
				}
				currentLeaderBoard = gameCenterManager.reloadLeaderboard (currentCategory);
				updateHighScore ();
			};

			this.selectLeaderBoardButton.TouchUpInside += (sender, e) => {
				selectCategory.ShowInView (this.View);
			};

			this.showLeaderboardButton.TouchUpInside += (sender, e) => {
				GKLeaderboardViewController leaderboardController = new GKLeaderboardViewController ();
				leaderboardController.Category = currentCategory;
				leaderboardController.TimeScope = GKLeaderboardTimeScope.AllTime;
				leaderboardController.DidFinish += (senderLeaderboard, eLeaderboard) => {
					leaderboardController.DismissViewController (true, null);
				};
				PresentViewController (leaderboardController, true, null);
			};

			this.showAchievementButton.TouchUpInside += (sender, e) => {
				GKAchievementViewController achievementController = new GKAchievementViewController ();
				achievementController.DidFinish += (senderAchievement, eAchievement) => {
					achievementController.DismissViewController (true, null);
				};
				PresentViewController (achievementController, true, null);
			};

			this.incrementScoreButton.TouchUpInside += (sender, e) => {
				currentScore++;
				currentScoreTextField.Text = currentScore.ToString ();
				checkAchievements ();
			};

			this.submitScoreButton.TouchUpInside += (sender, e) => {
				if (currentScore > 0)
					gameCenterManager.reportScore (currentScore, currentCategory, this);
			};

			this.resetButton.TouchUpInside += (sender, e) => {
				gameCenterManager.resetAchievement ();
			};
		}
		void setAuthenticateHandler ()
		{
			if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
				GKLocalPlayer.LocalPlayer.AuthenticateHandler = (ui, error) => {
					if (ui != null) {
						this.PresentViewController (ui, true, null);
					} else if (GKLocalPlayer.LocalPlayer.Authenticated) {
						currentLeaderBoard = gameCenterManager.reloadLeaderboard (currentCategory);
						updateHighScore ();
					} else {
						var alert = new UIAlertView ("Game Center Account Required", "Need login the game center!", null, "Retry", null);
						alert.Clicked += (sender, e) => {
							//GKLocalPlayer.LocalPlayer.Authenticated();
						};
						alert.Show ();
					}
				};
			} else {
				GKLocalPlayer.LocalPlayer.Authenticate (new Action<NSError> ((error) => {
					if (GKLocalPlayer.LocalPlayer.Authenticated) {
						currentLeaderBoard = gameCenterManager.reloadLeaderboard (currentCategory);
						updateHighScore ();
					} else {
						var alert = new UIAlertView ("Game Center Account Required", "Need login the game center!", null, "Retry", null);
						alert.Clicked += (sender, e) => {
							setAuthenticateHandler ();
						};
						alert.Show ();

					}
				}));
			}
		}
示例#18
0
    public void RetrieveTopTenScores()
    {
                #if UNITY_IOS && !UNITY_EDITOR
        GKLeaderboard leaderboardRequest = new GKLeaderboard();
        if (leaderboardRequest != null)
        {
            // configure request
            leaderboardRequest.playerScope = GKLeaderboardPlayerScope.Global;
            leaderboardRequest.timeScope   = GKLeaderboardTimeScope.AllTime;
            leaderboardRequest.category    = leaderboardID;
            leaderboardRequest.range       = new NSRange(1, 1);
            // load scores; it calls delegate back when done
            leaderboardRequest.LoadScores(delegate(object[] scores, NSError error) {
                if (error != null)
                {
                    //Log("Error retrieving scores: " + error.LocalizedDescription());
                }
                else if (scores != null)
                {
                    // got the scores, but the low-level GKScore only has player ID.
                    // if you want player display name, you need to combine it with
                    // the high-level API to load the players
                    string[] playerIDs = scores.Cast <GKScore>().Select(x => x.playerID).ToArray();
                    Player.LoadPlayersByIDs(playerIDs, delegate(Player[] players) {
                        // print localized title of leaderboard
                        //Log("Top 100 for " + leaderboardRequest.title);


                        //current user
                        GKScore score = leaderboardRequest.localPlayerScore;
                        int rank      = score.rank;
                        Player player = players[0];

                        //GameObject.Find ("TESTE").transform.GetChild(0).GetComponent<Text>().text="rank "+rank+" Score "+score+" Name "+player.displayName;

                        //All scores

                        /*for (int i=0; i<scores.Length; i++) {
                         *      GKScore score = scores[i] as GKScore;
                         *      Player player = players[i];
                         *      //plname = players[i];
                         *      testescore+=score.rank + ". " + score.formattedValue +", "+player.displayName;
                         *      //testescore+=score.rank + ". " + score.formattedValue;
                         *      //GameObject.Find ("TESTE").transform.GetChild(0).GetComponent<Text>().text="ShowScore "+testescore;
                         *      Debug.Log(score.rank + ". " + score.formattedValue + ", " + score.date + ", " + player.displayName);
                         * }*/
                    });
                }
            });
        }
                #endif

                #if UNITY_ANDROID && !UNITY_EDITOR
        /*ILeaderboard lb = Social.CreateLeaderboard();
         * lb.id = leaderboardID;
         * lb.LoadScores(ok =>
         *            {
         *      if (ok) {
         *              androidstatus="OK retrieving leaderboard";
         *              LoadUsersAndDisplay(lb);
         *      }
         *      else {
         *              androidstatus="Error retrieving leaderboard";
         *      }
         * });*/
                #endif
    }
示例#19
0
    void RetrieveTopTenScores()
    {
        GKLeaderboard leaderboardRequest = new GKLeaderboard();
        if (leaderboardRequest != null) {
            // configure request
            leaderboardRequest.playerScope = GKLeaderboardPlayerScope.Global;
            leaderboardRequest.timeScope = GKLeaderboardTimeScope.AllTime;
            leaderboardRequest.category = leaderboardID;
            leaderboardRequest.range = new NSRange(1, 10);

            // load scores; it calls delegate back when done
            leaderboardRequest.LoadScores(delegate(object[] scores, NSError error) {
                if (error != null) {
                    Log("Error retrieving scores: " + error.LocalizedDescription());
                } else if (scores != null) {

                    // got the scores, but the low-level GKScore only has player ID.
                    // if you want player display name, you need to combine it with
                    // the high-level API to load the players
                    string[] playerIDs = scores.Cast<GKScore>().Select(x => x.playerID).ToArray();
                    Player.LoadPlayersByIDs(playerIDs, delegate(Player[] players) {

                        // print localized title of leaderboard
                        Log("Top 10 for " + leaderboardRequest.title);

                        for (int i=0; i<scores.Length; i++) {
                            GKScore score = scores[i] as GKScore;
                            Player player = players[i];
                            Log(score.rank + ". " + score.formattedValue + ", " + score.date + ", " + player.displayName);
                        }
                    });
                }
            });
        }
    }
示例#20
0
 public GKLeaderboard GetLeaderboard()
 {
     GKLeaderboard leaderboard = new GKLeaderboard ();
     leaderboard.Category = GamePhysics.LeaderboardID;
     return leaderboard;
 }
		void SetAuthenticateHandler ()
		{
			GKLocalPlayer.LocalPlayer.AuthenticateHandler = (ui, error) => {
				if (ui != null) {
					PresentViewController (ui, true, null);
				} else if (GKLocalPlayer.LocalPlayer.Authenticated) {
					currentLeaderBoard = gameCenterManager.ReloadLeaderboard (currentCategory);
					UpdateHighScore ();
				} else {
					var alert = new UIAlertView ("Game Center Account Required", "Need login the game center!", null, "Retry", null);
					alert.Clicked += (sender, e) => {
						//GKLocalPlayer.LocalPlayer.Authenticated();
					};
					alert.Show ();
				}
			};
		}
示例#22
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]);
			});
		}
        public override void GetBestScoreAndRank(GameMode mode, GameDifficulty difficulty, Action<int,int> gcRankCallback)
        {
            if (IsAuthenticated)
              {

            if (gcRankCallback != null)
            {

              string leaderboardId = GetLeaderboardId(mode, difficulty);
              GKLeaderboard leaderboard = new GKLeaderboard();
              leaderboard.GroupIdentifier = leaderboardId;

              leaderboard.LoadScores((scoreArray, error) => {

            if (leaderboard.LocalPlayerScore != null)
            {
              int bestScore = (int) leaderboard.LocalPlayerScore.Value;
              int bestRank = leaderboard.LocalPlayerScore.Rank;

              gcRankCallback(bestRank, bestScore);
            }
              });

            }
              }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            InitGameCenter();

            string[] categories     = { "Easy", "Hard", "Awesome" };
            var      selectCategory = new UIActionSheet("Choose Leaderboard", null, "Cancel", null, categories);

            selectCategory.Dismissed += (sender, e) => {
                switch (e.ButtonIndex)
                {
                case 0:
                    currentCategory = EasyLeaderboardID;
                    this.selectLeaderBoardButton.SetTitle("Leaderboard: Easy", UIControlState.Normal);
                    currentScore = 0;
                    currentScoreTextField.Text = "0";
                    break;

                case 1:
                    currentCategory = HardLeaderboardID;
                    this.selectLeaderBoardButton.SetTitle("Leaderboard: Hard", UIControlState.Normal);
                    currentScore = 0;
                    currentScoreTextField.Text = "0";
                    break;

                case 2:
                    currentCategory = AwesomeLeaderboardID;
                    this.selectLeaderBoardButton.SetTitle("Leaderboard: Awesome", UIControlState.Normal);
                    currentScore = 0;
                    currentScoreTextField.Text = "0";
                    break;

                default:
                    break;
                }
                currentLeaderBoard = gameCenterManager.ReloadLeaderboard(currentCategory);
                UpdateHighScore();
            };

            selectLeaderBoardButton.TouchUpInside += (sender, e) => selectCategory.ShowInView(this.View);

            showLeaderboardButton.TouchUpInside += (sender, e) => {
                var leaderboardController = new GKLeaderboardViewController();
                leaderboardController.Category   = currentCategory;
                leaderboardController.TimeScope  = GKLeaderboardTimeScope.AllTime;
                leaderboardController.DidFinish += (senderLeaderboard, eLeaderboard) => leaderboardController.DismissViewController(true, null);
                PresentViewController(leaderboardController, true, null);
            };

            showAchievementButton.TouchUpInside += (sender, e) => {
                var achievementController = new GKAchievementViewController();
                achievementController.DidFinish += (senderAchievement, eAchievement) => achievementController.DismissViewController(true, null);
                PresentViewController(achievementController, true, null);
            };

            incrementScoreButton.TouchUpInside += (sender, e) => {
                currentScore++;
                currentScoreTextField.Text = currentScore.ToString();
                CheckAchievements();
            };

            submitScoreButton.TouchUpInside += (sender, e) => {
                if (currentScore > 0)
                {
                    gameCenterManager.ReportScore(currentScore, currentCategory, this);
                }
            };

            resetButton.TouchUpInside += (sender, e) => gameCenterManager.ResetAchievement();
        }
示例#25
0
 public void DefaultCtor()
 {
     using (var lb = new GKLeaderboard()) {
         Check(lb);
     }
 }
示例#26
0
        public void Login()
        {
            GKLocalPlayer player = GKLocalPlayer.LocalPlayer;

            if (!player.Authenticated)
            {
                player.AuthenticateHandler = (UIViewController controller, NSError error) =>
                {
                    if (controller != null)
                    {
                        UIViewController parent = AppMain.Current.Services.GetService(typeof(UIViewController)) as UIViewController;
                        parent.PresentViewController(controller, true, null);
                    }
                    else
                    {
                        if (GKLocalPlayer.LocalPlayer.Authenticated)
                        {
                            _enabled = true;

                            GKLeaderboard.LoadLeaderboards((GKLeaderboard[] leaderboards, NSError error3) =>
                            {
                                if (leaderboards != null && leaderboards.Length > 0 && _leaderboardInfo != null)
                                {
                                    LeaderboardInfo[] info = new LeaderboardInfo[leaderboards.Length];

                                    for (int idx = 0; idx < leaderboards.Length; ++idx)
                                    {
                                        GKLeaderboard lb = leaderboards[idx];

                                        int score = 0;

                                        if (lb.LocalPlayerScore != null)
                                        {
                                            score = (int)lb.LocalPlayerScore.Value;
                                        }

                                        info[idx] = new LeaderboardInfo(lb.Identifier)
                                        {
                                            Score = score
                                        };
                                    }

                                    _leaderboardInfo(info);
                                }
                            });

                            GKAchievement.LoadAchievements((GKAchievement[] achievements, NSError error2) =>
                            {
                                if (achievements != null && achievements.Length > 0 && _achievementInfo != null)
                                {
                                    AchievementInfo[] info = new AchievementInfo[achievements.Length];

                                    for (int idx = 0; idx < achievements.Length; ++idx)
                                    {
                                        GKAchievement ach = achievements[idx];

                                        info[idx] = new AchievementInfo(ach.Identifier)
                                        {
                                            Completion = ach.Completed ? Achievement.Completed : (int)ach.PercentComplete
                                        };
                                    }

                                    _achievementInfo(info);
                                }
                            });
                        }
                    }
                };
            }
        }
示例#27
0
		void LoadLeaderboard (GKLeaderboard[] leaderboards, NSError error)
		{
			this.leaderboards = leaderboards;
			int offset = 0;
			foreach (var leaderboard in leaderboards) {
				SKLabelNode leaderboardButton = new SKLabelNode ("GillSans-Bold") {
					Text = leaderboard.Title,
					FontSize = 18,
					Position = new PointF (FrameMidX, FrameMidY + 125 - offset)
				};
				offset += 50;

				AddChild (leaderboardButton);
				leaderboardButtons.Add (leaderboardButton);
			}
		}
示例#28
0
        public async void checkHighest(int sc, string level)
        {
            string catString = "com.commtech.inapppurchTest.StageScores";              //com.commtech.inapppurchTest.

            GKLocalPlayer xx = GKLocalPlayer.LocalPlayer;

            GKLeaderboard Leaderboard = new GKLeaderboard(new [] { xx.PlayerID })
            {
                Identifier = catString
            };

            var ss = Leaderboard.LocalPlayerScore;
            //var scores = await Leaderboard.LoadScoresAsync ();
            var oldScore = 0;            //ss.Value;
            //var oldScore = current.Value;

//			if (ss.Value != null) {
//
//				oldScore = (int)ss.Value;
//			}
//			var Category = Convert.ToInt64(  level.Substring (1, 1));
//
//			Console.WriteLine ("XXXXXXXXXXXXXXXXXXMXMXMXMXMMXMXMXXXXXXMXMXMXXXXXXXX");
//

//			if (oldScore == null) {
            var newScore = new GKScore(catString)
            {
                Value = sc
            };

            newScore.ReportScore(new Action <NSError> ((error) => {
                if (error == null)
                {
                    Console.WriteLine("YYYYYYYYYYYYYYYYYYYYYYYYYYBBBYYYBYBYBYBYYyy");

                    //new UIAlertView ("Score reported", "Score Reported successfully", null, "OK", null).Show ();
                }
                else
                {
                    Console.WriteLine("XXXXXXXXXXXXXXXXXXMXMXMXMXMMXMXMXXXXXXMXMXMXXXXXXXX");

                    //new UIAlertView ("Score Reported Failed", "Score Reported Failed", null, "OK", null).Show ();
                }
                NSThread.SleepFor(1);
                //controller.updateHighScore ();
            }));

//
//			Console.WriteLine ("score::"  + newScore.Value);
//				await GKScore.ReportScoresAsync(new [] {  newScore });
////
//			}
//			else if (sc > oldScore) {
//			//	gcm.reportScore (sc, car);
//				var newScore = new GKScore (catString) {
//					Value = sc
//
//				};
//
//				//await GKScore.ReportScoresAsync(new [] {  newScore });
//
//			}


            //GameCenterManager1 gcm = new GameCenterManager1 ();
        }