REFACTOR: extract spare checking logic
This commit is contained in:
parent
b6007c8115
commit
7c24567bfa
1 changed files with 5 additions and 1 deletions
|
|
@ -10,7 +10,7 @@ class BowlingGame {
|
|||
int rollIndex = 0;
|
||||
|
||||
for (int frame = 0; frame < 10; frame++) {
|
||||
if (_rolls[rollIndex] + _rolls[rollIndex + 1] == 10) {
|
||||
if (_isSpare(rollIndex)) {
|
||||
totalScore += 10 + _rolls[rollIndex + 2];
|
||||
rollIndex += 2;
|
||||
} else {
|
||||
|
|
@ -21,4 +21,8 @@ class BowlingGame {
|
|||
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
bool _isSpare(int rollIndex) {
|
||||
return _rolls[rollIndex] + _rolls[rollIndex + 1] == 10;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue