示例#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;
    }
示例#2
0
文件: AI.cs 项目: Zcholm/10k3D
    public int GetMove(int playerScore)
    {
        diceController.SelectSelectable();

        // Returns 1 for roll, 2 for bank, 3 for player handover.
        // The AI rolls the dice, selects all score giving dice, and banks
        // whenever it reaches a score above a set threshold (1000 for the first throw in
        // accordance with the rules).

        if (diceController.CanBank(playerScore) && diceController.GetHandScore() >= bankThreshold)
        {
            return(2);
        }
        if (diceController.FailedThrow())
        {
            return(3);
        }
        return(1);
    }
示例#3
0
文件: UI.cs 项目: Zcholm/10k3D
 private void Update()
 {
     if (!diceController.FailedThrow())
     {
         selectedScoreText.text = "Score selected dice: " + diceController.GetSelectedScore();
         handScoreText.text     = "Score in hand: " + (diceController.GetHandScore());
     }
     else
     {
         if (Parameters.AIPlaying)
         {
             selectedScoreText.text = "";
             handScoreText.text     = "";
         }
         else
         {
             selectedScoreText.text = "No points thrown, press anywhere to switch player";
             handScoreText.text     = "";
         }
     }
 }