예제 #1
0
        public TurnResult playTurn(int startDice, int playerScore)
        {
            int currentDiceCount = startDice;
            int currentScore     = playerScore;

            Console.WriteLine("Turn Score: {0}", currentScore);
            if (currentDiceCount == 0)
            {
                currentDiceCount = 6;
            }
            RollResult rollResult = playRoll(currentDiceCount, currentScore);
            TurnResult turnResult;

            if (rollResult.endTurn && rollResult.farkle)
            {
                turnResult = new TurnResult(currentScore, true);
                return(turnResult);
            }
            else if (rollResult.endTurn && !rollResult.farkle)
            {
                currentScore += rollResult.score;
                turnResult    = new TurnResult(currentScore, false);
                return(turnResult);
            }
            currentScore    += rollResult.score;
            currentDiceCount = rollResult.remainingDice;
            turnResult       = playTurn(currentDiceCount, currentScore);

            return(turnResult);
        }
예제 #2
0
        public RollResult playRoll(int startDice, int turnScore)
        {
            RollResult turnResult;
            Farkle     farkle           = new Farkle();
            int        currentDiceCount = startDice;
            int        currentScore     = turnScore;

            int[]             diceRolls   = farkle.roll(currentDiceCount);
            List <RollOption> rollResults = farkle.returnOptions(diceRolls);

            foreach (int roll in diceRolls)
            {
                Console.Write("{0} | ", roll);
            }
            Console.WriteLine(" ");
            Console.WriteLine("_________________");
            for (int i = 0; i < rollResults.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, rollResults[i]);
            }
            if (rollResults[0] == RollOption.Nothing)
            {
                Console.WriteLine("FARKLE!");
                turnResult = new RollResult(0, true, true, currentDiceCount);
                return(turnResult);
            }
            Console.WriteLine("Enter numbers of what options you want to take. If you want to take the roll, end your input with a /");
            Console.WriteLine("_______________");
            string            input = Console.ReadLine();
            List <RollOption> rollResultsSelected = farkle.determineRollSelections(input, rollResults);

            currentScore     = farkle.calculateScore(rollResultsSelected, turnScore);
            currentDiceCount = farkle.calculateRemainingDice(rollResultsSelected, currentDiceCount);
            bool endTurnTakeScore = (rollResultsSelected[rollResultsSelected.Count - 1] == RollOption.TakeScore ? true : false);

            turnResult = new RollResult(currentScore, endTurnTakeScore, false, currentDiceCount);
            Console.WriteLine("\n\n\n");
            return(turnResult);
        }