Skip to content

Instantly share code, notes, and snippets.

@zankich
Created February 21, 2013 19:08
Show Gist options
  • Select an option

  • Save zankich/5007224 to your computer and use it in GitHub Desktop.

Select an option

Save zankich/5007224 to your computer and use it in GitHub Desktop.
class Game
def initialize()
@score = 0
@frame = []
@frame_number = 0
@first = true
end
def roll(number_of_pins)
if @first
@frame.push(number_of_pins)
# @frame.last += number_of_pins if @frame.last == 10
@first = false
else
@frame[@frame_number] += number_of_pins
@first = true
@frame_number += 1
end
end
def score()
@frame.each do |n|
@score += n
end
@score
end
def frame
@frame_number
end
end
require './game'
describe Game do
it "should add increment your score" do
g = Game.new
g.roll(10)
g.score.should eq(10)
end
it "should accept two rolls per frame" do
g = Game.new
g.roll(5)
g.roll(2)
g.frame.should eq(1)
end
# it "should calculate a spare" do
# g = Game.new
# g.roll(5)
# g.roll(5)
# g.roll(2)
# g.roll(0)
# g.score.should eq(14)
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment