Created
July 30, 2011 23:36
-
-
Save philipschwarz/1116157 to your computer and use it in GitHub Desktop.
A Frame that models the domain more closely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bowling | |
class Frame | |
{ | |
public add(roll) { rolls << roll } | |
public addBonus(roll) { bonusRolls << roll } | |
public score() | |
{ | |
if(isStrike() || isSpare()) | |
{ | |
rolls.sum() + bonusRolls.sum() | |
} | |
else | |
{ | |
rolls.sum() | |
} | |
} | |
private rolls = [] | |
private bonusRolls = [] | |
public isStrike(){ roll(1) == 10 } | |
public isSpare(){ (roll(1) + roll(2)) == 10 } | |
private roll(n){ rolls[n-1] } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment