为游戏创建一个while循环
问题描述:
我是Python新手,对于我今天一直在处理的代码有个疑问。我正在创建一个使用while循环的游戏,其中两个对手将转向彼此“打”,直到其中一个玩家拥有0点生命值。为游戏创建一个while循环
这是我到目前为止的代码,虽然它不工作。谁能帮忙?
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
答
if You.Hit_points>Opponent.Hit_points:
也许应该
if You.Hit_points > 0 and Opponent.Hit_points > 0
吧?否则一旦You
的HP下降到Opponent
以下 - 可能在第一回合后 - 战斗将结束。
它怎么不起作用?如果它没有运行,可能是因为'Opponent.Hit_points'大于'You.Hit_points'以 – 2013-05-08 02:38:49
开头,那么你得到的错误信息是什么? – Serial 2013-05-08 02:39:35
我得到\t TypeError:不支持的操作数类型为+:'int'和'str' – user2360627 2013-05-08 03:42:47