Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My BowlingGame Kata (still no OOP, but with some improves)
package com.tolbier.bowlinggamekata;
public class Game {
private int currentRoll = 0;
private int rolls[] = new int[21];
int rollIndex ;
public void roll(int pins) {
rolls[currentRoll++] = pins;
}
public int score() {
int score = 0;
rollIndex = 0;
for (int frame = 0; frame < 10; frame++) {
int frameScore = getFrameScore();
score += frameScore;
}
return score;
}
private int getFrameScore() {
int frameScore = 10;
if (isStrike()) {
frameScore += strikeBonus();
} else {
if (isSpare()) {
frameScore += spareBonus() ;
}else {
frameScore = sumOfBallsInFrame();
}
rollIndex++;
}
rollIndex++;
return frameScore;
}
private int sumOfBallsInFrame() {
return rolls[rollIndex] + rolls[rollIndex + 1];
}
private int strikeBonus() {
return rolls[rollIndex + 1] + rolls[rollIndex + 2];
}
private int spareBonus() {
return rolls[rollIndex + 2];
}
private boolean isSpare() {
return rolls[rollIndex] + rolls[rollIndex + 1] == 10;
}
private boolean isStrike() {
return rolls[rollIndex] == 10;
}
}
@tolbier

This comment has been minimized.

Copy link
Owner Author

commented Nov 18, 2017

with a Java "structured programming" schema, and with respect and devotion for "UncleBob" Original Kata, but in favour of cleaning, I think it could be improved as it is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.