line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPG::Dice; |
2
|
1
|
|
|
1
|
|
24802
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
352
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: emulate rolling dice |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "1.2"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
2
|
|
|
2
|
1
|
15
|
shift; |
12
|
2
|
|
|
|
|
5
|
my $pat = shift; |
13
|
2
|
50
|
|
|
|
10
|
confess "Bad pattern: $pat\nShould be in the form of 'xdy' where" |
14
|
|
|
|
|
|
|
. "\n\tx = number of dice \n\ty = number of sides." |
15
|
|
|
|
|
|
|
unless $pat =~ m/^\d+[dD]\d+$/; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
6
|
my $self = { |
18
|
|
|
|
|
|
|
sides => 0, |
19
|
|
|
|
|
|
|
num => 0 |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
5
|
bless $self, "RPG::Dice"; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
7
|
$pat =~ m@^(\d+)[dD](\d+)$@; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
9
|
$self->{num} = $1; |
27
|
2
|
|
|
|
|
6
|
$self->{sides} = $2; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
6
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub roll { |
33
|
2000
|
|
|
2000
|
1
|
8898
|
my $self = shift; |
34
|
2000
|
|
|
|
|
2082
|
my $ret = 0; |
35
|
|
|
|
|
|
|
|
36
|
2000
|
|
|
|
|
2788
|
foreach ( 1 .. $self->{num} ) { |
37
|
3000
|
|
|
|
|
5554
|
$ret += int( rand( $self->{sides} ) ) + 1; |
38
|
|
|
|
|
|
|
} |
39
|
2000
|
|
|
|
|
3912
|
return $ret; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |