GREEN: calculate strike

This commit is contained in:
fiatcode 2026-02-10 12:34:55 +07:00
parent 9ca4accd7b
commit 8474b20e85

View file

@ -10,7 +10,10 @@ class BowlingGame {
int rollIndex = 0;
for (int frame = 0; frame < 10; frame++) {
if (_isSpare(rollIndex)) {
if (_isStrike(rollIndex)) {
totalScore += 10 + _rolls[rollIndex + 1] + _rolls[rollIndex + 2];
rollIndex += 1;
} else if (_isSpare(rollIndex)) {
totalScore += 10 + _rolls[rollIndex + 2];
rollIndex += 2;
} else {
@ -25,4 +28,8 @@ class BowlingGame {
bool _isSpare(int rollIndex) {
return _rolls[rollIndex] + _rolls[rollIndex + 1] == 10;
}
bool _isStrike(int rollIndex) {
return _rolls[rollIndex] == 10;
}
}