Пример #1
0
        // Game Over
        private void GameOver(int winner)
        {
            // If is already over
            if (isGameOver)
            {
                return;
            }

            _winner = winner;
            if (winner != -1)
            {
                // Draw lines
                _lineGen = Instantiate(line, _lineSpawnPos, Quaternion.identity) as GameObject;
                _lineGen.transform.SetParent(cardBorder.transform, false);
                _lineRend = _lineGen.GetComponent <LineRenderer>();

                // if AI Won
                if (winner == 2)
                {
                    _lineRend.material = oMat;
                    _lineDotPr         = blueLineDotPr;
                }
                else
                {
                    // If player won
                    _lineRend.material = xMat;
                    _lineDotPr         = redLineDotPr;

                    // Start the confetti
                    _confettiWindow = Instantiate(confettiWindow, new Vector3(0, 0, 0), Quaternion.identity);
                    _confettiWindow.transform.SetParent(transform, false);

                    _windowConfettiScript            = _confettiWindow.GetComponent <WindowConfetti>();
                    _windowConfettiScript.pfConfetti = xConfetti;

                    endImage.sprite = winnerSprite;
                }

                // 1st line dot
                _lineDot = Instantiate(_lineDotPr, _lineDot1Pos, Quaternion.identity);
                _lineDot.transform.SetParent(cardBorder.transform, false);

                // 2nd line dot
                _lineDot = Instantiate(_lineDotPr, _lineDot2Pos, Quaternion.identity);
                _lineDot.transform.SetParent(cardBorder.transform, false);

                // 3rd line dot
                _lineDot = Instantiate(_lineDotPr, _lineDot3Pos, Quaternion.identity);
                _lineDot.transform.SetParent(cardBorder.transform, false);

                _animateLine = true;
                _hasLost     = true;
            }

            isGameOver = true;
        }
Пример #2
0
        private void GameOver(int winner, bool hasMatched)
        {
            // Since there cant be 2 or more game overs return;
            if (isGameOver)
            {
                return;
            }

            // If there is a winner
            if (winner != 3)
            {
                // If player has matched draw lines
                if (hasMatched)
                {
                    Debug.Log("Initiating line at = " + _lineSpawnPos);
                    _lineGen = Instantiate(line, _lineSpawnPos, Quaternion.identity) as GameObject;
                    _lineGen.transform.SetParent(cardBorder.transform, false);
                    _lineRend = _lineGen.GetComponent <LineRenderer>();

                    // If Player 1 Wins
                    if (winner == 1)
                    {
                        _lineRend.material = xMat;
                        _lineDotPr         = redLineDotPr;
                    }
                    else
                    {
                        // If Player 2 Wins
                        _lineRend.material = oMat;
                        _lineDotPr         = blueLineDotPr;
                    }

                    // 1st line dot
                    _lineDot = Instantiate(_lineDotPr, _lineDot1Pos, Quaternion.identity);
                    _lineDot.transform.SetParent(cardBorder.transform, false);

                    // 2nd line dot
                    _lineDot = Instantiate(_lineDotPr, _lineDot2Pos, Quaternion.identity);
                    _lineDot.transform.SetParent(cardBorder.transform, false);

                    // 3rd line dot
                    _lineDot = Instantiate(_lineDotPr, _lineDot3Pos, Quaternion.identity);
                    _lineDot.transform.SetParent(cardBorder.transform, false);

                    // 4th line dot
                    if (grid != 3)
                    {
                        // 3rd line dot
                        _lineDot = Instantiate(_lineDotPr, _lineDot4Pos, Quaternion.identity);
                        _lineDot.transform.SetParent(cardBorder.transform, false);
                    }

                    if (grid == 5)
                    {
                        // 3rd line dot
                        _lineDot = Instantiate(_lineDotPr, _lineDot5Pos, Quaternion.identity);
                        _lineDot.transform.SetParent(cardBorder.transform, false);
                    }
                }


                // Only show confetti to the winner
                if (winner == _playerIndex)
                {
                    _windowConfetti =
                        Instantiate(confettiWindow, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                    _windowConfetti.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, Screen.height);
                    _windowConfetti.transform.SetParent(transform, false);
                    WindowConfetti windowScript = _windowConfetti.GetComponent <WindowConfetti>();

                    // If Player 1 Wins
                    if (winner == 1)
                    {
                        windowScript.pfConfetti = xConfetti;
                    }
                    else
                    {
                        // If Player 2 Wins
                        windowScript.pfConfetti = oConfetti;
                    }

                    _hasWon = true;
                }
                else
                {
                    _hasWon = false;
                }
            }
            else
            {
                _hasDrawn = true;
            }

            if (hasMatched)
            {
                _animateLine = true;
            }

            _showedEndImg = false;
            isGameOver    = true;
        }
        private void GameOver(bool hasTied)
        {
            // If is already over
            if (isGameOver)
            {
                return;
            }

            if (!hasTied)
            {
                _hasWon = true;

                // Draw lines
                _lineGen = Instantiate(line, _lineSpawnPos, Quaternion.identity) as GameObject;
                _lineGen.transform.SetParent(cardBorder.transform, false);
                _lineRend = _lineGen.GetComponent <LineRenderer>();

                // Start the confetti
                _windowConfetti = Instantiate(confettiWindowPr, new Vector3(0, 0, 0), Quaternion.identity);
                _windowConfetti.transform.SetParent(transform, false);
                _windowConfettiScript = _windowConfetti.GetComponent <WindowConfetti>();

                if (!p1)
                {
                    endTxt.text = "Winner";

                    _lineRend.material = xMat;
                    _windowConfettiScript.pfConfetti = xConfetti;
                    _lineDotPr = redLineDotPr;
                }
                else
                {
                    endTxt.text = "Winner";

                    _lineRend.material = oMat;
                    _windowConfettiScript.pfConfetti = oConfetti;
                    _lineDotPr = blueLineDotPr;
                }

                // 1st line dot
                _lineDot = Instantiate(_lineDotPr, _lineDot1Pos, Quaternion.identity);
                _lineDot.transform.SetParent(cardBorder.transform, false);

                // 2nd line dot
                _lineDot = Instantiate(_lineDotPr, _lineDot2Pos, Quaternion.identity);
                _lineDot.transform.SetParent(cardBorder.transform, false);

                // 3rd line dot
                _lineDot = Instantiate(_lineDotPr, _lineDot3Pos, Quaternion.identity);
                _lineDot.transform.SetParent(cardBorder.transform, false);

                // 4th line dot
                if (grid != 3)
                {
                    // 3rd line dot
                    _lineDot = Instantiate(_lineDotPr, _lineDot4Pos, Quaternion.identity);
                    _lineDot.transform.SetParent(cardBorder.transform, false);
                }

                if (grid == 5)
                {
                    // 3rd line dot
                    _lineDot = Instantiate(_lineDotPr, _lineDot5Pos, Quaternion.identity);
                    _lineDot.transform.SetParent(cardBorder.transform, false);
                }
            }
            else
            {
                _hasDrawn   = true;
                endTxt.text = "It's a Draw!";
            }

            // Disable back button
            isGameOver   = true;
            _animateLine = true;
        }