GREEN: calculate strike
This commit is contained in:
parent
9ca4accd7b
commit
8474b20e85
1 changed files with 8 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue