原谅代码的绝对混乱,我对此很陌生。这是一个基本的避免坠落物体类型的游戏,我遇到的问题是我正在努力做到这一点,所以如果你“崩溃”,会显示一个弹出窗口,询问你是否想用是或否按钮再次玩。
到目前为止,我已经运行了弹出窗口,如果选择了 no,它就会退出。如果选择了“是”,它要么不做任何事情,要么我采取了不同的方法,它只是再次重复“崩溃”的声音,弹出窗口立即再次出现。
有人知道我在做什么错吗?我似乎找不到有人制作我想要的东西的教程
#resetting
def restart():
player_car.goto(-100,-400)
left.goto(-300, 600)
mid.goto(-100, 300)
right.goto(100, 800)
main
def crashed():
end = Tk()
end.iconbitmap('c:/CODEING/test_img/car_icon.ico')
end.bg = 'black'
end.title('Restart')
end.geometry('250x100')
question = Label(end, text='Would you like to play again?', font=('bold', 12))
question.grid(row=0, column=1, columnspan=5)
yes = Button(end, text='Yes', padx=20, pady=10, font=12, command=restart)
no = Button(end, text='No', padx=20, pady=10, font=12, command=exit)
yes.grid(row=3, column=1)
no.grid(row=3, column=4)
pad1 = Label(end, padx=10).grid(row=0, column=0)
pad2 = Label(end).grid(row=2, column=0)
end.mainloop()
def main():
global s
global hs
#left lane
left.sety(left.ycor() - left.dy)
if left.ycor() < -650:
left.sety(1000)
winsound.PlaySound('c:/CODEING/Test_sounds/point.wav', winsound.SND_ASYNC)
s += 10
if s > hs:
hs = s
pen.clear()
pen.write('''Score= {}
High score ={}'''.format(s, hs), font=('Comic Sans MS',20,'underline'))
if (left.ycor() <= -300 and left.ycor() >=-480) and (left.xcor() == player_car.xcor()):
left.dy *= 0
winsound.PlaySound('c:/CODEING/Test_sounds/car_crash.wav', winsound.SND_ASYNC)
time.sleep(1)
crashed()
while True:
wn.update()
main()