Class: BCDice::GameSystem::Fiasco::Side

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/game_system/Fiasco.rb

Overview

片方の色のダイスロールを抽象化したクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colorObject (readonly)

Returns the value of attribute color.



136
137
138
# File 'lib/bcdice/game_system/Fiasco.rb', line 136

def color
  @color
end

#totalObject (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

もう一方の色との差分を求める

Parameters:

Returns:

  • (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

Parameters:

Returns:

  • (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.roll_barabara(@count, 6)
    end

  @total = @dice_list.sum()

  "#{@color}#{@total}[#{@dice_list.join(',')}]"
end