Ejemplo n.º 1
0
        private static IBowlingScore ComputeScore(Roll[] inputRolls)
        {
            var           rollsQueue  = new BowlingRolls(inputRolls);
            IBowlingScore totalScore  = new BowlingScore();
            int           frameNumber = 0;

            while (rollsQueue.Count > 0 && frameNumber < 10 && totalScore.IsValid)
            {
                IBowlingScore currentScore = new BowlingScore(rollsQueue.Dequeue());

                if (currentScore.Value == 10)
                {
                    IBowlingScore bonusValue = GetBonusValue(rollsQueue, 2);
                    currentScore = currentScore.Add(bonusValue);
                }
                else
                {
                    if (rollsQueue.Count > 0)
                    {
                        currentScore.Add(rollsQueue.Dequeue());

                        if (currentScore.Value == 10)
                        {
                            IBowlingScore bonusValue = GetBonusValue(rollsQueue, 1);
                            currentScore = currentScore.Add(bonusValue);
                        }
                    }
                }

                frameNumber++;
                totalScore = totalScore.Add(currentScore);
            }

            return(totalScore);
        }
Ejemplo n.º 2
0
        public static void Main(string[] strings)
        {
            string inputStr = strings[0];

            Roll[]        input      = ReadInput(inputStr);
            IBowlingScore totalScore = ComputeScore(input);

            WriteOutput(inputStr, totalScore);
        }
Ejemplo n.º 3
0
 public IBowlingScore Add(IBowlingScore currentScore) => new InvalidScore();
Ejemplo n.º 4
0
 public IBowlingScore Add(IBowlingScore bonusValue)
 {
     return(bonusValue.Add(Value));
 }
Ejemplo n.º 5
0
 private static void WriteOutput(string inputStr, IBowlingScore totalScore)
 {
     Console.WriteLine(inputStr);
     Console.Write(totalScore.StringValue);
 }