class Bowling::Frame
Attributes
balls[RW]
frame_number[RW]
game[RW]
Public Class Methods
Public Instance Methods
base_score()
click to toggle source
The base score ignores the 3rd ball of the final frame
# File lib/bowling/frame.rb, line 73 def base_score [ balls[0].score + balls[1].score, 10 ].min # No frame should have more than 10 end
final?()
click to toggle source
Returns true if this is the last frame of the game
# File lib/bowling/frame.rb, line 116 def final? frame_number == 9 # Frame with index 9 is 10th frame end
first_ball()
click to toggle source
# File lib/bowling/frame.rb, line 28 def first_ball balls[0] end
load( data )
click to toggle source
Load an array of scores (integers) representing each ball
# File lib/bowling/frame.rb, line 22 def load( data ) raise ArgumentError.new '#load needs array' unless data.instance_of? Array data.each_with_index{ |pins, i| @balls[i].knocked_pins = pins } end
next_ball()
click to toggle source
# File lib/bowling/frame.rb, line 43 def next_ball if final? balls[1] else next_frame.first_ball end end
next_frame()
click to toggle source
# File lib/bowling/frame.rb, line 33 def next_frame get_frame frame_number+1 end
next_next_ball()
click to toggle source
# File lib/bowling/frame.rb, line 52 def next_next_ball if final? next_frame.balls[2] elsif next_frame.strike? and not next_frame.final? next_next_frame.first_ball else next_frame.balls[1] end end
next_next_frame()
click to toggle source
# File lib/bowling/frame.rb, line 38 def next_next_frame get_frame frame_number+2 end
score()
click to toggle source
spare?()
click to toggle source
# File lib/bowling/frame.rb, line 126 def spare? not strike? and ( balls[0].score + balls[1].score >= 10 ) end
spare_score()
click to toggle source
Spare score represents the additional score added to the base when a spare occurs It is equal to the knocked_pins of the following ball
# File lib/bowling/frame.rb, line 97 def spare_score return 0 unless spare? if final? balls[2].score else next_ball.score end end
strike?()
click to toggle source
# File lib/bowling/frame.rb, line 121 def strike? first_ball.perfect? end
strike_score()
click to toggle source
Strike score represents the additional score added to the base when a strike occurs It is equal to the knocked_pins of the following 2 balls
# File lib/bowling/frame.rb, line 82 def strike_score return 0 unless strike? if final? balls[1].score + balls[2].score else next_ball.score + next_next_ball.score end end
total_balls()
click to toggle source
# File lib/bowling/frame.rb, line 108 def total_balls final? ? 3 : 2 end