您好,我有一小段较大代码中的代码,用于在游戏中显示敌人的健康栏,但出于某种原因,循环在我认为应该停止后仍在继续,我是否遗漏了什么或做错了什么
import pygame, sys
import time
import random
import os
import sqlite3
import os.path
damage_done = 1
random_monster_health = random.randint(7,10)
alive = True
print (random_monster_health)
while alive == True:
mob_health = random_monster_health - damage_done
print ("mob health is {}" .format(mob_health))
if mob_health != 0:
percent_damage_done = mob_health / int(random_monster_health)
how_much_health_bar = 1180 * (percent_damage_done)
else:
pass
random_monster_health = mob_health
print(random_monster_health)
if mob_health != 0:
print("the monster is still alive")
pass
else:
alive == False
print ("the monster is dead")
pass
print("the loop has ended")
这部分是错误的。您正在比较
alive
和False
应该是
旁注:您不需要在每个if语句中都使用pass
相关问题 更多 >
编程相关推荐