public void ShowGameOverUI(MatchOutcome.ParticipantResult result, bool showRematchButton) { leaveMatchButton.gameObject.SetActive(false); IsInPlayingMode = false; resultRootObject.SetActive(true); resultText.text = GetResultText(result); rematchButton.gameObject.SetActive(showRematchButton); var tempModel = currentModel; currentModel = null; selfInfos.Update(tempModel.Match.Self.Player.image, GetSpriteForTile(tempModel.LocalPlayerMark.ToTileState()), GetColorForTile(tempModel.LocalPlayerMark.ToTileState()), tempModel.Match.Self.DisplayName, false); opponentInfos.Update((tempModel.Opponent != null && tempModel.Opponent.Player != null) ? tempModel.Opponent.Player.image : defaulAvatar, GetSpriteForTile(tempModel.OpponentMark.ToTileState()), GetColorForTile(tempModel.OpponentMark.ToTileState()), tempModel.Opponent != null ? tempModel.Opponent.DisplayName : "Unmatched player", false, tempModel.Opponent != null && tempModel.Opponent.Player == null); }
public void HideGameSection() { ClearBoard(); IsInPlayingMode = false; currentModel = null; gameSection.SetActive(false); rematchButton.gameObject.SetActive(false); multiplayerSection.SetActive(true); }
private void InstantiateBoard(TicTacToeGameModel model) { /// This mean the board has been instantiated before /// and it's showing the same model. So we'll just update it. if (board != null && model.Match.MatchId.Equals(currentModel.Match.MatchId)) { for (int i = 0; i < model.TransferDatas.Board.Length; i++) { var innerArray = model.TransferDatas.Board[i]; for (int j = 0; j < innerArray.Length; j++) { UpdateTileUI(i, j, innerArray[j]); } } return; } /// Otherwise we need to clear the old board and create a new one. ClearBoard(); TileSize = CalculateTileSize(model.TransferDatas.Size); grid.cellSize = new Vector2(TileSize, TileSize); grid.spacing = new Vector2(TileSpacing, TileSpacing); grid.padding.top = (int)TileSpacing; grid.padding.bottom = (int)TileSpacing; grid.constraint = GridLayoutGroup.Constraint.FixedColumnCount; grid.constraintCount = model.TransferDatas.Size; /// Init array. board = new Button[model.TransferDatas.Size][]; for (int i = 0; i < board.Length; i++) { board[i] = new Button[model.TransferDatas.Size]; } /// Instantiate prefabs. for (int i = 0; i < board.Length; i++) { var innerArray = board[i]; for (int j = 0; j < innerArray.Length; j++) { int x = i, y = j; innerArray[j] = Instantiate(tilePrefab, grid.transform); UpdateTileUI(i, j, model.TransferDatas.Board[i][j]); innerArray[j].onClick.AddListener(() => { Move(x, y); demoUtils.PlayButtonSound(); }); } } }
public void CreateBoard(TicTacToeGameModel model) { if (model == null) { return; } currentModel = model; IsInPlayingMode = true; gameSection.SetActive(true); multiplayerSection.SetActive(false); progressTextObject.SetActive(false); rematchButton.gameObject.SetActive(false); leaveMatchButton.gameObject.SetActive(true); resultRootObject.SetActive(false); InstantiateBoard(model); }
private void InstantiateBoard(TicTacToeGameModel model) { }
public void CreateBoard(TicTacToeGameModel model) { }
private void CheckAndPlayMatch(TurnBasedMatch match, bool playerWantsToQuit, int boardSize) { if (playerWantsToQuit) { // This only happens on Game Center platform when the local player // removes the match in the matches UI while being the turn holder. // We'll end the local player's turn and pass the match to a next // participant. If there's no active participant left we'll end the match. if (match.HasVacantSlot) { GameServices.TurnBased.LeaveMatchInTurn(match, "", null); return; } var nextParticipant = match.Participants.FirstOrDefault( p => p.ParticipantId != match.SelfParticipantId && (p.Status == Participant.ParticipantStatus.Joined || p.Status == Participant.ParticipantStatus.Invited || p.Status == Participant.ParticipantStatus.Matching)); if (nextParticipant != default(Participant)) { GameServices.TurnBased.LeaveMatchInTurn( match, nextParticipant.ParticipantId, null ); } else { // No valid next participant, match ends here. // In this case we'll set the outcome for all players as Tied for demo purpose. // In a real game you may determine the outcome based on the game data and your game logic. MatchOutcome outcome = new MatchOutcome(); foreach (var id in match.Participants.Select(p => p.ParticipantId)) { var result = MatchOutcome.ParticipantResult.Tied; outcome.SetParticipantResult(id, result); } GameServices.TurnBased.Finish(match, match.Data, outcome, null); } return; } model = new TicTacToeGameModel(match, boardSize); if (match.Status == TurnBasedMatch.MatchStatus.Ended) { CanMove = false; view.StartProgressUI("Acknowledging finished match"); GameServices.TurnBased.AcknowledgeFinished(match, flag => { view.StopProgressUI("Acknowledging finished match: " + GetResultMessage(flag)); view.CreateBoard(model); view.ShowGameOverUI(model.LocalFinalResult, true); }); return; } var opponent = match.Participants.Where(p => p.ParticipantId != match.SelfParticipantId).FirstOrDefault(); if (opponent != default(Participant) && (opponent.Status == Participant.ParticipantStatus.Done || opponent.Status == Participant.ParticipantStatus.Left)) { view.ShowGameOverUI(MatchOutcome.ParticipantResult.Won, false); NativeUI.Alert("Game Over", "You won. Your opponent has left the match."); return; } CanMove = true; view.CreateBoard(model); }