Class: BCDice::DiceTable::D66ParityTable

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/dice_table/d66_parity_table.rb

Overview

出目の偶奇による場合分け機能をもつD66表

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, odd, even) ⇒ D66ParityTable

Returns a new instance of D66ParityTable.

Parameters:

  • name (String)

    表の名前

  • odd (Array<String>)

    左ダイスが奇数だったときの次層テーブル(サイズ6)

  • even (Array<String>)

    左ダイスが偶数だったときの次層テーブル(サイズ6)



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

Parameters:

  • key (String)
  • locale (Symbol)

Returns:



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

表を振る

Parameters:

  • randomizer (#roll_once)

    ランダマイザ

Returns:

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