package dojo.java;

/**
 * @author Norbert Wigbels (norbert@wigbels.de)
 */
public class BowlingGame {

    private int[] rolls = new int[20 + 1];
    private int currentRoll = 0;


    public int calcScore() {
        int score = 0;
        int subFrame = 0;

        for (int frame = 1; frame <= 10; frame++) {
            if (rolls[subFrame] == 10) {                                // Frame with Strike
                score += 10 + rolls[subFrame + 1] + rolls[subFrame + 2];
                subFrame++;
            } else if (rolls[subFrame] + rolls[subFrame + 1] == 10) {   // Frame with Spare
                score += 10 + rolls[subFrame + 2];
                subFrame += 2;
            } else {                                                    // normal Frame
                score += rolls[subFrame] + rolls[subFrame + 1];
                subFrame += 2;
            }
        }

        return score;
    }

    public void roll(int pinsDown) {
        rolls[currentRoll] = pinsDown;
        currentRoll++;
    }

}
