コード例 #1
0
ファイル: GameController.cs プロジェクト: Zcholm/10k3D
    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     = "";
         }
     }
 }