我正在开发一款回合制多人游戏 Android 应用程序。
最初,我必须实现 TurnBasedMultiplayerListener
并覆盖 onTurnBasedMatchInitiated
但现在该接口(interface)已弃用,我需要使用 this listener
问题是,我不知道如何使用它。我已经让我的类实现了接口(interface),并且覆盖了这些方法。
然后我创建一个turnBasedGame,如下所示...
PendingResult<InitiateMatchResult> f =
Games.TurnBasedMultiplayer.createMatch(gApiClient, tbmc);
现在我想我必须说f.setResultCallback(...)
但我不知道要在里面放什么。
有什么建议吗?
最佳答案
您需要提供一个实现 ResultCallback 作为参数的类。
public void MatchInitiatedCallback implements ResultCallback {
@Override
public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) {
// Check if the status code is not success;
if (result.getStatus != GamesStatusCodes.STATUS_OK) {
showError(statusCode);
return;
}
TurnBasedMatch match = result.getMatch();
// If this player is not the first player in this match, continue.
if (match.getData() != null) {
showTurnUI(match);
return;
}
// Otherwise, this is the first player. Initialize the game state.
initGame(match);
// Let the player take the first turn
showTurnUI(match);
}
}
关于java - 我如何使用这个新的监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21780525/