我正在用Python开发一个游戏,现在我需要做一个游戏循环,在这个循环中,随机选择一个人先走,轮到他们执行。在
到目前为止,我的代码是:
当运行状况>0和运行状况1>0时:
if turn == 1:
while loopx == False:
try:
move = raw_input("Do you want to attack or gegenerate health? Press 1 to ATTACK and 2 to REGEN. ")
print ""
move = int(move)
if move == 1:
health1 = health1 - damage
print "You attacked!"
loopx == True
elif move == 2:
health = health+regen
print "You regenerated health!"
loopx = True
else:
print "Invalid number, try again"
continue
except:
print "Invalid number, try again"
continue
turn == 2
if turn == 2:
AImove = r.randint(1,2)
if AImove == 1:
print "AI attacked!"
health = health - damage1
else:
print "AI regenerated!"
health1 = health1+regen1
turn == 1
continue
打印“游戏结束!”在
我使用的是python2.7。在
我在你的代码中看到的一个明显的问题就是你经常做错题。您使用的是
==
运算符,而不是=
运算符。前者检查平等,而不是做作业。在以下是修复此问题后的代码(请参阅注释了解修复位置):
相关问题 更多 >
编程相关推荐