private void queryMatchState() { // Read match history // Query more detail state about the match App.Bc.AsyncMatchService .ReadMatch(App.OwnerId, App.MatchId, (response, cbObject) => { var match = App.CurrentMatch; var data = JsonMapper.ToObject(response)["data"]; int newVersion = int.Parse(data["version"].ToString()); if (App.MatchVersion + 1 < (ulong)newVersion) { App.MatchVersion = (ulong)newVersion; // Setup a couple stuff into our TicTacToe scene App.BoardState = (string)data["matchState"]["board"]; App.PlayerInfoX = match.playerXInfo; App.PlayerInfoO = match.playerOInfo; App.WhosTurn = match.yourToken == "X" ? App.PlayerInfoX : match.playerOInfo; App.OwnerId = match.ownerId; App.MatchId = match.matchId; //Checking if game is completed to assign winner and loser info BuildBoardFromState(App.BoardState); App.Winner = BoardUtility.CheckForWinner(); if (App.Winner != 0) { Transform[] toCheckDisplay = { DuringGameDisplay.transform, AfterGameDisplay.transform }; Transform statusOverlay = toCheckDisplay[1].Find("StatusOverlay"); TextMeshProUGUI status = statusOverlay.Find("StatusText").GetComponent <TextMeshProUGUI>(); if (App.Winner == 1) { status.text = Truncate(App.PlayerInfoX.PlayerName, MAX_CHARS) + " Wins!"; App.WinnerInfo = App.PlayerInfoX; App.LoserInfo = App.PlayerInfoO; } else { status.text = Truncate(App.PlayerInfoO.PlayerName, MAX_CHARS) + " Wins!"; App.WinnerInfo = App.PlayerInfoO; App.LoserInfo = App.PlayerInfoX; } } // Load the Tic Tac Toe scene if (this != null && this.gameObject != null) { App.GotoTicTacToeScene(gameObject); } } }); }
public void AcceptRematch(GameObject previousScene) { // Send Event back to opponent that its accepted var jsonData = new JsonData(); jsonData["isReady"] = true; //Event to send to opponent to disable PleaseWaitScreen Bc.EventService.SendEvent(OpponentInfo.ProfileId, "playAgain", jsonData.ToJson()); //Making sure player info is ready to be sent for OnCompleteGame() if (WinnerInfo == null || LoserInfo == null) { Winner = BoardUtility.CheckForWinner(); WinnerInfo = Winner == 1 ? PlayerInfoX : PlayerInfoO; LoserInfo = Winner == 1 ? PlayerInfoO : PlayerInfoX; } // Reset Match OnCompleteGame(); GotoMatchSelectScene(previousScene); _localMatchSelect.OnPickOpponent(OpponentInfo); }
private void updateHud(bool updateNames = true) { // Check we if are not seeing a done match App.Winner = BoardUtility.CheckForWinner(); // Read match history if (_history == null && App.Winner != 0) { _turnPlayed = true; App.Bc.AsyncMatchService .ReadMatchHistory(App.OwnerId, App.MatchId, OnReadMatchHistory); } enableDuringGameDisplay(App.Winner == 0); Transform[] toCheckDisplay = { DuringGameDisplay.transform, AfterGameDisplay.transform }; //Game is finished if (App.Winner != 0) { App.IsAskingToRematch = false; App.AskedToRematch = false; } if (DuringGameDisplay.activeInHierarchy) { TextMeshProUGUI status = toCheckDisplay[0].Find("StatusOverlay").Find("StatusText").GetComponent <TextMeshProUGUI>(); // update the during Game Display status.text = App.Winner != 0 ? App.Winner == -1 ? "Match Tied" : "Match Completed" : (App.WhosTurn == App.PlayerInfoX && App.CurrentMatch.yourToken == "X" || App.WhosTurn == App.PlayerInfoO && App.CurrentMatch.yourToken == "O") ? "Your Turn" : Truncate(App.WhosTurn.PlayerName, MAX_CHARS) + "'s Turn"; } else { Transform statusOverlay = toCheckDisplay[1].Find("StatusOverlay"); TextMeshProUGUI status = statusOverlay.Find("StatusText").GetComponent <TextMeshProUGUI>(); TextMeshProUGUI statusOutline = statusOverlay.Find("StatusTextOutline").GetComponent <TextMeshProUGUI>(); if (App.Winner < 0) { status.text = "Game Tied!"; } else if (App.Winner > 0) { if (App.Winner == 1) { status.text = Truncate(App.PlayerInfoX.PlayerName, MAX_CHARS) + " Wins!"; App.WinnerInfo = App.PlayerInfoX; App.LoserInfo = App.PlayerInfoO; } else { status.text = Truncate(App.PlayerInfoO.PlayerName, MAX_CHARS) + " Wins!"; App.WinnerInfo = App.PlayerInfoO; App.LoserInfo = App.PlayerInfoX; } if (!App.CurrentMatch.scoreSubmitted) { if (App.WinnerInfo.ProfileId == App.ProfileId) { App.CheckAchievements(); App.PostToLeaderboard(); } App.CurrentMatch.scoreSubmitted = true; var jsonData = new JsonData(); jsonData["scoreSubmitted"] = true; jsonData["opponentProfileID"] = App.ProfileId; jsonData["opponentName"] = App.Name; jsonData["matchID"] = App.MatchId; jsonData["ownerID"] = App.OwnerId; //Send event to opponent to prompt them to play again App.Bc.EventService.SendEvent(App.CurrentMatch.matchedProfile.ProfileId, "gameConcluded", jsonData.ToJson()); } } else { status.text = Truncate(App.WhosTurn.PlayerName, MAX_CHARS) + " Turn"; } statusOutline.text = status.text; } if (updateNames) { Transform playerVsOpp; TextMeshProUGUI playerXName, playerXNameOutline, playerOName, playerONameOutline; // update the names for (int i = 0; i < toCheckDisplay.Length; ++i) { playerVsOpp = toCheckDisplay[i].Find("PlayerVSOpponent"); playerXName = playerVsOpp.Find("PlayerName").GetComponent <TextMeshProUGUI>(); playerXNameOutline = playerVsOpp.Find("PlayerNameOutline").GetComponent <TextMeshProUGUI>(); playerXName.text = Truncate(App.PlayerInfoX.PlayerName, MAX_CHARS); playerXNameOutline.text = playerXName.text; playerOName = playerVsOpp.Find("OpponentName").GetComponent <TextMeshProUGUI>(); playerONameOutline = playerVsOpp.Find("OpponentNameOutline").GetComponent <TextMeshProUGUI>(); playerOName.text = Truncate(App.PlayerInfoO.PlayerName, MAX_CHARS); playerONameOutline.text = playerOName.text; } } }