Class: BCDice::DiceTable::D66ParityTable
- Inherits:
-
Object
- Object
- BCDice::DiceTable::D66ParityTable
- Defined in:
- lib/bcdice/dice_table/d66_parity_table.rb
Overview
出目の偶奇による場合分け機能をもつD66表
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, odd, even) ⇒ D66ParityTable
constructor
A new instance of D66ParityTable.
-
#roll(randomizer) ⇒ String
表を振る.
Constructor Details
#initialize(name, odd, even) ⇒ D66ParityTable
Returns a new instance of D66ParityTable.
18 19 20 21 22 |
# File 'lib/bcdice/dice_table/d66_parity_table.rb', line 18 def initialize(name, odd, even) @name = name @odd = odd.freeze @even = even.freeze end |
Class Method Details
.from_i18n(key, locale) ⇒ D66ParityTable
10 11 12 13 |
# File 'lib/bcdice/dice_table/d66_parity_table.rb', line 10 def self.from_i18n(key, locale) table = I18n.t(key, locale: locale, raise: true) new(table[:name], table[:odd], table[:even]) end |
Instance Method Details
#roll(randomizer) ⇒ String
表を振る
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bcdice/dice_table/d66_parity_table.rb', line 27 def roll(randomizer) dice1 = randomizer.roll_once(6) dice2 = randomizer.roll_once(6) if dice1.odd? second_table = @odd else second_table = @even end result = second_table[dice2 - 1] key = dice1 * 10 + dice2 return RollResult.new(@name, key, result) end |