Exemplo n.º 1
0
        private void OnGameOver(WinResult result)
        {
            Debug.Log("Drawning line");
            Debug.Log(result.lineType + ": " + result.lineIndex);

            switch (result.lineType)
            {
            case LineType.Horizontal:
                line.rectTransform.position      = gridManager.GetGridButtonAtPosition(new Vector2Int(result.lineIndex, 1)).gameObject.GetComponent <RectTransform>().position;
                line.rectTransform.localScale    = new Vector3(28, 1, 1);
                line.rectTransform.localRotation = Quaternion.Euler(0, 0, 0);
                break;

            case LineType.Vertical:
                line.rectTransform.position      = gridManager.GetGridButtonAtPosition(new Vector2Int(1, result.lineIndex)).gameObject.GetComponent <RectTransform>().position;
                line.rectTransform.localScale    = new Vector3(1, 28, 1);
                line.rectTransform.localRotation = Quaternion.Euler(0, 0, 0);
                break;

            case LineType.Diagonal:
                line.rectTransform.position      = gridManager.GetGridButtonAtPosition(new Vector2Int(1, 1)).gameObject.GetComponent <RectTransform>().position;
                line.rectTransform.localScale    = new Vector3(40, 1, 1);
                line.rectTransform.localRotation = Quaternion.Euler(0, 0, -45);
                break;

            case LineType.AntiDiagonal:
                line.rectTransform.position      = gridManager.GetGridButtonAtPosition(new Vector2Int(1, 1)).gameObject.GetComponent <RectTransform>().position;
                line.rectTransform.localScale    = new Vector3(40, 1, 1);
                line.rectTransform.localRotation = Quaternion.Euler(0, 0, 45);
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        private void OnGridCellFilled(int[,] grid, int gridSize)
        {
            WinResult result = TicTacToeUtility.CheckWinner(grid, gridSize);

            switch (result.score)
            {
            case 1:
                Debug.Log("X - win");
                p1Score++;
                isGameOver = true;
                OnGameOver?.Invoke(result);
                break;

            case -1:
                Debug.Log("O - win");
                p2Score++;
                isGameOver = true;
                OnGameOver?.Invoke(result);
                break;

            case 0:
                if (!TicTacToeUtility.CheckForEmptyCells(grid))
                {
                    Debug.Log("Draw");
                    drawScore++;
                    isGameOver = true;
                    OnGameOver?.Invoke(result);
                }
                break;

            default:
                Debug.Log("Incorrect result");
                break;
            }
            if (!isGameOver)
            {
                SwitchSymbolTurn();
                OnSymbolTurnStart?.Invoke(currentSymbolTurn);
            }
            else
            {
                if (result.score == 0)
                {
                    SwitchSymbolTurn();
                }
                DOVirtual.DelayedCall(2f, () => Rematch());
            }
        }
Exemplo n.º 3
0
 private void OnGameOver(WinResult result)
 {
     switch (result.score)
     {
         case 1:
             txt.text = "X - Win";
             break;
         case -1:
             txt.text = "O - Win";
             break;
         case 0:
             txt.text = "Draw";
             break;
         default:
             Debug.LogError("Incorrect result");
             break;
     }
     ShowResultWindow();
 }
Exemplo n.º 4
0
        private void OnGameOver(WinResult result)
        {
            switch (result.score)
            {
            case 1:
                p1ScoreTxt.text = (Convert.ToInt16(p1ScoreTxt.text) + 1).ToString();
                break;

            case -1:
                p2ScoreTxt.text = (Convert.ToInt16(p2ScoreTxt.text) + 1).ToString();
                break;

            case 0:
                drawScoreTxt.text = (Convert.ToInt16(drawScoreTxt.text) + 1).ToString();
                break;

            default:
                break;
            }
        }