-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathle-diecey.py
286 lines (228 loc) · 11.8 KB
/
le-diecey.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import os
import beaupy
from beaupy.spinners import *
from pystyle import Colors, Colorate
import requests
import re
def clear():
os.system("clear||cls")
def banner():
banner = """
██╗ ███████╗ ██████╗ ██╗███████╗ ██████╗███████╗██╗ ██╗
██║ ██╔════╝ ██╔══██╗██║██╔════╝██╔════╝██╔════╝╚██╗ ██╔╝
██║ █████╗█████╗██║ ██║██║█████╗ ██║ █████╗ ╚████╔╝
██║ ██╔══╝╚════╝██║ ██║██║██╔══╝ ██║ ██╔══╝ ╚██╔╝
███████╗███████╗ ██████╔╝██║███████╗╚██████╗███████╗ ██║
╚══════╝╚══════╝ ╚═════╝ ╚═╝╚══════╝ ╚═════╝╚══════╝ ╚═╝
Made by Ori#6338 | @therealOri_ | https://github.com/therealOri
"""
colored_banner = Colorate.Horizontal(Colors.purple_to_blue, banner, 1)
return colored_banner
def main():
def roll(minimum, maximum, num=1):
url = f"https://www.random.org/integers/?num={num}&min={minimum}&max={maximum}&col=5&base=10&format=plain&rnd=new"
#random numbers generated by atmospheric noise. (as close to random as one can get while not having to use math.)
number = requests.get(url)
if num > 1:
numbers_list = re.split(r'[\n\t]+', number.text.strip())
return numbers_list
else:
return int(number.text)
def choose(list_of_data):
maximum = len(list_of_data)-1
#for example lets say "list_of_data" is 11 items long, we need to account for index 0, 0 is the minimum so now there are 10 index spots to choose from, not 11.
#we will get an "index out of range" error without "-1".
url = f"https://www.random.org/integers/?num=1&min=0&max={maximum}&col=5&base=10&format=plain&rnd=new"
number = requests.get(url)
index = int(number.text)
if isinstance(list_of_data, list):
option = list_of_data[index]
return option
else:
return None
while True:
clear()
main_options = ["Regular Dice?", "D&D dice set?", "Exit?"]
print(f'{banner()}\n\nWhat would you like to do?\n-----------------------------------------------------------\n')
main_option = beaupy.select(main_options, cursor_style="#ffa533")
if not main_option:
clear()
exit("Keyboard Interuption Detected!\nGoodbye <3")
if main_options[0] in main_option:
# regular dice menu
clear()
while True:
reg_dice_options = ["1 Die?", "2 Dice?", "3 Dice?", "Custom?", "Back?"]
print(f'{banner()}\n\nHow many dice would you like to roll?\n-----------------------------------------------------------\n')
reg_dice_option = beaupy.select(reg_dice_options, cursor_style="#ffa533")
if not reg_dice_option:
clear()
break
if reg_dice_options[0] in reg_dice_option:
spinner = Spinner(ARC, "User has rolled 1 die...")
spinner.start()
die1 = roll(1, 6, 1)
spinner.stop()
input(f'The die has landed on: {die1}\n\nPress "enter" to continue...')
clear()
continue
if reg_dice_options[1] in reg_dice_option:
spinner = Spinner(ARC, "User has rolled 2 dice...")
spinner.start()
dice = roll(1, 6, 2)
spinner.stop()
input(f'The dice have landed on: {dice}\n\nPress "enter" to continue...')
clear()
continue
if reg_dice_options[2] in reg_dice_option:
spinner = Spinner(ARC, "User has rolled 3 dice...")
spinner.start()
dice = roll(1, 6, 3)
spinner.stop()
input(f'The dice have landed on: {dice}\n\nPress "enter" to continue...')
clear()
continue
if reg_dice_options[3] in reg_dice_option:
dice_list = []
clear()
while True:
try:
dice = int(beaupy.prompt("How many dice do you want to roll?"))
except:
input('Please choose a number/integer.\n\nPress "enter" to try again...')
clear()
continue
if type(dice) == int:
break
if dice == 1:
msg = f"User has rolled 1 die..."
else:
msg = f"User has rolled {dice} dice..."
spinner = Spinner(ARC, msg)
spinner.start()
dice_list = roll(1, 6, dice)
spinner.stop()
if dice == 1:
input_msg = f'The die has landed on: {dice_list}\n\nPress "enter" to continue...'
else:
input_msg = f'The set of "{dice}" dice have rolled: {dice_list}\n\nPress "enter" to continue...'
input(input_msg)
clear()
continue
if reg_dice_options[4] in reg_dice_option:
clear()
break
if main_options[1] in main_option:
# D&D dice menu
clear()
while True:
dnd_dice_options = ["Roll d4?", "Roll d6?", "Roll d8?", "Roll d10?", "Roll d12?", "Roll d20?", "Custom?", "Back?"]
print(f'{banner()}\n\nWhat dice would you like to roll?\n-----------------------------------------------------------\n')
dnd_dice_option = beaupy.select(dnd_dice_options, cursor_style="#ffa533")
if not dnd_dice_option:
clear()
break
if dnd_dice_options[0] in dnd_dice_option:
spinner = Spinner(ARC, "User has rolled a d4 die...")
spinner.start()
d4 = roll(1, 4, 1)
spinner.stop()
input(f'The d4 die has landed on: {d4}\n\nPress "enter" to continue...')
clear()
continue
if dnd_dice_options[1] in dnd_dice_option:
spinner = Spinner(ARC, "User has rolled a d6 die...")
spinner.start()
d6 = roll(1, 6, 1)
spinner.stop()
input(f'The d6 die has landed on: {d6}\n\nPress "enter" to continue...')
clear()
continue
if dnd_dice_options[2] in dnd_dice_option:
spinner = Spinner(ARC, "User has rolled a d8 die...")
spinner.start()
d8 = roll(1, 8, 1)
spinner.stop()
input(f'The d4 die has landed on: {d8}\n\nPress "enter" to continue...')
clear()
continue
if dnd_dice_options[3] in dnd_dice_option:
if beaupy.confirm("Want to make a 'percentile' role as well?"):
d10_00 = ["00", "10", "20", "30", "40", "50", "60", "70", "80", "90"] #
spinner = Spinner(ARC, "User has rolled a d10 die and a percentile die...")
spinner.start()
d10 = roll(0, 9, 1)
d10p = choose(d10_00)
if not d10p:
clear()
spinner.stop()
input('No valid list to choose an item from. Not a list.\n\nPress "enter" to continue...')
clear()
continue
spinner.stop()
input(f'The d10 die has landed on: {d10}\nThe percentile roll is: {d10p}\n\nPress "enter" to continue...')
clear()
continue
else:
spinner = Spinner(ARC, "User has rolled a d10 die...")
spinner.start()
d10 = roll(0, 9, 1)
spinner.stop()
input(f'The d10 die has landed on: {d10}\n\nPress "enter" to continue...')
clear()
continue
if dnd_dice_options[4] in dnd_dice_option:
spinner = Spinner(ARC, "User has rolled a d12 die...")
spinner.start()
d12 = roll(1, 12, 1)
spinner.stop()
input(f'The d12 die has landed on: {d12}\n\nPress "enter" to continue...')
clear()
continue
if dnd_dice_options[5] in dnd_dice_option:
spinner = Spinner(ARC, "User has rolled a d20 die...")
spinner.start()
d20 = roll(1, 20, 1)
spinner.stop()
input(f'The d20 die has landed on: {d20}\n\nPress "enter" to continue...')
clear()
continue
if dnd_dice_options[6] in dnd_dice_option:
clear()
dice_options = ["d4", "d6", "d8", "d10", "d10p", "d12", "d20"]
print(f"Dice options: {dice_options} | (d10p = percentile die)")
dice_input = beaupy.prompt("Enter dice in format 'XdY' separated by commas (e.g. '3d6, 2d4, 1d20'):")
dice_sets = dice_input.split(", ")
spinner = Spinner(ARC, "Rolling dice...")
spinner.start()
# Roll each set of dice and store the results in a list
all_results = []
for dice_set in dice_sets:
if "d10p" in dice_set:
num_dice = dice_set.split("d")
d10_00 = ["00", "10", "20", "30", "40", "50", "60", "70", "80", "90"]
results = [choose(d10_00) for i in range(int(num_dice[0]))]
else:
num_dice, dice_type = dice_set.split("d")
if dice_type == "d10":
results = [roll(0, 9, 1) for i in range(int(num_dice))]
else:
results = [roll(1, int(dice_type)) for i in range(int(num_dice))]
all_results.append(results)
spinner.stop()
clear()
print("Dice Results:\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n")
for i, results in enumerate(all_results):
print(f"{dice_sets[i]} has rolled: {results}\n")
input("\nPress enter to continue...")
clear()
continue
if dnd_dice_options[7] in dnd_dice_option:
clear()
break
if main_options[2] in main_option:
clear()
exit("Goodbye! <3")
if __name__ == '__main__':
clear()
main()