Class: DndTreasureCalc::Dice

Inherits:
Object
  • Object
show all
Defined in:
lib/dnd_treasure_calc/dice.rb

Constant Summary collapse

@@rand =
Random.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rolls, faces, modifier = 0) ⇒ Dice

Returns a new instance of Dice.



8
9
10
11
12
# File 'lib/dnd_treasure_calc/dice.rb', line 8

def initialize(rolls, faces, modifier=0)
  @rolls = rolls
  @faces = faces
  @modifier = modifier
end

Class Method Details

.seed=(seed) ⇒ Object



21
22
23
# File 'lib/dnd_treasure_calc/dice.rb', line 21

def self.seed=(seed)
  @@rand = Random.new(seed)
end

Instance Method Details

#rollObject



14
15
16
17
18
19
# File 'lib/dnd_treasure_calc/dice.rb', line 14

def roll
  total = 0
  @rolls.times { total += @@rand.rand(@faces) + 1 }
  total += @modifier
  total
end