当前位置: 首页>>代码示例>>Java>>正文


Java Games类代码示例

本文整理汇总了Java中com.google.android.gms.games.Games的典型用法代码示例。如果您正苦于以下问题:Java Games类的具体用法?Java Games怎么用?Java Games使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Games类属于com.google.android.gms.games包,在下文中一共展示了Games类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import com.google.android.gms.games.Games; //导入依赖的package包/类
/**
 * Initializes the GoogleApiClient. Give your main AndroidLauncher as context.
 * <p>
 * Don't forget to add onActivityResult method there with call to onGpgsActivityResult.
 *
 * @param context        your AndroidLauncher class
 * @param enableDriveAPI true if you activate save gamestate feature
 * @return this for method chunking
 */
public GpgsClient initialize(Activity context, boolean enableDriveAPI) {

    if (mGoogleApiClient != null)
        throw new IllegalStateException("Already initialized.");

    myContext = context;
    // retry some times when connect fails (needed when game state sync is enabled)
    firstConnectAttempt = MAX_CONNECTFAIL_RETRIES;

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(myContext)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES);

    driveApiEnabled = enableDriveAPI;
    if (driveApiEnabled)
        builder.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER);

    // add other APIs and scopes here as needed

    mGoogleApiClient = builder.build();

    return this;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:34,代码来源:GpgsClient.java

示例2: delete

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public PendingResult<DeleteSnapshotResult> delete(GoogleApiClient googleApiClient,
                                                  final SnapshotMetadata snapshotMetadata) {
    if (!isAlreadyOpen(snapshotMetadata.getUniqueName()) &&
            !isAlreadyClosing(snapshotMetadata.getUniqueName())) {
        setIsClosing(snapshotMetadata.getUniqueName());
        try {
            return new CoordinatedPendingResult<>(
                    Games.Snapshots.delete(googleApiClient, snapshotMetadata),
                    new ResultListener() {
                        @Override
                        public void onResult(Result result) {
                            // deleted files are closed.
                            setClosed(snapshotMetadata.getUniqueName());
                        }
                    });
        } catch (RuntimeException e) {
            setClosed(snapshotMetadata.getUniqueName());
            throw e;
        }
    } else {
        throw new IllegalStateException(snapshotMetadata.getUniqueName() +
                " is either open or is busy");
    }
}
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:26,代码来源:SnapshotCoordinator.java

示例3: openLeaderboard

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void openLeaderboard() {
    Log.d(LOG_TAG, "The user opened the leaderboard");

    GoogleApiClientCallback myActivity = (GoogleApiClientCallback) getActivity();
    GoogleApiClient myClient = myActivity.getGoogleApiClient();

    if (myClient.isConnected()) {
        startActivityForResult(
                Games.Leaderboards.getAllLeaderboardsIntent(myClient),
                RC_UNUSED);
    } else {
        BaseGameUtils.makeSimpleDialog(
                getActivity(),
                getString(R.string.leaderboards_not_available))
                .show();
    }
}
 
开发者ID:jaysondc,项目名称:TripleTap,代码行数:19,代码来源:GameOverFragment.java

示例4: matchCompleted

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void matchCompleted(boolean victory) {
	if(!isSignedIn())
		return;

	Games.Achievements.unlock(gameHelper.getApiClient(),
			getString(R.string.achievement_your_first_match));
	Games.Achievements.increment(gameHelper.getApiClient(),
			getString(R.string.achievement_5_matches), 1);
	Games.Achievements.increment(gameHelper.getApiClient(),
			getString(R.string.achievement_25_matches), 1);
	Games.Achievements.increment(gameHelper.getApiClient(),
			getString(R.string.achievement_50_matches), 1);

	if(victory) {
		Games.Achievements.increment(gameHelper.getApiClient(),
				getString(R.string.achievement_10_wins), 1);
		Games.Achievements.increment(gameHelper.getApiClient(),
				getString(R.string.achievement_25_wins), 1);
		Games.Achievements.increment(gameHelper.getApiClient(),
				getString(R.string.achievement_50_wins), 1);
	}
}
 
