玩家健康功能有问题

时间:2014-06-20 00:55:40

标签: python

所以我在课堂上做了一个小蟒蛇游戏。

无论如何,我将此作为一个功能:

def checkplayerhealth (playerhealth):
    while playerhealth < 1000:
        if playerhealth < 0:
            input ("Looks like you died.  Better luck next time! Press any key to exit")
            sys.exit()

每当我打电话,游戏就会停止。显然这是因为我需要找到一种方法来运行循环,或者至少不断地检查玩家健康并让游戏的其余部分继续运行。

有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

陈述

while playerhealth < 1000:
    if playerhealth < 0:
如果使用大于或等于0且小于1000的任何函数调用函数,

将使您进入无限循环。如果要中断该循环,则需要更改playerhealth的值的代码循环到小于0或等于或大于1000的东西。

也许,你的意思是:

def checkplayerhealth (playerhealth):
    if playerhealth < 0:
        input ("Looks like you died.  Better luck next time! Press any key to exit")
        sys.exit()