Skip to content

Instantly share code, notes, and snippets.

@philipschwarz
Created July 30, 2011 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipschwarz/1116157 to your computer and use it in GitHub Desktop.
Save philipschwarz/1116157 to your computer and use it in GitHub Desktop.
A Frame that models the domain more closely.
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