Example #1
0
        public IEnumerable <int> GetProgressiveScores()
        {
            List <int> scores = new List <int>();

            foreach (Frame frame in Frames)
            {
                Tuple <int, int, int> currentScores = frame.GetUnmodifiedScores();
                if (frame is StandardFrame)
                {
                    StandardFrame standardFrame = frame as StandardFrame;
                    if (standardFrame.Strike)
                    {
                        if (standardFrame.NextFrame != null && standardFrame.NextFrame is StandardFrame)
                        {
                            // 8th frame or earlier
                            StandardFrame nextFrame = standardFrame.NextFrame as StandardFrame;
                            if (nextFrame.Strike)
                            {
                                // need to roll to next frame for second ball score
                                if (nextFrame.NextFrame != null)
                                {
                                    scores.Add(currentScores.Item1 + nextFrame.GetUnmodifiedScores().Item1 + nextFrame.NextFrame.GetUnmodifiedScores().Item1);
                                }
                            }
                            else
                            {
                                scores.Add(currentScores.Item1 + currentScores.Item2 + nextFrame.GetUnmodifiedScores().Item1);
                            }
                        }
                        else if (standardFrame.NextFrame != null && standardFrame.NextFrame is TenthFrame)
                        {
                            // we're on the ninth
                            scores.Add(currentScores.Item1 + standardFrame.NextFrame.GetUnmodifiedScores().Item1 + standardFrame.NextFrame.GetUnmodifiedScores().Item2);
                        }
                    }
                    else if (standardFrame.Spared)
                    {
                        if (standardFrame.NextFrame != null)
                        {
                            scores.Add(currentScores.Item1 + currentScores.Item2 + standardFrame.NextFrame.GetUnmodifiedScores().Item1);
                        }
                    }
                    else
                    {
                        scores.Add(currentScores.Item1 + currentScores.Item2); // simple total
                    }
                }
                else if (frame is TenthFrame)
                {
                    scores.Add(currentScores.Item1 + currentScores.Item2 + currentScores.Item3);
                }
            }

            return(scores);
        }
Example #2
0
        public void AddFrame(string frameAsString)
        {
            Frame frame;

            if (Frames.Count() < 9)
            {
                frame = new StandardFrame(_currentFrame, frameAsString);
                if (_currentFrame != null)
                {
                    _currentFrame.LinkNext(frame);
                }
                _currentFrame = frame;
            }
            else
            {
                frame = new TenthFrame(_currentFrame, frameAsString);
                _currentFrame.LinkNext(frame);
                _currentFrame = frame;
            }
        }