开发者ID:antonioalmeida,项目名称:retro-reversi,代码行数:24,代码来源:AndroidLauncher.java

示例5: startMatch

import com.google.android.gms.games.Games; //导入依赖的package包/类
public void startMatch(TurnBasedMatch match) {
	System.out.println("Started match");

	mTurnData = new GameModelWrapper();

	mMatch = match;

	String playerId = Games.Players.getCurrentPlayerId(gameHelper.getApiClient());
	String myParticipantId = mMatch.getParticipantId(playerId);

	Games.TurnBasedMultiplayer.takeTurn(gameHelper.getApiClient(), match.getMatchId(),
			mTurnData.convertToByteArray(), myParticipantId).setResultCallback(
			new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
				@Override
				public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
					processResult(result);
				}
			});
}
 
开发者ID:antonioalmeida,项目名称:retro-reversi,代码行数:20,代码来源:AndroidLauncher.java

示例6: onConnected

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
  Log.d(TAG, "onConnected() called. Sign in successful!");

  Log.d(TAG, "Sign-in succeeded.");

  // register listener so we are notified if we receive an invitation to play
  // while we are in the game
  Games.Invitations.registerInvitationListener(mGoogleApiClient, this);

  if (connectionHint != null) {
    Log.d(TAG, "onConnected: connection hint provided. Checking for invite.");
    Invitation inv = connectionHint
        .getParcelable(Multiplayer.EXTRA_INVITATION);
    if (inv != null && inv.getInvitationId() != null) {
      // retrieve and cache the invitation ID
      Log.d(TAG,"onConnected: connection hint has a room invite!");
      acceptInviteToRoom(inv.getInvitationId());
      return;
    }
  }
  switchToMainScreen();

}
 
开发者ID:ezet,项目名称:penguins-in-space,代码行数:25,代码来源:Example.java

示例7: onConnectedToRoom

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnectedToRoom(Room room) {
    Log.d(TAG, "onConnectedToRoom.");

    //get participants and my ID:
    mParticipants = room.getParticipants();
    mMyId = room.getParticipantId(Games.Players.getCurrentPlayerId(mGoogleApiClient));
    
     // save room ID if its not initialized in onRoomCreated() so we can leave cleanly before the game starts.
     if(mRoomId==null)
      mRoomId = room.getRoomId();

    // print out the list of participants (for debug purposes)
    Log.d(TAG, "Room ID: " + mRoomId);
    Log.d(TAG, "My ID " + mMyId);
    Log.d(TAG, "<< CONNECTED TO ROOM>>");
}
 
开发者ID:ezet,项目名称:penguins-in-space,代码行数:18,代码来源:Example.java

示例8: onStop

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onStop(int score) {
    animateTitle(true);
    gameView.setOnClickListener(this);

    int highScore = prefs.getInt(PreferenceUtils.PREF_HIGH_SCORE, 0);
    if (score > highScore) {
        //TODO: awesome high score animation or something
        highScore = score;
        prefs.edit().putInt(PreferenceUtils.PREF_HIGH_SCORE, score).apply();

        if (isConnected())
            Games.Leaderboards.submitScore(apiClient, getString(R.string.leaderboard_high_score), highScore);
    }

    highScoreView.setText(String.format(getString(R.string.score_high), highScore));

    if (achievementUtils != null)
        achievementUtils.onStop(score);
}
 
开发者ID:TheAndroidMaster,项目名称:Asteroid,代码行数:21,代码来源:MainActivity.java

