public void TakeTurn() { if (CurrentMatch == null) { NativeUI.Alert("Error", NullMatchMessage); return; } if (!IsMyTurn) { NativeUI.Alert("Warning", "Not your turn."); return; } if (CurrentMatchData == null) { NativeUI.Alert("Error", "Couldn't find any match data."); return; } if (AllOpponensLeft) { NativeUI.Alert("Error", AllOpponentsLeftMessage); return; } if (SelectedParticipantLeftMatch) { NativeUI.Alert("Error", SelectedParticipantLeftMessage); return; } GameServices.TurnBased.TakeTurn(CurrentMatch, CurrentMatchData.ToByteArray(), SelectedParticipant, success => { if (success) { canTakeTurn = false; NativeUI.Alert("Success", "Take turn successfully."); return; } NativeUI.Alert("Error", "Failed to take turn."); }); }
private void ShowMatchData() { if (CurrentMatch == null) { NativeUI.Alert("Error", NullMatchMessage); return; } if (CurrentMatchData == null) { NativeUI.Alert("Error", "The current match doesn't have any data to show."); return; } var bytes = CurrentMatchData.ToByteArray(); string dataSize = bytes != null ? (bytes.Length.ToString() + " byte(s)") : "Error"; string message = string.Format("Turn Count: {0}\nWinner Name: {1}\nSize: {2}", CurrentMatchData.TurnCount, CurrentMatchData.WinnerName, dataSize); NativeUI.Alert("Match Data", message); }
public void Finish() { if (CurrentMatch == null) { NativeUI.Alert("Error", NullMatchMessage); return; } if (!IsMyTurn) { NativeUI.Alert("Warning", "Not your turn."); return; } if (CurrentMatchData == null) { NativeUI.Alert("Error", "Couldn't find any match data."); return; } MatchOutcome outcome = new MatchOutcome(); outcome.SetParticipantResult(CurrentMatch.SelfParticipantId, MatchOutcome.ParticipantResult.Won); foreach (var id in CurrentOpponents.Select(p => p.ParticipantId)) { outcome.SetParticipantResult(id, MatchOutcome.ParticipantResult.Lost); } CurrentMatchData.WinnerName = CurrentMatch.Self.DisplayName; var callback = GetAlertCallbackAction("Finished the match successfully.", "Failed to finish the match."); callback += success => { if (success) { canTakeTurn = false; } }; GameServices.TurnBased.Finish(CurrentMatch, CurrentMatchData.ToByteArray(), outcome, callback); }