Exemplo n.º 1
0
    private IEnumerator PlayerControl()
    {
        bool aITurn = false;
        int  aIMove = 0;

        if (Parameters.AIPlaying)
        {
            aITurn       = true;
            waitingForAI = true;
            yield return(new WaitForSeconds(aIWaitTime));

            aIMove = aI.GetMove(playerScore[currentPlayer]);
            // Sometimes the diceController says there are no scoring dice,
            // so have it wait some time before deciding to hand over the turn.
            if (aIMove == 3)
            {
                yield return(new WaitForSeconds(aIWaitTime * 3));

                aIMove = aI.GetMove(playerScore[currentPlayer]);
            }
        }

        if (userInterface.GetRollPressed() || (aITurn && aIMove == 1))
        {
            diceController.Roll();
            userInterface.ResetRollButton();
        }
        else if (userInterface.GetBankPressed() || (aITurn && aIMove == 2))
        {
            playerScore[currentPlayer] += diceController.GetHandScore();
            userInterface.scoreBoard.AddPlayerScore(currentPlayer, playerScore[currentPlayer]);

            // Winning can only be achieved when banking, so here is a good place to check if we won:
            if (playerScore[currentPlayer] >= goalScore)
            {
                PlayerWon(currentPlayer);
            }

            diceController.TurnReset();
            ShiftPlayer();
            userInterface.ResetBankButton();
        }
        else if (diceController.FailedThrow() && (Input.anyKeyDown || aIMove == 3))
        {
            ShiftPlayer();
        }
        waitingForAI = false;
    }