class EtudeOp10No6::Scorer
Public Class Methods
new()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 4 def initialize @its_throws = Array.new(21,0) @its_current_throw = 0 end
Public Instance Methods
add_throw(pins)
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 9 def add_throw(pins) @its_throws[@its_current_throw] = pins @its_current_throw += 1 end
score_for_frame(the_frame)
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 14 def score_for_frame(the_frame) score = 0 @ball = 0 current_frame = 0 while current_frame < the_frame if strike score += 10 + next_tow_balls_for_strike @ball += 1 elsif spare score += 10 + next_ball_for_spare @ball+=2 else score += two_balls_in_frame @ball+=2 end current_frame += 1 end score end
Private Instance Methods
next_ball()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 59 def next_ball @its_throws[@ball] end
next_ball_for_spare()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 39 def next_ball_for_spare @its_throws[@ball+2] end
next_tow_balls()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 47 def next_tow_balls @its_throws[@ball] + @its_throws[@ball+1] end
next_tow_balls_for_strike()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 35 def next_tow_balls_for_strike @its_throws[@ball+1] + @its_throws[@ball+2] end
spare()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 55 def spare (@its_throws[@ball] + @its_throws[@ball+1]) == 10 end
strike()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 43 def strike @its_throws[@ball] == 10 end
two_balls_in_frame()
click to toggle source
# File lib/etude_op10_no6/scorer.rb, line 51 def two_balls_in_frame @its_throws[@ball] + @its_throws[@ball+1] end