forked from syntruth/Dice-Bag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard_dice.rb
62 lines (49 loc) · 841 Bytes
/
standard_dice.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# This builds off the dicelib, constructing sub-classes of the Dice::Roll
# class for the standard dice: d4, d6, etc...
require "dicelib"
module Dice
class Die < SimpleRoll
def initialize(sides)
super("1d#{sides}")
end
def roll(modifier=0)
modifier = 0 if not modifier.is_a?(Fixnum)
return super.total + modifier
end
end
class D4 < Die
def initialize
super(4)
end
end
class D6 < Die
def initialize
super(6)
end
end
class D8 < Die
def initialize
super(8)
end
end
class D10 < Die
def initialize
super(10)
end
end
class D12 < Die
def initialize
super(12)
end
end
class D20 < Die
def initialize
super(20)
end
end
class D100 < Die
def initialize
super(100)
end
end
end