-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.py
More file actions
36 lines (30 loc) · 1.12 KB
/
dice.py
File metadata and controls
36 lines (30 loc) · 1.12 KB
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
import random
class Dice:
def __init__(self, quant: int, size: int, negative: bool):
if quant <= 0 or size <= 0:
raise AttributeError("Dado com quantidade e/ou valor negativo")
self.quant = quant
self.size = size
self.negative = negative
self.total = 0
self.min_roll = self.quant * self.size
self.roll_str = ('-' if negative else '') + str(quant) + "d" + str(size)
def roll(self):
self.roll_str += " ( "
for i in range(self.quant):
this_roll = random.randint(1, self.size)
if this_roll <= self.min_roll:
self.min_roll = this_roll
self.total += this_roll
self.roll_str += str(this_roll) + " "
self.roll_str += ")"
if self.negative:
self.total *= -1
return self.total, self.roll_str
def get_as_character_dices(self):
self.roll()
self.total -= self.min_roll
self.roll_str += " - " + str(self.min_roll)
return self.total, self.roll_str
def boundaries(self):
return self.quant, self.quant * self.size