-4

我是 Python 新手,我有一个关于我今天正在编写的代码的快速问题。我正在创建一个使用 while 循环的游戏,其中两个对手将轮流“击中”对方,直到其中一个玩家的健康点为 0。

这是我到目前为止的代码,尽管它不起作用。任何人都可以帮忙吗?

done=False
while not done:
    if You.Hit_points>Opponent.Hit_points:
        move=raw_input("Would you like to make a move? (y/n) ")
        if move=="y":
            print "",You.name,"hit ",Opponent.name," by",You.Hit_points," hit points!"
            Opponent.Health=You.Hit_points+You.Skill_points+Opponent.Health
            print "Due to the hit",Opponent.name,"is left with",Opponent.Health," health points."
            print ("The Mighty Beast will make a move.")
            print "",Opponent.name,"hits",You.name,"by",Opponent.Hit_points,"points"
            You.Health=(Opponent.Hit_points-Opponent.Skill_points)+You.Health
            print "Due to the hit",You.name,"loses",Opponent.Hit_points,"points.Leaving",You.name,"with",You.Health,"health points."
            print "Now it is",Opponent.name,"'s turn to make a move"
            You.Health=You.Health-(Opponent.Hit_points+Opponent.Skill_points)
            print "Due to the hit",You.name,"is left with",You.Health,"health points."
    else:
        You.Hit_points==0
        move=="n"
        done=True
4

1 回答 1

0
if You.Hit_points>Opponent.Hit_points:

应该是

if You.Hit_points > 0 and Opponent.Hit_points > 0

正确的?否则一旦You' 的 HP 下降到Opponent' - 可能是在第一回合之后 - 战斗就会结束。

于 2013-05-08T02:51:06.257 回答