private void HandleStartGame(string payload) { MatchPayload match = JsonUtility.FromJson <MatchPayload>(payload); loadingController.Hide(); string currentTurnDisplay = ""; string currentTurnPieceDisplay = ""; if (string.IsNullOrEmpty(match.winner) && match.draw == false) { currentTurnDisplay = (match.currentTurnId == LoggedInUser.Instance.GetUserUID()) ? "Your Turn" : "Opponent Turn"; currentTurnPieceDisplay = (match.currentTurnId == match.xOwner) ? "X" : "O"; } else if (!string.IsNullOrEmpty(match.winner)) { currentTurnDisplay = (match.winner == LoggedInUser.Instance.GetUserUID()) ? "You Won!" : "Opponent Won!"; } else { currentTurnDisplay = "It's a draw!"; } turnController.SetState(new TurnState() { CurrentTurn = currentTurnDisplay, CurrentTurnPiece = currentTurnPieceDisplay }); gridController.SetState(new GridState() { bottomRow = match.gameState.bottomRow, middleRow = match.gameState.middleRow, topRow = match.gameState.topRow, currentTurnId = match.currentTurnId, currentTurnPiece = GetCurrentTurnPiece(match) }); if (!string.IsNullOrEmpty(match.winner) || match.draw == true) { gridController.DisablePlacingPiece(); } else if (isYourTurn(match)) { gridController.EnablePlacingPiece(); } else { gridController.DisablePlacingPiece(); } }
private string GetCurrentTurnPiece(MatchPayload payload) { string piece = ""; if (payload.currentTurnId == payload.oOwner) { piece = "O"; } else { piece = "X"; } return(piece); }
private bool isYourTurn(MatchPayload payload) { return(payload.currentTurnId == LoggedInUser.Instance.GetUserUID()); }