如何取消先前的if语句?

问题描述

我正在尝试为我正在制作的基于文本的游戏创建主菜单系统。我目前正在使用if语句基本上说“如果光标在某个按钮上并单击= True,请执行此功能”。

当前,我设法制作了一个退出按钮,但是遇到一个问题,如果我单击一个按钮,然后将鼠标悬停在该按钮所在的位置,屏幕将恢复为原始状态,大概是因为上一个语句仍在运行。我该如何取消以前的if语句,以免发生这种情况?

def mainMenu():
screen.blit(button,[0,0])
screen.blit(button,150])
screen.blit(button,300])


text1 = font.render('New Game',True,BLACK)
screen.blit(text1,[255,368])
text2 = font.render('Load Game',BLACK)
screen.blit(text2,[235,520])
text3 = font.render('Quit',BLACK)
screen.blit(text3,[334,672])


if x >=168 and y >=343 and x <=607 and y<=468:
    screen.blit(buttonHover,0])
    text1 = font.render('New Game',BLACK)
    screen.blit(text1,368])
if x >=168 and y >=498 and x <=607 and y<=620:
    screen.blit(buttonHover,150])
    text2 = font.render('Load Game',BLACK)
    screen.blit(text2,520])
if x >=168 and y >=646 and x <=607 and y<=770:
    screen.blit(buttonHover,300])
    text3 = font.render('Quit',BLACK)
    screen.blit(text3,[335,672])



if x >=168 and y >=646 and x <=607 and y<=770 and click == True:
    pygame.quit()
    sys.exit()

loadgame = False

if x >=168 and y >=498 and x <=607 and y<=620 and click == True:
   loadGame()


           
    


def loadGame():
screen.blit(background_image,-50])
screen.blit(button,-200])
screen.blit(button,-350])

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)