blob: 103a28210ab085acaa68aea9439ed72c399a63a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
class Dice::Result
attr_reader :rolls
def initialize
@rolls = []
end
# @param other [Dice::Result]
def ==(other)
sides == other.sides && face == other.face
end
# @param roll [Dice::Roll]
def add_roll(roll)
@rolls << roll
end
# @return [Integer]
def total
@rolls.sum(&:face)
end
def increase_sides_below_max(max_value, increase_by)
@rolls.each do |roll|
roll.increase_side_below_max(max_value, increase_by)
end
end
def to_s
"#{total} (#{@rolls.map(&:face).join(', ')})"
end
end
|