Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public BowlScore GetIntermediateScore()
        {
            BowlScore totalScore = new BowlScore(0);

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

            return(totalScore);
        }
Exemplo n.º 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());
        }
Exemplo n.º 6
0
 public Frame(BowlScore bowl)
 {
     bowls.Add(bowl);
 }
Exemplo n.º 7
0
 public BowlScore AddSpareBonus(BowlScore currentScore)
 {
     return(currentScore.Add(bowls[0]));
 }
Exemplo n.º 8
0
 public Frame(BowlScore firstBowl, BowlScore secondBowl, BowlScore thirdBowl)
 {
     bowls.Add(firstBowl);
     bowls.Add(secondBowl);
     bowls.Add(thirdBowl);
 }