Ejemplo n.º 1
0
        public void StrikeFrameCreation()
        {
            var roll1 = new Roll(10);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1 });

            Assert.IsType <StrikeFrame>(frame);
        }
Ejemplo n.º 2
0
        private static int NextTwoBalls(IBowlingFrame frame, IList<IBowlingFrame> frames)
        {
            var nextFrame = NextFrame(frame, frames);

            var secondFrame = NextFrame(nextFrame, frames);

            return nextFrame.First + (nextFrame.IsStrike ? secondFrame.First : nextFrame.Second);
        }
Ejemplo n.º 3
0
        public void Roll(int numberOfPinsKnockedDown)
        {
            if (currentFrame == null)
            {
                currentFrame = _frameFactory.CreateFrame();
            }

            currentFrame.Roll(numberOfPinsKnockedDown);
        }
Ejemplo n.º 4
0
        public void OpenFrameCreation()
        {
            var roll1 = new Roll(4);
            var roll2 = new Roll(2);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1, roll2 });

            Assert.IsType <OpenFrame>(frame);
        }
Ejemplo n.º 5
0
        public void LastFrameCreationWith_TwoRolls()
        {
            var roll1 = new Roll(1);
            var roll2 = new Roll(1);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1, roll2 }, 10);

            Assert.IsType <LastFrame>(frame);
        }
Ejemplo n.º 6
0
        public void SpareFrameCreation()
        {
            var roll1 = new Roll(5);
            var roll2 = new Roll(5);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1, roll2 });

            Assert.IsType <SpareFrame>(frame);
        }
Ejemplo n.º 7
0
        private static IBowlingFrame NextFrame(IBowlingFrame frame, IList<IBowlingFrame> frames)
        {
            var index = frames.IndexOf(frame);

            return index == 10
                       ? frame
                       : index == -1 || index == frames.Count - 1
                             ? _empty
                             : frames[index + 1];
        }
        public IFrameScore GetCurrentScore(IBowlingFrame currentFrame, int howManyRolls)
        {
            if (_framesQueue.Sum(frame => frame.ConsumesRolls) < howManyRolls)
            {
                return(new OpenScore());
            }

            return(new FrameScore(currentFrame.OpenValue + _framesQueue
                                  .SelectMany(frame => frame.GetInternalFrames())
                                  .Take(howManyRolls)
                                  .Sum(frame => frame.OpenValue)));
        }
 public bool TryDequeue(out IBowlingFrame frame)
 {
     return(_framesQueue.TryDequeue(out frame));
 }
Ejemplo n.º 10
0
 private bool ShouldWaitForASecondBall(IBowlingFrame frame)
 {
     return !frame.IsStrike || this._frames.Count == 11;
 }
Ejemplo n.º 11
0
 private static int NextBall(IBowlingFrame frame, IList<IBowlingFrame> frames)
 {
     return NextFrame(frame, frames).First;
 }