示例#1
0
    public void StartGame(AbstractPlayer p1, AbstractPlayer p2)
    {
        //Deactivate the options to start a game
        uiCanvas.SetActive(false);
        winLossText.gameObject.SetActive(false);

        //Remove any previous board pieces
        for (int i = 0; i < squares.Count; ++i)
        {
            squares[i].DumpPieces();
        }

        for (int i = 0; i < pieces.Count; ++i)
        {
            Destroy(pieces[i].gameObject);
        }

        //Flush queue
        playerTurns = new Queue <AbstractPlayer>();
        winner      = null;

        Debug.Log("RESETING");
        //Reset important data
        p1.ResetPlayer(TTT.SquareState.X);
        p2.ResetPlayer(TTT.SquareState.O);

        //Enqueue both players to make moves
        playerTurns.Enqueue(p1);
        playerTurns.Enqueue(p2);

        gameBoard = new TTT.TTTBoard(3, 3);

        started = true;

        //Undo previous table-flips
        OpponentAnimationController oac = null;

        if (player1.TryGetComponent(out oac))
        {
            oac.UN_YEET();
        }

        oac = null;

        if (player2.TryGetComponent(out oac))
        {
            oac.UN_YEET();
        }
    }
示例#2
0
    void EndGame(AbstractPlayer theWinner, bool cheat)
    {
        winner = theWinner;

        playerTurns.Clear();
        currentPlayer = null;

        if (cheat)
        {
            //Check for a cheater
            winLossText.text = "YOU CHEATED!";
            OpponentAnimationController oac = null;

            //The fabled table flip animation
            if (player1.TryGetComponent(out oac))
            {
                oac.anim.SetTrigger("Flip");
            }

            oac = null;

            if (player2.TryGetComponent(out oac))
            {
                oac.anim.SetTrigger("Flip");
            }

            //UI is not immediately activated here, waits for animation event
        }
        else if (theWinner == null)
        {
            //Check for a tie
            winLossText.text = "NOBODY WINS!";

            ActivateUI();
        }
        else
        {
            //Check for a win
            winLossText.text = (theWinner.playingAs + " WINS!");

            ActivateUI();
        }

        started = false;
    }