[英]GKTurnBasedMatch doesn't consistently advance to the next player (Xamarin, Apple GameKit)
我在棋盤游戲中使用基於回合的比賽,回合完成后,我調用GKTurnBasedMatch.EndTurn並將比賽參與者和新的比賽數據作為參數傳遞。 我需要將游戲推進到無與倫比的玩家手中,但是只有在與超時值相關的不確定時間之后,游戲才可以前進。 將超時值設置為0只會阻止游戲從玩家1前進。比賽數據正在更新,因此該應用程序肯定與Game Center服務器進行通信。 我在這里想念什么?
private void endTurn(double timeout)
{
// Copies list of participants to a mutable array
GKTurnBasedParticipant[] Participants = new GKTurnBasedParticipant[match.Participants.Length];
match.Participants.CopyTo(Participants, 0);
// Advances to the next player
match.EndTurn(Participants, timeout, matchData, (e) =>
{
// If there is an error message, print it to the console
if (e != null)
{
Console.WriteLine(e.LocalizedDescription);
Console.WriteLine(e.LocalizedFailureReason);
}
// Otherwise proceed normally
else
turnOverUpdate();
});
}
對於EndTurn方法,Apple的文檔非常差,但我知道了。 NextParticipants字段應像EndTurnWithNextParticipant一樣對待,因此您必須復制GKTurnBasedMatch.Participants並重新排序,以便下一個玩家排在第一位,第四位。 比賽只給您參與者的加入順序,而不是與本地球員的相對,因此您必須對其進行排序。 以下是我用來完成此操作的代碼。
List<GKTurnBasedParticipant> participants = new List<GKTurnBasedParticipant>();
// Gets the index of the local player
int index = 0;
for (int i = 0; i < match.Participants.Length; i++)
{
if (match.Participants[i].Player != null)
{
if (match.Participants[i].Player.PlayerID == GKLocalPlayer.LocalPlayer.PlayerID)
{
index = i;
break;
}
}
}
int offset = match.Participants.Length - index;
for (int i = 1; i < offset; i++)
participants.Add(match.Participants[i + index]);
for (int i = 0; i <= index; i++)
participants.Add(match.Participants[i]);
GKTurnBasedParticipant[] nextParticipants = participants.ToArray();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.