Wroking on roll logic

This commit is contained in:
Stephen Deaton 2024-06-18 13:13:29 -04:00
parent bb746798a6
commit e02f3a9ae6
2 changed files with 45 additions and 5 deletions

View File

@ -4,19 +4,58 @@ import pygame_widgets
import pygame
from pygame_widgets.button import Button
from pygame_widgets.dropdown import Dropdown
pygame.init()
import random
win_width = 600
win_height = 480
win_bg_color = (102, 255, 255)
win_bg_color = (0, 0, 0)
dice_results = []
def roll_dice():
print("Type of dice: D", side_dropdown.getSelected())
print("Number of dice: ", numdice_dropdown.getSelected())
results = []
for dice in range(0, numdice_dropdown.getSelected()):
results.append(random.randint(1, side_dropdown.getSelected()))
print(results)
pygame.init()
window = pygame.display.set_mode((win_width, win_height))
pygame.display.set_caption('Dice Roll')
icon = pygame.image.load(os.path.join("img", "PyGame\practice\icon\dieicon.png"))
icon = pygame.image.load(os.path.join("icon", "dieicon_64x.png"))
icon.convert_alpha()
pygame.display.set_icon(icon)
window.fill(win_bg_color)
side_dropdown = Dropdown(
window, 120, 10, 150, 50, name='How many sides',
choices=[
'D4',
'D6',
'D12',
'D20',
],
borderRadius=3, colour=pygame.Color(200, 200, 200), values=[4, 6, 12, 20], direction='down', textHAlign='left'
)
numdice_dropdown = Dropdown(
window, 320, 10, 150, 50, name='Number of Dice',
choices=[
'1',
'2',
],
borderRadius=3, colour=pygame.Color(200, 200, 200), values=[1, 2], direction='down', textHAlign='left'
)
button = Button(
window, 200, 300, 200, 50, text='Roll', fontSize=50, textColor=("red"),
margin=20, inactiveColour=(243, 243, 243), pressedColour=(0, 255, 0),
radius=5, onClick=roll_dice, font=pygame.font.SysFont('calibri', 30),
textVAlign='bottom',
)
@ -30,6 +69,7 @@ while run:
quit()
window.fill(win_bg_color)
pygame_widgets.update(events)
pygame.display.update()

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB