Example #1
0
            public override void PlayerQuitForMatch(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
            {
                Logger.I("MatchMakerDelegate.PlayerQuitForMatch");

                // Mark current player as quiter
                foreach (GKTurnBasedParticipant participant in match.Participants)
                {
                    if (participant.PlayerID == GKLocalPlayer.LocalPlayer.PlayerID)
                    {
                        participant.MatchOutcome = GKTurnBasedMatchOutcome.Quit;
                    }
                    else
                    {
                        // Win?
                        participant.MatchOutcome = GKTurnBasedMatchOutcome.Won;
                    }
                }

                //viewController.DismissViewController (true, null);

                // Delete the match
                match.Remove(new GKNotificationHandler((error) => {
                    Logger.E("MatchMakerDelegate.PlayerQuitForMatch: " + error.DebugDescription);
                }));

                if (PlayerQuitCallback != null)
                {
                    PlayerQuitCallback();
                }
            }
Example #2
0
        /// <summary>
        /// Send a photo to a friend via GameCenter
        /// </summary>
        /// <param name="matchFoundCallback">Match found callback.</param>
        /// <param name="cancelCallback">Cancel callback.</param>
        /// <param name="errorCallback">Error callback.</param>
        /// <param name="playerQuitCallback">Player quit callback.</param>
        public static void NewVersusPhoto(Action <UIViewController> showCallback, Action <PuzzleData> matchFoundCallback, Action cancelCallback, Action errorCallback, Action playerQuitCallback)
        {
            Logger.I("Game center: new turn based match request...");

            GKMatchRequest matchRequest = new GKMatchRequest();

            matchRequest.MinPlayers             = 2;
            matchRequest.MaxPlayers             = 2;
            matchRequest.DefaultNumberOfPlayers = 2;

            GKTurnBasedMatchmakerViewController matchMakerVc = new GKTurnBasedMatchmakerViewController(matchRequest);
            var d = new MatchMakerDelegate();

            d.MatchFoundCallback += matchFoundCallback;
            d.CancelCallback     += cancelCallback;
            d.ErrorCallback      += errorCallback;
            d.PlayerQuitCallback += playerQuitCallback;

            matchMakerVc.Delegate = d;

            if (showCallback != null)
            {
                showCallback(matchMakerVc);
            }
        }
Example #3
0
        /// <summary>
        /// Brings up the match making interface to start or join a turn-based match with other players.
        /// Raises TurnChanged, MatchMakerCancelled, and MatchMakerFailed events.
        /// </summary>
        /// <param name="minPlayers">The minimum nubmer of players that can join a match; between 2 and 4 inclusively.</param>
        /// <param name="maxPlayers">The maximum number of players that can join a match; between 2 and 4 inclusively.</param>
        /// <param name="playersToInvite">An array of Player instances; this is passed in from the PlayersInvited event.</param>
        /// <param name="showExistingMatches">If set to <c>true</c> show existing matches.</param>
        public static void StartMatch(uint minPlayers, uint maxPlayers, Player[] playersToInvite = null, bool showExistingMatches = true)
        {
            if ((minPlayers < 2) || (minPlayers > 16) || (maxPlayers < 2) || (maxPlayers > 16) || (maxPlayers < minPlayers))
            {
                throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 16.");
            }

            // create request
            var request = new GKMatchRequest();

            request.minPlayers = minPlayers;
            request.maxPlayers = maxPlayers;
            if (playersToInvite != null)
            {
                request.playersToInvite = Player.PlayersToIDs(playersToInvite);
            }

            // create view controller
            var mmvc = new GKTurnBasedMatchmakerViewController(request);

            mmvc.showExistingMatches         = showExistingMatches;
            mmvc.turnBasedMatchmakerDelegate = TurnBasedMatchmakerViewControllerDelegate.instance;

            // show it
            UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null);
        }
Example #4
0
            public override void FailedWithError(GKTurnBasedMatchmakerViewController viewController, MonoTouch.Foundation.NSError error)
            {
                Logger.W("MatchMakerDelegate.FailedWithError");

                viewController.DismissViewController(true, null);

                if (ErrorCallback != null)
                {
                    ErrorCallback();
                }
            }
Example #5
0
            public override void WasCancelled(GKTurnBasedMatchmakerViewController viewController)
            {
                Logger.I("MatchMakerDelegate.WasCancelled");

                viewController.DismissViewController(true, null);

                if (CancelCallback != null)
                {
                    CancelCallback();
                }
            }
