首页 > 解决方案 > 为什么我的空闲窗口一直没有响应?

问题描述

当我对是否有人不想玩它说不时,它会崩溃,我希望它询问用户是否有人不想玩并将它们从列表中删除,然后询问是否还有。在我希望它加载游戏之后。

import pygame
from pygame import *
import random
import time
import sys
pygame.init()
Red = (247, 12, 12)
White = (255,255,255)
Blue = (0, 157, 255)
Black=(0,0,0)
Person_One = random.randint(0,19)
Person_Two = random.randint(0,19)
Number1 = random.randint(0,100)
Number2 = random.randint(0,100)
Number1 = random.randint(0,100)
Number2 = random.randint(0,100)
mmm =  ["Donald", "Jacey","Baxter","Dusan","Nathaniel","Hayden","Yusuf","Hayley","Andre","Rafif","Jeremey","Mark","Tia","Malu","Dorian","Jarius","Sammar","Peter","Rafif","Jasmin"]

Playerone = mmm[Person_One]
Playertwo = mmm[Person_Two]
X = 1400
timer = 0
Y = 1000
noonbe = input("Does anyone not want to play?\n")
noonbe.lower()
if noonbe == 'yes':
    thenwho = input("Who is it?\n")
    mmm.remove(thenwho)
    noonbe = input("Does anyone else not want to play?\n")
    noonbe.lower()
    if noonbe == 'yes':
        thenwho = input("Who is it?\n")
        mmm.remove(thenwho)
        noonbe = input("Does anyone else not want to play?\n")
        noonbe.lower()
    if noonbe == 'no':
        pass

    
display_surface = pygame.display.set_mode((X, Y))
font = pygame.font.Font('freesansbold.ttf', 20)
text = font.render("Player one is:", True, Black, White)
textRect = text.get_rect()
textRect.center = (X // 4.4, Y // 3.6)
text1 = font.render(Playerone, True, Black, White)
text1Rect = text1.get_rect()
text1Rect.center = (X // 4.4, Y // 3)
text2 = font.render("Player two is:", True, Black, White)
text2Rect = text2.get_rect()
text2Rect.center = (X // 1.5, Y // 3.6)
text3 = font.render(Playertwo, True, Black, White)
text3Rect = text3.get_rect()
text3Rect.center = (X // 1.5, Y // 3)
aa = True
while True:
    
    # completely fill the surface object
    # with white color
    display_surface.fill(White)
 
    # copying the text surface object
    # to the display surface object
    # at the center coordinate.
    display_surface.blit(text, textRect)
    display_surface.blit(text1, text1Rect)
    display_surface.blit(text2, text2Rect)
    display_surface.blit(text3, text3Rect)
    aa = False
    Number2=str(Number2)
    text3 = font.render(Number2, True, Black, White)
    text3Rect = text3.get_rect()
    text3Rect.center = (X // 1.5, Y // 3)
    pygame.display.update()
    time.sleep(20)
    font = pygame.font.Font('freesansbold.ttf', 20)
    text2 = font.render("Player two's number is:", True, Black, White)
    text2Rect = text2.get_rect()
    text2Rect.center = (X // 1.5, Y // 3.6)
    Number1 = str(Number1)
    text1 = font.render(Number1, True, Black, White)
    text1Rect = text1.get_rect()
    text1Rect.center = (X // 4.4, Y // 3)
    font = pygame.font.Font('freesansbold.ttf', 20)
    text = font.render("Player one's number is:", True, Black, White)
    textRect = text.get_rect()
    textRect.center = (X // 4.4, Y // 3.6)
    display_surface.blit(text, textRect)
    display_surface.blit(text1, text1Rect)
    display_surface.blit(text2, text2Rect)
    display_surface.blit(text3, text3Rect)    

它甚至发生在我没有添加 sys.exit()

标签: pythonpython-3.xwindowspygame

解决方案


推荐阅读