public void Roll(int pins) { frame.Load(pins); //special rule for last frame if (frame.Number == maxFrameCount && (frame.IsStrike() || frame.IsSpare())) { frame.IncreaseThrowCount(); } if (frame.IsStrike() || frame.ThrowCount() == frame.ThrowsPerFrame()) { frame = AddFrames(); } }
private int CalculateNormalFrame(int frameIndex, IFrame frame) { var totalFrameScore = frame.GetScore(); if (frame.IsStrike()) { totalFrameScore = CalculateStrikeScore(frameIndex, totalFrameScore); } else if (frame.IsSpare()) { totalFrameScore = CalculateSpareScore(frameIndex, totalFrameScore); } return(totalFrameScore); }
public IFrameScorer GetScorer(IFrame frameToScore) { IFrameScorer frameScorer; if (frameToScore.IsStrike()) { frameScorer = new StrikeFrameScorer(); } else if (frameToScore.IsSpare()) { frameScorer = new SpareFrameScorer(); } else { frameScorer = new NormalFrameScorer(); } return(frameScorer); }
public IFrameScorer GetScorer(IFrame frameToScore) { IFrameScorer frameScorer; if(frameToScore.IsStrike()) { frameScorer = new StrikeFrameScorer(); } else if(frameToScore.IsSpare()) { frameScorer = new SpareFrameScorer(); } else { frameScorer = new NormalFrameScorer(); } return frameScorer; }
public int?ScoreFrame(IFrame frameToScore) { if (!frameToScore.IsStrike()) { return(null); } var frameScore = frameToScore.TotalPins; var subsequentFrame1 = frameToScore.NextFrame; if (subsequentFrame1 == null || !subsequentFrame1.PinsWithBall1.HasValue) { return(frameScore); } var frame1Ball1Pins = subsequentFrame1.PinsWithBall1; var frame1Ball2Pins = subsequentFrame1.PinsWithBall2; frameScore += frame1Ball1Pins.Value; var subsequentFrame2 = subsequentFrame1.NextFrame; if (subsequentFrame2 == null) { return(frameScore); } var frame2Ball1Pins = subsequentFrame2.PinsWithBall1; if (subsequentFrame1.IsStrike() && frame2Ball1Pins.HasValue) { frameScore += frame2Ball1Pins.Value; } else if (frame1Ball2Pins.HasValue) { frameScore += frame1Ball2Pins.Value; } return(frameScore); }
public int? ScoreFrame(IFrame frameToScore) { if (!frameToScore.IsStrike()) { return null; } var frameScore = frameToScore.TotalPins; var subsequentFrame1 = frameToScore.NextFrame; if (subsequentFrame1 == null || !subsequentFrame1.PinsWithBall1.HasValue) { return frameScore; } var frame1Ball1Pins = subsequentFrame1.PinsWithBall1; var frame1Ball2Pins = subsequentFrame1.PinsWithBall2; frameScore += frame1Ball1Pins.Value; var subsequentFrame2 = subsequentFrame1.NextFrame; if (subsequentFrame2 == null) { return frameScore; } var frame2Ball1Pins = subsequentFrame2.PinsWithBall1; if (subsequentFrame1.IsStrike() && frame2Ball1Pins.HasValue) { frameScore += frame2Ball1Pins.Value; } else if (frame1Ball2Pins.HasValue) { frameScore += frame1Ball2Pins.Value; } return frameScore; }