Don got the logic to work
This commit is contained in:
parent
4c9b1e328a
commit
62560d4735
|
@ -9,16 +9,36 @@ import random
|
||||||
win_width = 600
|
win_width = 600
|
||||||
win_height = 480
|
win_height = 480
|
||||||
win_bg_color = (0, 0, 0)
|
win_bg_color = (0, 0, 0)
|
||||||
dice_results = [4, 6, 8, 10, 12,20]
|
dice_results = []
|
||||||
dice_count = [ 0, 1]
|
text_color = (221, 221, 221)
|
||||||
|
|
||||||
|
def draw_results(clicked: bool = False):
|
||||||
|
if len(dice_results) == 0: return
|
||||||
|
my_string = "Results: "
|
||||||
|
for index, element in enumerate(dice_results):
|
||||||
|
my_string += str(element)
|
||||||
|
if index != len(dice_results) - 1:
|
||||||
|
my_string += ", "
|
||||||
|
if clicked: print(my_string)
|
||||||
|
font_size = 50
|
||||||
|
while True:
|
||||||
|
arail_20 = pygame.font.SysFont('bauhaus 93', font_size)
|
||||||
|
results_text = arail_20.render(my_string, True, text_color)
|
||||||
|
if results_text.get_width() < win_width:
|
||||||
|
break
|
||||||
|
font_size = font_size - 5
|
||||||
|
text_x = (win_width // 2) - (results_text.get_width() // 2)
|
||||||
|
text_y = win_height - 25 - results_text.get_height()
|
||||||
|
window.blit(results_text,(text_x, text_y))
|
||||||
|
|
||||||
def roll_dice():
|
def roll_dice():
|
||||||
|
global dice_results
|
||||||
print("Type of dice: D", side_dropdown.getSelected())
|
print("Type of dice: D", side_dropdown.getSelected())
|
||||||
print("Number of dice: ", numdice_dropdown.getSelected())
|
print("Number of dice: ", numdice_dropdown.getSelected())
|
||||||
results = []
|
dice_results = []
|
||||||
for dice in range(0, numdice_dropdown.getSelected()):
|
for dice in range(0, numdice_dropdown.getSelected()):
|
||||||
results.append(random.randint(1, side_dropdown.getSelected()))
|
dice_results.append(random.randint(1, side_dropdown.getSelected()))
|
||||||
print(results)
|
draw_results(True)
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
window = pygame.display.set_mode((win_width, win_height))
|
window = pygame.display.set_mode((win_width, win_height))
|
||||||
|
@ -45,8 +65,9 @@ numdice_dropdown = Dropdown(
|
||||||
choices=[
|
choices=[
|
||||||
'1',
|
'1',
|
||||||
'2',
|
'2',
|
||||||
|
'8',
|
||||||
],
|
],
|
||||||
borderRadius=3, colour=pygame.Color(200, 200, 200), values=[1, 2], direction='down', textHAlign='left'
|
borderRadius=3, colour=pygame.Color(200, 200, 200), values=[1, 2, 8], direction='down', textHAlign='left'
|
||||||
)
|
)
|
||||||
|
|
||||||
button = Button(
|
button = Button(
|
||||||
|
@ -56,25 +77,17 @@ button = Button(
|
||||||
textVAlign='bottom',
|
textVAlign='bottom',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
events = pygame.event.get()
|
events = pygame.event.get()
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
pygame.quit()
|
|
||||||
run = False
|
run = False
|
||||||
quit()
|
|
||||||
|
|
||||||
|
|
||||||
window.fill(win_bg_color)
|
window.fill(win_bg_color)
|
||||||
|
draw_results()
|
||||||
|
|
||||||
pygame_widgets.update(events)
|
pygame_widgets.update(events)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
|
quit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user