一段时间后进行检查

时间:2016-12-13 04:00:01

标签: python-3.x

我试图为游戏编写一段代码,我会创建一个向目标投射球的游戏,并在一段时间后检查球是否与目标发生碰撞。为了简单起见,我将仅包括移动球的部分并检查它们是否相撞。

def answer():
    answergiven = simpledialog.askstring("angle", "Pick an angle", initialvalue="Enter a degree")
    dMove = game.create_oval(75, 25, 100, 50,fill="black")
    degree = (90 + int(answergiven))
    for i in range(50):
        game.move(dMove, math.sin(math.radians(degree))*10, \
                  -math.cos(math.radians(degree))*10)
        time.sleep(0.06)
        game.update()
        check()

def check():
    global tarx
    global tary
    global game
    end = game.find_overlapping(tarx-25, tary-25,tarx+25, tary+25)
    if len(end) >1:
        choice = simpledialog.askstring("Congratz", "You win! Try again? Y/N")
        if choice == "Y":
            game.delete(dMove)
            game.delete(tar)
            play()
        if choice == "N":
            master.destroy()
    else:
        choice1 = simpledialog.askstring("Drat", "You missed! Try again? Y/N")
        if choice1 == "Y":
            game.delete(dMove)
            game.delete(tar)
            play()
        if choice1 == "N":
            master.destroy()

现在我遇到的问题是检查立即执行,而不是在球行进到路径末端之前。如何修改此项以在一段时间后执行检查?

0 个答案:

没有答案