Permalink
Browse files

Adds some scoring rules

  • Loading branch information...
1 parent 01e6445 commit 4146d8ee992d4f73c75ae7059dddee8ce388eb06 @justinxreese committed Apr 1, 2012
Showing with 11 additions and 2 deletions.
  1. +4 −1 game.rb
  2. +7 −1 game_spec.rb
View
@@ -17,7 +17,10 @@ def roll(pins)
end
frame << pins
@frames << frame
- @score += pins
+ end
+
+ def score
+ @frames.flatten.inject{|sum,x| sum + x } || 0
end
end
View
@@ -13,6 +13,11 @@
@game.score.should == 0
end
+ #it "returns 300 for a perfect game" do
+ # 21.times { @game.roll(10) }
+ # @game.score.should == 300
+ #end
+
it "returns 0 before rolls" do
@game.score.should == 0
end
@@ -64,7 +69,8 @@
it "tracks the game's scores" do
21.times.each{|n|@game.roll(10)}
- @game.frames.should == [[10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10, 10]]
+ @game.frames.should == [[10, 10], [10, 10], [10, 10], [10, 10], [10, 10],
+ [10, 10], [10, 10], [10, 10], [10, 10], [10, 10, 10]]
end
end

0 comments on commit 4146d8e

Please sign in to comment.