Class: BCDice::GameSystem::Fiasco::Side
- Inherits:
-
Object
- Object
- BCDice::GameSystem::Fiasco::Side
- Defined in:
- lib/bcdice/game_system/Fiasco.rb
Overview
片方の色のダイスロールを抽象化したクラス
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#diff(other) ⇒ String
もう一方の色との差分を求める.
-
#initialize(color, count) ⇒ Side
constructor
A new instance of Side.
- #roll(randomizer) ⇒ String
Constructor Details
#initialize(color, count) ⇒ Side
Returns a new instance of Side.
103 104 105 106 |
# File 'lib/bcdice/game_system/Fiasco.rb', line 103 def initialize(color, count) @color = color @count = count end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
136 137 138 |
# File 'lib/bcdice/game_system/Fiasco.rb', line 136 def color @color end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
136 137 138 |
# File 'lib/bcdice/game_system/Fiasco.rb', line 136 def total @total end |
Instance Method Details
#diff(other) ⇒ String
もう一方の色との差分を求める
126 127 128 129 130 131 132 133 134 |
# File 'lib/bcdice/game_system/Fiasco.rb', line 126 def diff(other) if @total == other.total "0" elsif @total > other.total "#{@color}#{@total - other.total}" else "#{other.color}#{other.total - @total}" end end |
#roll(randomizer) ⇒ String
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/bcdice/game_system/Fiasco.rb', line 110 def roll(randomizer) @dice_list = if @count == 0 [0] else randomizer.(@count, 6) end @total = @dice_list.sum() "#{@color}#{@total}[#{@dice_list.join(',')}]" end |