パイガムのボタンをクリックするたびに、それは私にサイコロのように1から6の乱数を与えます。しかし、ウィンドウを閉じてプログラムを再実行しない限り、ボタンを押した回数は何度も同じになります。ここに私のコードです:完全にランダムになるパイガムのサイコロ
import pygame, sys
import random
pygame.init()
def main():
screen= pygame.display.set_mode([550,200])
screen.fill((0,0,0))
pygame.display.set_caption('dice')
pygame.display.flip()
myfont = pygame.font.SysFont("monospace", 15)
label = myfont.render("click the button to roll the dice!", 2, (255,0,255))
screen.blit(label, (200, 100))
dice= [1,2,3,4,5,6]
button= pygame.Rect(100,100,50,50)
playerroll= random.choice(dice)
running= True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running= False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
if button.collidepoint(mouse_pos):
print("you rolled a:" , playerroll)
pygame.draw.rect(screen, [255,255,255], button)
pygame.display.update()
if __name__== '__main__':
main()
私の問題を誰かに助けてくれますか?ありがとう
は 'playerroll'定義を削除し、(、playerroll「あなたはロール」)'置き換えるプリント、マウスクリックした後、それを更新する必要があります(サイコロ)) ' –
義務的なxkcd:https://xkcd.com/221/ – Lolgast