如何解决后退按钮数量不确定后,即使所有按钮均正确,屏幕仍显示错误消息
这个回答有点复杂,但是基本上,经过一堆正确的答案+返回后,即使所有答案都是正确的,我的屏幕也不正确。它可能与游戏循环有关,但由于我现在感到困惑,因此需要任何帮助。随意复制和粘贴,因为我认为我的解释并不能很好地说明所有问题。
import pygame
import random
pygame.init()
#TO DO: Make questions and make them random and fix go back into incorrect bug.
#Title
pygame.display.set_caption('Average Speed Game')
#Screen
screenWidth=900
screenHeight=500
win=pygame.display.set_mode((screenWidth,screenHeight))
#Framerate
clock= pygame.time.Clock()
#background image
bg=pygame.image.load('C:\\Users\\18597\\Desktop\\My Python Scripts\\speed\\bg.png')
#button colors
buttonWhite=(255,255,255)
buttonPink=(255,182,193)
class car(object):
def __init__(self,x):
self.x=x
self.y=300
self.image=pygame.image.load('C:\\Users\\18597\\Desktop\\My Python Scripts\\speed\\car.png')
#Car Instance
global racer
racer=car(0)
class question(object):
def __init__(self,b,c,d):
self.a=['Time/distance','Direction+Time','13mph']
self.b=b
self.c=c
self.d=d
self.q=['What is the Formula for Speed','What is the Formula for VeLocity','What is the average speed of 13miles in 6 min.']
self.font=pygame.font.SysFont('Courier',30,True,False)
def draw(self,win):
while newQ ==True:
self.font
q1Text= self.font.render(self.q[0],1,(255,193))
win.blit(q1Text,(200,50))
button('',130,150,300,50,buttonWhite,145,buttonPink,'inco')
q1TextA= self.font.render(self.a[0],193))
win.blit(q1TextA,(150,150))
button('',530,'co')
q1TextB= self.font.render(self.b,193))
win.blit(q1TextB,(550,240,350,'inco')
q1TextC= self.font.render(self.c,193))
win.blit(q1TextC,250))
button('','inco')
q1TextD= self.font.render(self.d,193))
win.blit(q1TextD,250))
break
#Button for Start
def button(msg,x,y,w,h,inactive,active,xT,yT,inactiveT,activeT,action=None):
#Use location of mouse to track the button
mouse= pygame.mouse.get_pos()
#Tracks mouse clicks
click=pygame.mouse.get_pressed()
#0 is x,1 is y,2 is width,3 is height
if x+w> mouse[0] >x and y+h>mouse[1]>y:
pygame.draw.rect(win,(x,h))
#Click[0] is left mouse click
if click[0] == 1 and action!= None:
if action == 'co':
correctPage()
elif action == 'inco':
incorrectPage()
elif action == 'backQ':
gameLoop()
elif action == 'start':
gameLoop()
else:
pygame.draw.rect(win,h))
buttonText= pygame.font.SysFont('Courier',False)
buttonType= buttonText.render(msg,(activeT))
buttonText2= pygame.font.SysFont('Courier',False)
buttonType2= buttonText2.render(msg,(inactiveT))
if x+w> mouse[0] >x and y+h>mouse[1] > y:
win.blit(buttonType2,(xT,yT))
else:
win.blit(buttonType,yT))
buttonText2= pygame.font.SysFont('Courier',(inactiveT))
def start():
start=True
while start:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
quit()
win.blit(bg,(0,0))
startFont=pygame.font.SysFont('Courier',False)
startText= startFont.render('Start Game',193))
win.blit(startText,(315,100))
button('Start',275,220,380,230,'start')
pygame.display.update()
clock.tick(15)
def incorrectPage():
inco=True
while inco:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
quit()
win.blit(bg,0))
incoFont=pygame.font.SysFont('Courier',False)
incoText= incoFont.render('Incorrect',193))
win.blit(incoText,100))
button('Back','backQ')
if racer.x>=200:
racer.x=-200
win.blit(racer.image,(racer.x,270))
pygame.display.update()
clock.tick(15)
def correctPage():
co=True
while co:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
quit()
win.blit(bg,0))
coFont=pygame.font.SysFont('Courier',False)
coText= coFont.render('Correct!',193))
win.blit(coText,'backQ')
racer.x+200
win.blit(racer.image,270))
pygame.display.update()
clock.tick(15)
global q1
q1=question('B.distance/Time','C.Accleration/Time','D.distance+Time')
def redrawGameWin():
win.blit(bg,0))
q1.draw(win)
win.blit(racer.image,270))
pygame.display.update()
clock.tick(15)
def gameLoop():
global newQ
newQ=True
#global q1
#q1=question('A.Time/distance','B.distance/Time','D.distance+Time')
global font
q1.font
run= True
while run:
clock.tick(27)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run=False
redrawGameWin()
start()
pygame.quit()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。