class ScoreSheet
Constants
- LowerScores
- UpperScores
Attributes
dice[R]
num_yahtzees[R]
sheet[R]
Public Class Methods
new(custom_dice=Array.new(5) {Dice.new.instance_eval "new_dice"})
click to toggle source
@param custom_dice [Array<Fixnum>] custom dice for testing
end¶ ↑
# File lib/scoresheet.rb, line 17 def initialize(custom_dice=Array.new(5) {Dice.new.instance_eval "new_dice"}) @sheet, @dice, @num_yahtzees = Hash.new, Dice.new(custom_dice), 0 Array.new(UpperScores).concat(LowerScores).each {|s| @sheet[s] = [0, false]} end
Public Instance Methods
enter_score(field)
click to toggle source
@param field [Symbol] @return [void] @raise ArgumentError
end¶ ↑
# File lib/scoresheet.rb, line 27 def enter_score(field) if field == :yahtzee && ((available :yahtzee) || @num_yahtzees > 0) @sheet[field] = yahtzee, true elsif available field @sheet[field] = send(field, @dice.values), true else raise ArgumentError, "Score already entered." end end
filled?()
click to toggle source
lower_score_total()
click to toggle source
# File lib/scoresheet.rb, line 52 def lower_score_total # @return [Integer] The total score of the lower part of the ScoreSheet @sheet.select{|x| LowerScores.include? x }.collect{|k,v| v[0]}.reduce :+ end
raw_upper()
click to toggle source
# File lib/scoresheet.rb, line 45 def raw_upper # @return [Fixnum] @sheet.select{|x| UpperScores.include? x }.collect{|k,v| v[0]}.reduce :+ end
to_s()
click to toggle source
@todo Find a less complex way to create final string @return [String]
end¶ ↑
# File lib/scoresheet.rb, line 87 def to_s ss = String.new ss += %Q( S C O R E S H E E T ).center(80, ?=) + "\n\n" (0..(UpperScores.length - 1)).each { |i| ss += print_score_sheet_line(i) } ss += bonus_yahtzee_line ss += "\n\n" ss += "Total Score: #{total}".center(80) + ?\n ss += (?= * 80) + ?\n return ss end
total()
click to toggle source
# File lib/scoresheet.rb, line 55 def total # @return [Integer] the grand total lower_score_total + upper_score_total end
upper_score_bonus()
click to toggle source
upper_score_total()
click to toggle source
# File lib/scoresheet.rb, line 49 def upper_score_total # @return [Fixnum] the total score of the upper part of the ScoreSheet, including bonuses raw_upper + upper_score_bonus end