-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleDie.php
More file actions
42 lines (34 loc) · 799 Bytes
/
SingleDie.php
File metadata and controls
42 lines (34 loc) · 799 Bytes
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
<?php
namespace Fervo\Rollo;
class SingleDie implements DieInterface
{
protected $sides;
protected $result = null;
public function __construct($sides)
{
$this->sides = $sides;
}
public function roll()
{
if (function_exists('random_int')) {
$this->result = random_int(1, $this->sides);
} else {
$this->result = mt_rand(1, $this->sides);
}
}
public function getValue()
{
return $this->result;
}
public function getValueDescription()
{
if ($this->result) {
return sprintf('D%d:%d', $this->sides, $this->result);
}
return sprintf('D%d:*', $this->sides);
}
public function getExpression()
{
return 'D'.$this->sides;
}
}