public void GetRollReturnsSameObjectThatWasPlacedAtGivenIndex()
 {
     Roll r1 = new Roll('5');
     Frame f = new Frame();
     f.AddRoll(r1);
     Assert.AreSame(r1, f.GetRoll(0));
 }
Beispiel #2
0
        public int Score()
        {
            int frameIndex = 0;
            var frames = new List<Frame>();
            for (int frame = 0; frame < 10; frame++)
            {
                var currentFrame = new Frame(frameIndex, rolls);
                frames.Add(currentFrame);

                if (currentFrame.IsStrike())
                {
                    frameIndex++;
                }
                else if (currentFrame.IsSpare())
                {
                    frameIndex += 2;
                }
                else
                {
                    frameIndex += 2;
                }
            }

            int score = 0;
            foreach (var currentFrame in frames)
            {
                score += currentFrame.GetScore();
            }
            return score;
        }
 public void GetRawScoreAccountsForPreviousRollWhenCalculatingSpare()
 {
     Frame f = new Frame();
     f.AddRoll(new Roll('1'));
     f.AddRoll(new Roll('/'));
     Assert.AreEqual(10, f.GetRawScore());
 }
 public void GetRollScoreCanBeUsedToGetASingleRollsScore()
 {
     Frame f = new Frame();
     f.AddRoll(new Roll('1'));
     f.AddRoll(new Roll('8'));
     Assert.AreEqual(1, f.GetRollScore(0));
     Assert.AreEqual(8, f.GetRollScore(1));
 }
Beispiel #5
0
        private Frame GetNextFrameWithEmptyRoll(Frame currentFrame)
        {
            if ((currentFrame.GetRawScore() >= _maxScorePerRoll || currentFrame.Size >= _rollsPerFrame)
                    && currentFrame != _frames.Last())
            {
                currentFrame = _frames.SkipWhile(x => x != currentFrame).Skip(1).First();
            }

            return currentFrame;
        }
        public void GetRawScoreAddsRollsAsRawValues()
        {
            Frame f = new Frame();
            f.AddRoll(new Roll('1'));
            Assert.AreEqual(1, f.GetRawScore());
            f.AddRoll(new Roll('X'));

            // 12 because X is technically 11
            Assert.AreEqual(12, f.GetRawScore());
        }
        public void AddRollsIncreasesFrameSizeByNumberOfArguments()
        {
            Roll r1 = new Roll('-');
            Roll r2 = new Roll('1');
            Roll r3 = new Roll('2');
            Frame f = new Frame(3);

            f.AddRolls(r1, r2, r3);
            Assert.AreEqual(3, f.Size);
        }
        private static int GetBonusScore(Frame currentFrame, Frame previousFrame)
        {
            if (previousFrame.FrameType == FrameType.Spare)
            {
                return currentFrame.Throw1;
            }
            if (previousFrame.FrameType == FrameType.Strike)
            {
                return currentFrame.Score;
            }

            return 0;
        }
Beispiel #9
0
        public void Roll(char ball)
        {
            if(_lastFrame == null || !_lastFrame.IsOpen)
            {
                Frame f = new Frame(_lastFrame == null ? 1 : _lastFrame.FrameNumber + 1);
                _scoringFrames.Add(f);
                _allframes.Add(f);
                _lastFrame = f;
            }

            _scoringFrames.ForEach(f => f.Roll(ball));
            _scoringFrames.RemoveAll(f => !f.StillScoring);

            _allRolls.Add(ball);
        }
Beispiel #10
0
        public int CalculateLookAhead(Frame currentFrame, int frameIndex, int numRolls)
        {
            int rollScore = 0;
            for (int i = 0; i < numRolls; i++)
            {
                int index = i;
                if (index >= currentFrame.Size)
                {
                    index = 0;
                    currentFrame = _frames[++frameIndex];
                }

                rollScore += RawScoreToRealScore(currentFrame.GetRollScore(index));
            }

            return rollScore;
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            FrameCollection frames = new FrameCollection();

            int count = 0;

            do
            {
                count++;
                Console.WriteLine("In frame {0}, Please enter the pins knowked down...", count);
                Console.Write("...on the first throw:");
                string first = Console.ReadLine();
                string second = "0";
                if (first != "10" && first !="X" && first != "x")
                {
                    Console.Write("...on the second throw:");
                    second = Console.ReadLine();
                }
                frames.Add(new Frame(first,second));
            } while (count < 10);

            if (frames[9].IsStrike || frames[9].IsSpare)
            {
                Console.WriteLine("Bonus frame #1!");
                Console.Write("Enter pins knocked down on 1st bonus frame:");
                string bonusScore1 = Console.ReadLine();
                Frame bonus1 = new Frame(bonusScore1,true);
                frames.Add(bonus1);
                if (bonus1.IsStrike && frames[9].IsStrike)
                {
                    Console.WriteLine("Bonus frame #2!");
                    Console.Write("Enter pins knocked down on 2nd bonus frame:");
                    string bonusScore2 = Console.ReadLine();
                    frames.Add(new Frame(bonusScore2,true));
                }

            }

            Console.WriteLine("The final score was: {0}", frames.Score());
            Console.ReadLine();
        }
Beispiel #12
0
 private void InitializeFrames()
 {
     Enumerable.Range(0, FrameCount - 1).Select(x => _frames[x] = new Frame(_rollsPerFrame)).ToArray();
     _frames[FrameCount - 1] = new Frame(_rollsPerFrame + 1);
 }
 public void GetRollScoreThrowsExceptionWhenIndexIsOutOfRange()
 {
     Frame f = new Frame();
     f.AddRoll(new Roll('7'));
     Assert.AreEqual(0, f.GetRollScore(10));
 }
 public void AddRollIncreasesFrameSize()
 {
     Frame f = new Frame();
     f.AddRoll(new Roll('-'));
     Assert.AreEqual(1, f.Size);
 }
 public void ConstructorCreatesEmptyFrame()
 {
     Frame f = new Frame();
     Assert.AreEqual(0, f.Size);
 }
 public void AddRollsThrowsExceptionWhenTooManyRollsAreAdded()
 {
     Frame f = new Frame(2);
     f.AddRolls(new Roll('-'), new Roll('1'), new Roll('2'));
 }
Beispiel #17
0
 public static BonusFrame AddSpare(Frame frame)
 {
     return new BonusFrame {countOfBonusRolls = 1, Frame = frame};
 }
Beispiel #18
0
 public static BonusFrame AddStrike(Frame frame)
 {
     return new BonusFrame {countOfBonusRolls = 2, Frame = frame};
 }
 public void OverfillFrameThrowsFrameFullExceptionWhenAddingTooManyRolls()
 {
     Frame f = new Frame(2);
     f.AddRoll(new Roll('-'));
     f.AddRoll(new Roll('-'));
     f.AddRoll(new Roll('-'));
 }