Example #6
0
            public override void FoundMatch(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
            {
                Logger.I("MatchMakerDelegate.FoundMatch");

                viewController.DismissViewController(true, null);

                PuzzleData puzzleData = new PuzzleData();

                puzzleData.Match   = match;
                puzzleData.MatchId = match.MatchID;

                bool matchError = false;

                if (match.MatchData.Length > 0)
                {
                    // Match has data
//					var tp = GameCenterHelper.GetPuzzleFromMatch (match);
                    // TODO ?
                }
                else
                {
                    // No data: new match

                    // Set up outcomes
                    // -> Player who sent the picture set a time first
                    match.Participants [0].MatchOutcome = GKTurnBasedMatchOutcome.First;
                    match.Participants [1].MatchOutcome = GKTurnBasedMatchOutcome.Second;
                }

                if (matchError == false)
                {
                    match.Remove(new GKNotificationHandler((e) => {}));

                    if (MatchFoundCallback != null)
                    {
                        MatchFoundCallback(puzzleData);
                    }
                }
                else
                {
                    if (ErrorCallback != null)
                    {
                        ErrorCallback();
                    }
                }
            }
Example #7
0
            public override void TurnBasedMatchmakerViewControllerDidFailWithError(GKTurnBasedMatchmakerViewController viewController, NSError error)
            {
                // Automatically close the VC.
                if (viewController != null)
                {
                    viewController.DismissViewController(true, null);
                }

                if (ResetMatchmakerVC != null)
                {
                    ResetMatchmakerVC();
                }

                // Invoke consumer callback.
                if (ErrorCallback != null)
                {
                    ErrorCallback(error != null ? error.LocalizedDescription : string.Empty);
                }
            }
Example #8
0
            public override void TurnBasedMatchmakerViewControllerWasCancelled(GKTurnBasedMatchmakerViewController viewController)
            {
                // Automatically close the VC.
                if (viewController != null)
                {
                    viewController.DismissViewController(true, null);
                }

                if (ResetMatchmakerVC != null)
                {
                    ResetMatchmakerVC();
                }

                // Invoke consumer callback.
                if (CancelCallback != null)
                {
                    CancelCallback();
                }
            }
Example #9
0
        public override void WasCancelled(GKTurnBasedMatchmakerViewController viewController)
        {
            UIApplication.deviceRootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerCancelled();
        }
        public override void WasCancelled(GKTurnBasedMatchmakerViewController viewController)
        {
            UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerCancelled();
        }
        public override void DidFind(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
        {
            UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerFoundMatch(match);
        }
 public override void PlayerQuit(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
 {
     TurnBasedMatchesController._OnPlayerQuit(match);
 }
        public override void WasCancelled(GKTurnBasedMatchmakerViewController viewController)
        {
            UIApplication.deviceRootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerCancelled();
        }
        public override void DidFail(GKTurnBasedMatchmakerViewController viewController, NSError error)
        {
            UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerFailed(error);
        }
Example #15
0
            public override void PlayerQuitForMatch(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
            {
                Logger.I ("MatchMakerDelegate.PlayerQuitForMatch");

                // Mark current player as quiter
                foreach (GKTurnBasedParticipant participant in match.Participants) {
                    if (participant.PlayerID == GKLocalPlayer.LocalPlayer.PlayerID) {
                        participant.MatchOutcome = GKTurnBasedMatchOutcome.Quit;
                    } else {
                        // Win?
                        participant.MatchOutcome = GKTurnBasedMatchOutcome.Won;
                    }
                }

                //viewController.DismissViewController (true, null);

                // Delete the match
                match.Remove (new GKNotificationHandler ((error) => {
                    Logger.E ("MatchMakerDelegate.PlayerQuitForMatch: " + error.DebugDescription);
                }));

                if (PlayerQuitCallback != null)
                    PlayerQuitCallback ();
            }
            public override void FoundMatch(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
            {
                Logger.I("Versus match found...");

                viewController.DismissViewController(true, null);

                this.parent.CurrentGKMatch = match;

                bool matchError = false;

                VersusMatch versusMatch = GameCenterHelper.ParseMatch(match);

                if (versusMatch == null)
                {
                  matchError = true;
                }
                else
                {
                  if (MatchFoundCallback != null)
                  {
                MatchFoundCallback(versusMatch);
                  }
                }

                if (matchError)
                {
                  GameCenterHelper.KillMatch(match);
                }
            }
Example #17
0
            public override void FailedWithError(GKTurnBasedMatchmakerViewController viewController, MonoTouch.Foundation.NSError error)
            {
                Logger.W ("MatchMakerDelegate.FailedWithError");

                viewController.DismissViewController (true, null);

                if (ErrorCallback != null)
                    ErrorCallback ();
            }
        /// <summary>
        /// Brings up the match making interface to start or join a turn-based match with other players.
        /// Raises TurnChanged, MatchMakerCancelled, and MatchMakerFailed events.
        /// </summary>
        /// <param name="minPlayers">The minimum nubmer of players that can join a match; between 2 and 4 inclusively.</param>
        /// <param name="maxPlayers">The maximum number of players that can join a match; between 2 and 4 inclusively.</param>
        /// <param name="playersToInvite">An array of Player instances; this is passed in from the PlayersInvited event.</param>
        /// <param name="showExistingMatches">If set to <c>true</c> show existing matches.</param>
        public static void StartMatch(uint minPlayers, uint maxPlayers, Player[] playersToInvite = null, bool showExistingMatches = true)
        {
            if ((minPlayers < 2) || (minPlayers > 16) || (maxPlayers < 2) || (maxPlayers > 16) || (maxPlayers < minPlayers))
                throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 16.");

            // create request
            var request = new GKMatchRequest();
            request.minPlayers = minPlayers;
            request.maxPlayers = maxPlayers;
            if (playersToInvite != null)
                request.playersToInvite = Player.PlayersToIDs(playersToInvite);

            // create view controller
            var mmvc = new GKTurnBasedMatchmakerViewController(request);

            mmvc.showExistingMatches = showExistingMatches;
            mmvc.turnBasedMatchmakerDelegate = TurnBasedMatchmakerViewControllerDelegate.instance;

            // show it
            UIApplication.SharedApplication().keyWindow.rootViewController.PresentViewController(mmvc, true, null);
        }
Example #19
0
        public override void DidFail(GKTurnBasedMatchmakerViewController viewController, NSError error)
        {
            UIApplication.deviceRootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerFailed(error);
        }
Example #20
0
 public virtual void TurnBasedMatchmakerViewControllerWasCancelled(GKTurnBasedMatchmakerViewController viewController)
 {
 }
Example #21
0
 public virtual void TurnBasedMatchmakerViewControllerDidFailWithError(GKTurnBasedMatchmakerViewController viewController, NSError error)
 {
 }
Example #22
0
        /// <summary>
        /// Send a photo to a friend via GameCenter
        /// </summary>
        /// <param name="matchFoundCallback">Match found callback.</param>
        /// <param name="cancelCallback">Cancel callback.</param>
        /// <param name="errorCallback">Error callback.</param>
        /// <param name="playerQuitCallback">Player quit callback.</param>
        public static void NewVersusPhoto(Action<UIViewController> showCallback, Action<PuzzleData> matchFoundCallback, Action cancelCallback, Action errorCallback, Action playerQuitCallback)
        {
            Logger.I ("Game center: new turn based match request...");

            GKMatchRequest matchRequest = new GKMatchRequest ();
            matchRequest.MinPlayers = 2;
            matchRequest.MaxPlayers = 2;
            matchRequest.DefaultNumberOfPlayers = 2;

            GKTurnBasedMatchmakerViewController matchMakerVc = new GKTurnBasedMatchmakerViewController (matchRequest);
            var d = new MatchMakerDelegate ();
            d.MatchFoundCallback += matchFoundCallback;
            d.CancelCallback += cancelCallback;
            d.ErrorCallback += errorCallback;
            d.PlayerQuitCallback += playerQuitCallback;

            matchMakerVc.Delegate = d;

            if (showCallback != null) {
                showCallback (matchMakerVc);
            }
        }
Example #23
0
        public override void DidFind(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
        {
            UIApplication.deviceRootViewController.DismissViewController(true, null);

            TurnBasedMatchesController._OnMatchMakerFoundMatch(match);
        }
Example #24
0
            public override void FoundMatch(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
            {
                Logger.I ("MatchMakerDelegate.FoundMatch");

                viewController.DismissViewController (true, null);

                PuzzleData puzzleData = new PuzzleData ();
                puzzleData.Match = match;
                puzzleData.MatchId = match.MatchID;

                bool matchError = false;

                if (match.MatchData.Length > 0) {
                    // Match has data
                //					var tp = GameCenterHelper.GetPuzzleFromMatch (match);
                    // TODO ?
                } else {
                    // No data: new match

                    // Set up outcomes
                    // -> Player who sent the picture set a time first
                    match.Participants [0].MatchOutcome = GKTurnBasedMatchOutcome.First;
                    match.Participants [1].MatchOutcome = GKTurnBasedMatchOutcome.Second;
                }

                if (matchError == false) {
                    match.Remove (new GKNotificationHandler ((e) => {}));

                    if (MatchFoundCallback != null) {
                        MatchFoundCallback (puzzleData);
                    }
                } else {
                    if (ErrorCallback != null) {
                        ErrorCallback ();
                    }
                }
            }
Example #25
0
 public override void PlayerQuit(GKTurnBasedMatchmakerViewController viewController, GKTurnBasedMatch match)
 {
     TurnBasedMatchesController._OnPlayerQuit(match);
 }
Example #26
0
            public override void WasCancelled(GKTurnBasedMatchmakerViewController viewController)
            {
                Logger.I ("MatchMakerDelegate.WasCancelled");

                viewController.DismissViewController (true, null);

                if (CancelCallback != null)
                    CancelCallback ();
            }
        public override void NewMatch(Action<VersusMatch> matchFoundCallback, Action cancelCallback, Action errorCallback, Action playerQuitCallback)
        {
            GKMatchRequest matchRequest = new GKMatchRequest();
              matchRequest.MinPlayers = 2;
              matchRequest.MaxPlayers = 2;
              matchRequest.DefaultNumberOfPlayers = 2;

              GKTurnBasedMatchmakerViewController matchMakerVc = new GKTurnBasedMatchmakerViewController(matchRequest);

              var mmDelegate = new MatchMakerDelegate(this);
              mmDelegate.MatchFoundCallback += matchFoundCallback;
              mmDelegate.CancelCallback += cancelCallback;
              mmDelegate.ErrorCallback += errorCallback;
              mmDelegate.PlayerQuitCallback += playerQuitCallback;
              matchMakerVc.Delegate = mmDelegate;

              ShowGameCenter(matchMakerVc);
        }