示例9: onConnected

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) 
{
	// The player is signed in. Hide the sign-in button and allow the
	// player to proceed.
	Log.i("yoyo","Sign In Succeeded");
	
	
	Player p = Games.Players.getCurrentPlayer(getApiClient());
       String displayName;
       String id;
       if (p == null) {
           Log.i("yoyo", "mGamesClient.getCurrentPlayer() is NULL!");
           displayName = "???";
           id="-1";
       }
       else {
           displayName = p.getDisplayName();
           id = p.getPlayerId();
       }
       
       Log.i("yoyo","Found displayname " + displayName + " with id " + id);
	
	RunnerJNILib.OnLoginSuccess(displayName,id,"","","","","");
	
	//Call back to generate the social event 
}
 
开发者ID:Magicrafter13,项目名称:1946,代码行数:28,代码来源:GooglePlayServicesExtension.java

示例10: Logout

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void Logout()
{
	if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) 
	{
		mSignInClicked= false;
		Games.signOut(mGoogleApiClient);
		mGoogleApiClient.disconnect();
		Log.i("yoyo","Logged out of Google Play Services");
		RunnerJNILib.OnLoginSuccess("Not logged in","-1","","","","","");
	}
}
 
开发者ID:Magicrafter13,项目名称:1946,代码行数:13,代码来源:GooglePlayServicesExtension.java

示例11: rematch

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void rematch() {
	Games.TurnBasedMultiplayer.rematch(gameHelper.getApiClient(), mMatch.getMatchId()).setResultCallback(
			new ResultCallback<TurnBasedMultiplayer.InitiateMatchResult>() {
				@Override
				public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) {
					processResult(result);
				}
			});
	mMatch = null;
	isDoingTurn = false;
}
 
开发者ID:antonioalmeida,项目名称:retro-reversi,代码行数:13,代码来源:AndroidLauncher.java

示例12: onConnected

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnected(Bundle bundle) {
    super.onConnected(bundle);
    if (googleResource == Constants.LEADERBOARD)
        startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
    else
        startActivityForResult(Games.Achievements.getAchievementsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
}
 
开发者ID:simoneapp,项目名称:S3-16-simone,代码行数:9,代码来源:ScoreboardActivity.java

示例13: onShowGSAchievements

import com.google.android.gms.games.Games; //导入依赖的package包/类
public void onShowGSAchievements()
  {
if (isSignedIn()) {
          RunnerActivity.CurrentActivity.startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), RC_GPS_ACTIVITY);
      }
      else {
          (new AlertDialog.Builder(RunnerActivity.CurrentActivity))
             .setTitle("Achievement Not Available")
             .setMessage("You can't view achievements because you are not signed in.")
                .setNeutralButton("OK", null)
                .show();
      }
  }
 
开发者ID:Magicrafter13,项目名称:1946,代码行数:14,代码来源:GooglePlayServicesExtension.java

示例14: openIfConnected

import com.google.android.gms.games.Games; //导入依赖的package包/类
private void openIfConnected() {
    if (App.getGoogleApiHelper().getGoogleApiClient() == null || !App.getGoogleApiHelper().getGoogleApiClient().isConnected()) {
        Message msg = new Message();
        msg.what = Constants.CONNECT;
        msg.obj = this;
        googleHandler.sendMessage(msg);
    } else {
        if (googleResource == Constants.LEADERBOARD)
            startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
        else
            startActivityForResult(Games.Achievements.getAchievementsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
    }
}
 
开发者ID:simoneapp,项目名称:S3-16-simone,代码行数:14,代码来源:ScoreboardActivity.java

示例15: showLeaderboards

import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void showLeaderboards(String leaderBoardId) throws GameServiceException {
    if (isSessionActive()) {
        if (gpgsLeaderboardIdMapper != null)
            leaderBoardId = gpgsLeaderboardIdMapper.mapToGsId(leaderBoardId);

        myContext.startActivityForResult(leaderBoardId != null ?
                Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, leaderBoardId) :
                Games.Leaderboards.getAllLeaderboardsIntent(mGoogleApiClient), RC_LEADERBOARD);
    } else
        throw new GameServiceException.NoSessionException();
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:13,代码来源:GpgsClient.java


注:本文中的com.google.android.gms.games.Games类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。