static int scoreFrames(Frame[] frames) { int score = 0; for (int i = 0; i < 10; i++) { Frame currentFrame = frames[i]; int currentScore = 0; for (int j = 0; j < currentFrame.ballThrows.Count(); j++) { BallThrow currentThrow = currentFrame.ballThrows[j]; switch (currentThrow.throwType) { case 0: currentScore += currentThrow.score; break; case 1: currentScore = 10; if (!currentFrame.lastFrame) { currentScore += frames[i + 1].ballThrows[0].score; } break; case 2: currentScore = 10; if (!currentFrame.lastFrame) { switch (frames[i + 1].ballThrows[0].throwType) { case 0: if (frames[i + 1].ballThrows[1].throwType != 1) { currentScore += frames[i + 1].ballThrows[0].score + frames[i + 1].ballThrows[1].score; } else { currentScore += frames[i + 1].ballThrows[1].score; } break; case 2: currentScore += frames[i + 1].ballThrows[0].score; if (!frames[i + 1].lastFrame) { currentScore += frames[i + 2].ballThrows[0].score; } else { currentScore += frames[i + 1].ballThrows[1].score; } break; } } break; } } score += currentScore; } return(score); }
public Frame(char[] frameChars, bool lastFrame) { ballThrows = new BallThrow[frameChars.Length]; for (int i = 0; i < frameChars.Length; i++) switch (frameChars[i]) { case 'X': ballThrows[i] = new BallThrow(10, 2); break; case '/': ballThrows[i] = new BallThrow(10, 1); break; default: ballThrows[i] = new BallThrow(int.Parse(frameChars[i].ToString()), 0); break; } this.lastFrame = lastFrame; }
public Frame(char[] frameChars, bool lastFrame) { ballThrows = new BallThrow[frameChars.Length]; for (int i = 0; i < frameChars.Length; i++) { switch (frameChars[i]) { case 'X': ballThrows[i] = new BallThrow(10, 2); break; case '/': ballThrows[i] = new BallThrow(10, 1); break; default: ballThrows[i] = new BallThrow(int.Parse(frameChars[i].ToString()), 0); break; } } this.lastFrame = lastFrame; }