class EtudeOp10No6::Game

Public Class Methods

new() click to toggle source
# File lib/etude_op10_no6/game.rb, line 3
def initialize
  @its_current_frame = 0
  @first_throw_in_frame = true
  @its_scorer = Scorer.new
end

Public Instance Methods

add(pins) click to toggle source
# File lib/etude_op10_no6/game.rb, line 13
def add(pins)
  @its_scorer.add_throw(pins)
  adjust_current_frame(pins)
end
score() click to toggle source
# File lib/etude_op10_no6/game.rb, line 9
def score
  score_for_frame(@its_current_frame)
end
score_for_frame(the_frame) click to toggle source
# File lib/etude_op10_no6/game.rb, line 18
def score_for_frame(the_frame)
  @its_scorer.score_for_frame(the_frame)
end

Private Instance Methods

adjust_current_frame(pins) click to toggle source
# File lib/etude_op10_no6/game.rb, line 23
def adjust_current_frame(pins)
  if last_ball_in_frame(pins)
    advance_frame
  else
    @first_throw_in_frame = false
  end
end
advance_frame() click to toggle source
# File lib/etude_op10_no6/game.rb, line 39
def advance_frame
  @its_current_frame = [10,@its_current_frame+1].min
end
last_ball_in_frame(pins) click to toggle source
# File lib/etude_op10_no6/game.rb, line 31
def last_ball_in_frame(pins)
  strike(pins) || !@first_throw_in_frame
end
strike(pins) click to toggle source
# File lib/etude_op10_no6/game.rb, line 35
def strike(pins)
  @first_throw_in_frame && pins == 10
end