我正在用python开发一个基于文本的游戏。我遇到了一个小问题。我的一个类方法告诉程序当敌人攻击时该怎么做。这是代码
def attack(self, method):
user_health_old = user_health
self.method = method
probs = random.randrange(1,100)
if method == "Knife":
while user_health > 0:
if probs in range(1,70):
attackWin = True
break
else:
attackWin = False
pla = player()
pla.healthRem(7)
if user_health < 1:
death()
elif method == "Hands":
while plaHealth > 0:
if probs in range(1,40):
attackWin = True
break
else:
attackWin = False
pla.healthRem(7)
if user_health < 1:
death()
pla = player()
pla.attackStatus()
player() 是类,这个方法是 attack() attackStatus() 是一个小块,它会告诉玩家在战斗中发生了什么,这是它的代码
def attackStatus(self):
if attackWin == True:
print "You Win, this time"
time.sleep(2)
if user_health < user_health_old:
print "But you're victory did come at a cost"
time.sleep(2)
print "You're new health value is: ",user_health
time.sleep(3)
还有几行代码,我没有运行整个程序,而是设置了 atm 来运行这个模块,
pla = player()
pla.attack("Knife")
当我运行程序时,问题就来了。它打开控制台,但立即退出。它也不输出任何信息。我不太确定发生了什么,如果有人可以帮助我,我将不胜感激。