Class: BCDice::DiceTable::D66GridTable

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

Overview

D66を振って6x6マスの表を参照する

Direct Known Subclasses

D66HalfGridTable, D66OneThirdTable

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, items) ⇒ D66GridTable

Returns a new instance of D66GridTable.

Parameters:

  • name (String)

    表の名前

  • items (Array<Array<String>>)

    表の項目の配列



17
18
19
20
# File 'lib/bcdice/dice_table/d66_grid_table.rb', line 17

def initialize(name, items)
  @name = name
  @items = items.freeze
end

Class Method Details

.from_i18n(key, locale) ⇒ D66GridTable

Parameters:

  • key (String)
  • locale (Symbol)

Returns:



10
11
12
13
# File 'lib/bcdice/dice_table/d66_grid_table.rb', line 10

def self.from_i18n(key, locale)
  table = I18n.t(key, locale: locale, raise: true)
  new(table[:name], table[:items])
end

Instance Method Details

#roll(randomizer) ⇒ String

表を振る

Parameters:

  • randomizer (#roll_once)

    ランダマイザ

Returns:

  • (String)

    結果



25
26
27
28
29
30
31
32
33
# File 'lib/bcdice/dice_table/d66_grid_table.rb', line 25

def roll(randomizer)
  dice1 = randomizer.roll_once(6)
  dice2 = randomizer.roll_once(6)
  value = dice1 * 10 + dice2

  index1 = dice1 - 1
  index2 = dice2 - 1
  return RollResult.new(@name, value, @items[index1][index2])
end