Beispiel #1
0
 // Accept the given invitation.
 void AcceptInviteToRoom(string invId)
 {
     // accept the invitation
     Log.Debug(TAG, "Accepting invitation: " + invId);
     RoomConfig.Builder roomConfigBuilder = RoomConfig.InvokeBuilder(this);
     roomConfigBuilder.SetInvitationIdToAccept(invId)
     .SetMessageReceivedListener(this)
     .SetRoomStatusUpdateListener(this);
     SwitchToScreen(Resource.Id.screen_wait);
     KeepScreenOn();
     ResetGameVars();
     GamesClass.RealTimeMultiplayer.Join(mGoogleApiClient, roomConfigBuilder.Build());
 }
        public void AcceptInvite(string invitationId)
        {
            //auto accept
            _roomFragment = new RoomFragment();
            SupportFragmentManager.BeginTransaction()
            .Replace(Resource.Id.FragmentContainer, _roomFragment)
            .Commit();
            var builder = RoomConfig.InvokeBuilder(this);

            builder.SetInvitationIdToAccept(invitationId);
            builder.SetMessageReceivedListener(this);
            GamesClient.JoinRoom(builder.Build());
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);
        }
Beispiel #3
0
        void StartQuickGame()
        {
            // quick-start a game with 1 randomly selected opponent
            int    MIN_OPPONENTS = 1, MAX_OPPONENTS = 1;
            Bundle autoMatchCriteria = RoomConfig.CreateAutoMatchCriteria(MIN_OPPONENTS,
                                                                          MAX_OPPONENTS, 0);

            RoomConfig.Builder rtmConfigBuilder = RoomConfig.InvokeBuilder(this);
            rtmConfigBuilder.SetMessageReceivedListener(this);
            rtmConfigBuilder.SetRoomStatusUpdateListener(this);
            rtmConfigBuilder.SetAutoMatchCriteria(autoMatchCriteria);
            SwitchToScreen(Resource.Id.screen_wait);
            KeepScreenOn();
            ResetGameVars();
            GamesClass.RealTimeMultiplayer.Create(mGoogleApiClient, rtmConfigBuilder.Build());
        }
Beispiel #4
0
        // Handle the result of the "Select players UI" we launched when the user clicked the
        // "Invite friends" button. We react by creating a room with those players.
        private void HandleSelectPlayersResult(Result response, Intent data)
        {
            if (response != Result.Ok)
            {
                Log.Warn(TAG, "*** select players UI cancelled, " + response);
                SwitchToMainScreen();
                return;
            }

            Log.Debug(TAG, "Select players UI succeeded.");

            // get the invitee list
            var invitees = data.GetStringArrayListExtra(GamesClass.ExtraPlayerIds);

            Log.Debug(TAG, "Invitee count: " + invitees.Count);

            // get the automatch criteria
            Bundle autoMatchCriteria   = null;
            int    minAutoMatchPlayers = data.GetIntExtra(Multiplayer.ExtraMinAutomatchPlayers, 0);
            int    maxAutoMatchPlayers = data.GetIntExtra(Multiplayer.ExtraMaxAutomatchPlayers, 0);

            if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0)
            {
                autoMatchCriteria = RoomConfig.CreateAutoMatchCriteria(
                    minAutoMatchPlayers, maxAutoMatchPlayers, 0);
                Log.Debug(TAG, "Automatch criteria: " + autoMatchCriteria);
            }

            // create the room
            Log.Debug(TAG, "Creating room...");
            RoomConfig.Builder rtmConfigBuilder = RoomConfig.InvokeBuilder(this);
            rtmConfigBuilder.AddPlayersToInvite(invitees);
            rtmConfigBuilder.SetMessageReceivedListener(this);
            rtmConfigBuilder.SetRoomStatusUpdateListener(this);
            if (autoMatchCriteria != null)
            {
                rtmConfigBuilder.SetAutoMatchCriteria(autoMatchCriteria);
            }
            SwitchToScreen(Resource.Id.screen_wait);
            KeepScreenOn();
            ResetGameVars();
            GamesClass.RealTimeMultiplayer.Create(mGoogleApiClient, rtmConfigBuilder.Build());
            Log.Debug(TAG, "Room created, waiting for it to be ready...");
        }
Beispiel #5
0
        public override View OnCreateView(LayoutInflater p0, ViewGroup p1, Bundle p2)
        {
            var view = p0.Inflate(Resource.Layout.Lobby, p1, false);

            _builder = RoomConfig.InvokeBuilder((GameActivity)Activity);
            _builder.SetMessageReceivedListener((GameActivity)Activity);

            var autoMatch = view.FindViewById <Button>(Resource.Id.AutoMatch);

            autoMatch.Click += delegate
            {
                var am = RoomConfig.CreateAutoMatchCriteria(1, 1, 0);
                _builder.SetAutoMatchCriteria(am);
                _config = _builder.Build();
                ((GameActivity)Activity).GamesClient.CreateRoom(_config);
                Activity.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
                autoMatch.Enabled = false;
            };

            var hostGame = view.FindViewById <Button>(Resource.Id.HostGame);

            hostGame.Click += delegate
            {
                var intent = ((GameActivity)Activity).GamesClient.GetSelectPlayersIntent(1, 1);
                StartActivityForResult(intent, FriendsIntent);
            };

            var joinGame = view.FindViewById <Button>(Resource.Id.JoinGame);

            joinGame.Click += delegate
            {
                var intent = ((GameActivity)Activity).GamesClient.InvitationInboxIntent;
                StartActivityForResult(intent, InboxIntent);
            };

            return(view);
        }