public override void OnTurnBasedTournamentWillBegin(SkillzSDK.TurnBasedMatch matchInfo) { GameplayController_TurnBased.Skillz_tookTurn = false; Application.LoadLevel("TurnBasedGameScene"); TBMInfo = matchInfo; PlayerUniqueID = matchInfo.Player.ID.ToString(); if (TBMInfo.SkillzDifficulty.HasValue) { MySkillzDelegate.SkillzDifficulty = (int)TBMInfo.SkillzDifficulty.Value; } else { MySkillzDelegate.SkillzDifficulty = 5; } //If the tournament is a continuation of an ongoing match, load the tournament data into the "GameData" instance. GameData = new TurnBasedGameData(); if (TBMInfo.ContinueMatchData.HasValue) { if (!GameData.ParseFrom(TBMInfo.ContinueMatchData.Value.GameData)) { Debug.LogError("Couldn't parse game data: '" + TBMInfo.ContinueMatchData.Value.GameData); return; } } //Otherwise, set the GameData instance to an empty value, with the current player name. else { GameData.Blocks = null; GameData.KnownPlayerIDScore = 0; GameData.UnknownPlayerIDScore = 0; GameData.KnownPlayerID = PlayerUniqueID; } }
protected override void Update() { base.Update(); //Update UI text. TurnsLeftUIText.text = TurnsLeft.ToString() + " left"; if (!SkillzSDK.Api.IsTournamentInProgress) { CurrentPlayerUIText.text = (IsPlayer1Turn ? "Player 1" : "Player 2"); } //If in online tournament, check for end of turn. if (SkillzSDK.Api.IsTournamentInProgress) { if (Skillz_tookTurn && !LocalPlayer.IsInputDisabled) { //Serialize the game data for output. string knownID = Skillz_GameData.KnownPlayerID; Skillz_GameData = new TurnBasedGameData(); Skillz_GameData.TurnsLeft = TurnsLeft; Skillz_GameData.KnownPlayerID = knownID; Skillz_GameData.SetScore(PlayerUniqueID, PlayerOneScore); Skillz_GameData.SetOtherScore(PlayerUniqueID, PlayerTwoScore); Skillz_GameData.Blocks = new int[GameGrid.Instance.GetGridSize().X, GameGrid.Instance.GetGridSize().Y]; for (int x = 0; x < GameGrid.Instance.GetGridSize().X; ++x) { for (int y = 0; y < GameGrid.Instance.GetGridSize().Y; ++y) { Vector2i loc = new Vector2i(x, y); GameGridBlock block = GameGrid.Instance.GetBlock(loc); if (block == null) { Skillz_GameData.Blocks[x, y] = -1; } else { Skillz_GameData.Blocks[x, y] = block.ColorID; } } } //Is the game over? if (TurnsLeft == 0) { SkillzSDK.TurnBasedMatchOutcome whoWon = SkillzSDK.TurnBasedMatchOutcome.NoOutcome; if (PlayerOneScore > PlayerTwoScore) { whoWon = SkillzSDK.TurnBasedMatchOutcome.Win; } else if (PlayerOneScore < PlayerTwoScore) { whoWon = SkillzSDK.TurnBasedMatchOutcome.Loss; } else { whoWon = SkillzSDK.TurnBasedMatchOutcome.Draw; } Skillz_tookTurn = false; SkillzSDK.Api.FinishTurn(Skillz_GameData.ToString(), SkillzSDK.TurnBasedRoundOutcome.NoOutcome, whoWon, PlayerOneScore.ToString(), PlayerOneScore, PlayerTwoScore); } //Otherwise, continue as normal. else { Skillz_tookTurn = false; SkillzSDK.Api.FinishTurn(Skillz_GameData.ToString(), SkillzSDK.TurnBasedRoundOutcome.NoOutcome, SkillzSDK.TurnBasedMatchOutcome.NoOutcome, PlayerOneScore.ToString(), PlayerOneScore, PlayerTwoScore); } } } //Otherwise, check for end of game. else { if (!LocalPlayer.IsInputDisabled && TurnsLeft <= 0) { Application.LoadLevel("PresentTurnBasedScore"); } } }