Beispiel #1
0
        ScoreFrameState UpdateScoreFrame(int pinScore)
        {
            var frameResult = currentScoreFrame.AddPinScore(pinScore);

            if (frameResult == ScoreFrameState.Spare)
            {
                frameScorePostProcessors.Add(currentScoreFrame.CreateFrameScorePostProcessor());
            }
            if (currentScoreFrame.IsCompleted)
            {
                currentScoreFrame = null;
            }

            return(frameResult);
        }
Beispiel #2
0
        ScoreFrameState AddScoreFrame(int pinScore)
        {
            var  result   = ScoreFrameState.Pending;
            bool isStrike = pinScore == ScoreRules.MaxPinScore;

            if (scoreFrames.Count < ScoreRules.LastScoreFrame)
            {
                var previousScoreFrame = scoreFrames.Count > 0 ? scoreFrames[scoreFrames.Count - 1] : null;
                if (isStrike)
                {
                    var strikeScoreFrame = new StrikeScoreFrame(previousScoreFrame);
                    scoreFrames.Add(strikeScoreFrame);
                    frameScorePostProcessors.Add(strikeScoreFrame.CreateFrameScorePostProcessor());
                    result = ScoreFrameState.Strike;
                }
                else
                {
                    currentScoreFrame = new SpareScoreFrame(previousScoreFrame, pinScore);
                    scoreFrames.Add(currentScoreFrame);
                }
            }
            else if (scoreFrames.Count == ScoreRules.LastScoreFrame)
            {
                currentScoreFrame = new LastScoreFrame(scoreFrames[scoreFrames.Count - 1], pinScore);
                scoreFrames.Add(currentScoreFrame);
                if (isStrike)
                {
                    frameScorePostProcessors.Add(currentScoreFrame.CreateFrameScorePostProcessor());
                    result = ScoreFrameState.Strike;
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(result);
        }