Example #1
0
        private static BowlScore CalculateSpare(BowlScore totalScore, Frames frames, int i)
        {
            if (frames[i].IsSpare() && i < frames.Count() - 1)
            {
                totalScore = frames[i + 1].AddSpareBonus(totalScore);
            }

            return(totalScore);
        }
Example #2
0
        private static BowlScore CalculateStrikeBonusIfNotPenultimateFrame(BowlScore totalScore, Frames frames, int i)
        {
            if (i < frames.Count() - 2 && frames[i + 1].IsStrike())
            {
                totalScore = frames[i + 2].AddSpareBonus(totalScore);
            }

            return(totalScore);
        }
Example #3
0
        private static BowlScore CalculateStrike(BowlScore totalScore, Frames frames, int i)
        {
            if (frames[i].IsStrike() && i < frames.Count() - 1)
            {
                totalScore = CalculateStrikeBonusIfNotPenultimateFrame(totalScore, frames, i);
                totalScore = totalScore.Add(frames[i + 1].StrikeBonus());
            }

            return(totalScore);
        }
Example #4
0
        public BowlScore GetIntermediateScore()
        {
            BowlScore totalScore = new BowlScore(0);

            foreach (BowlScore bowl in bowls)
            {
                totalScore = totalScore.Add(bowl);
            }

            return(totalScore);
        }
Example #5
0
        public int FinalScore()
        {
            BowlScore totalScore = new BowlScore(0);

            Frames frames = bowls.GetFrames();

            for (int i = 0; i < frames.Count(); i++)
            {
                totalScore = CalculateSpare(totalScore, frames, i);
                totalScore = CalculateStrike(totalScore, frames, i);

                totalScore = totalScore.Add(frames[i].GetIntermediateScore());
            }

            return(totalScore.ToInt());
        }
Example #6
0
 public Frame(BowlScore bowl)
 {
     bowls.Add(bowl);
 }
Example #7
0
 public BowlScore AddSpareBonus(BowlScore currentScore)
 {
     return(currentScore.Add(bowls[0]));
 }
Example #8
0
 public Frame(BowlScore firstBowl, BowlScore secondBowl, BowlScore thirdBowl)
 {
     bowls.Add(firstBowl);
     bowls.Add(secondBowl);
     bowls.Add(thirdBowl);
 }