public int CalculateScoreForSingleFrame(int frameNumber, IList <BowlingFrame> playedFrames)
        {
            #region Guard Clause

            if (playedFrames.Count > MAX_NO_OF_FRAMES)
            {
                throw new ArgumentException($"Invalid number of frames - max {MAX_NO_OF_FRAMES} is allowed.");
            }

            if (frameNumber > playedFrames.Count || frameNumber > MAX_NO_OF_FRAMES)
            {
                throw new ArgumentException("The frame-number is out of bounds.");
            }

            #endregion Guard Clause

            BowlingFrame frameToCalculateScoreFor = playedFrames[frameNumber - 1];
            int          framePoints = frameToCalculateScoreFor.Points.Sum();

            if (frameToCalculateScoreFor.Points[0] == 10 /* strike */)
            {
                framePoints += GetBonusPointsFromNextFrames(2, frameNumber + 1, playedFrames);
            }
            else if (framePoints == 10 /* spare */)
            {
                framePoints += GetBonusPointsFromNextFrames(1, frameNumber + 1, playedFrames);
            }

            return(framePoints);
        }
        public static BowlingFrame CreateAndValidateFrameFromPoints(int[] points)
        {
            BowlingFrame newBowlingFrame = new BowlingFrame(points);

            ValidateFrame(points);

            return(newBowlingFrame);
        }
예제 #3
0
        internal IList <BowlingFrame> ConvertTestDataToBowlingFrames(TestGameDataDto playedFramesPocos)
        {
            IList <BowlingFrame> playedFrames = new List <BowlingFrame>();

            for (int i = 0; i < playedFramesPocos.points.Length; i++)
            {
                BowlingFrame playedFrame = BowlingFrame.CreateAndValidateFrameFromPoints(playedFramesPocos.points[i]);
                playedFrames.Add(playedFrame);
            }

            return(playedFrames);
        }
 public void AddPlayedBowlingFrame(BowlingFrame bowlingFrame)
 {
     _playedFrames.Add(bowlingFrame);
 }