示例#1
0
        private void Turns(Player player)
        {
            int    rollsCounter = 0;
            double roundPoints = 0.0;
            double points = 0.0;
            Random rnd = new Random();
            double roll = 0.0;
            int    dice1, dice2;

            do
            {
                points = 0.0;
                roll   = 0.0;
                ConsoleWriter.PlayerTurn(player.Name, player.Score);

                dice1 = rnd.Next(1, 7);
                dice2 = rnd.Next(1, 7);
                ConsoleWriter.DicesRolled(dice1, dice2);

                if (rollsCounter == 0 && (dice1 + dice2 == 7 || dice1 + dice2 == 11))
                {
                    ConsoleWriter.RoundWon(player.Name, 0.0);
                    break;
                }
                if (rollsCounter == 0 && (dice1 + dice2 == 2 || dice1 + dice2 == 12))
                {
                    points = MaxScore();
                    ConsoleWriter.RoundLost(player.Name, points);
                    break;
                }
                if (dice1 + dice2 == 5)
                {
                    ConsoleWriter.RoundWon(player.Name, roundPoints);
                    break;
                }
                else
                {
                    roll  = (dice1 + dice2);
                    roll /= (rollsCounter + 1);
                    ConsoleWriter.CurrentPoints(player.Name, roll, player.Score + roll);
                }
                points += roll;
                player.AddPoints(points);
                roundPoints += points;
                rollsCounter++;
            } while (rollsCounter < MAXROLLS);
        }