函数中的循环随机停止
是的,我正在制作RPG,而战斗并不可靠...如果您能弄清楚为什么那会很棒!
#Enemy System
def MMEnemy(PL, HP, STR, DEF, SLTH, Name, CLASSNO):
EnemyLvl = random.randint(PL, (PL * 2))
EnemyHP = random.randint(EnemyLvl * 40, EnemyLvl * 80)
Defend = False
while HP >= 1 & EnemyHP >= 1:
HPPercent = HP / PL
HPPercent = int(HPPercent)
if HPPercent >= 90:
HealthBar = ("█████████▓ | ", HP, " / ",(100 * PL))
elif HPPercent >= 80 and HPPercent <= 89:
HealthBar = ("████████▓░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 70 and HPPercent <= 79:
HealthBar = ("███████▓░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 60 and HPPercent <= 69:
HealthBar = ("██████▓░░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 50 and HPPercent <= 59:
HealthBar = ("█████▓░░░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 40 and HPPercent <= 49:
HealthBar = ("████▓░░░░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 30 and HPPercent <= 39:
HealthBar = ("███▓░░░░░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 20 and HPPercent <= 29:
HealthBar = ("██▓░░░░░░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 10 and HPPercent <= 19:
HealthBar = ("█▓░░░░░░░░ | ", HP, " / ",(100 * PL))
elif HPPercent >= 0 and HPPercent <= 9:
HealthBar = ("▓░░░░░░░░░ | ", HP, " / ",(100 * PL))
else:
HealthBar = "Unknown Health!!"
print("The ", Name," is still standing... (", HealthBar, " HP)")
print("What should you do?")
print("1: Attack\n2: Heal\n3: Defend\n4: Run")
choice = input()
choice = int(choice)
if choice == 1:
roll = random.randint(STR, STR + 2)
print("You attack for ", roll)
EnemyHP -= (roll)
print(Name, " is at ", EnemyHP)
elif choice == 2:
roll = random.randint(PL * -2, PL * 5)
if CLASSNO == 2:
roll += PL * 3
if roll >= 1:
print("You healed for ", roll)
if roll <= 0:
print("You failed your heal [", roll," HP]")
HP += roll
elif choice == 3:
Defend = True
elif choice == 4:
print("Run failed, not implemented yet")
else:
print("None were chosen, you stood still")
DamageTaken = random.randint(5, EnemyLvl * 8)
if Defend == True:
prin("Your Defend was successful")
Defend = False
else:
HP -= DamageTaken
DamageTaken = str(DamageTaken)
print("You got damaged for ", DamageTaken,"!")
if HP <= 0:
print("You have been defeated by the ", Name,"...")
return "Lose"
if EnemyHP <= 0:
print("You defeated ", Name,"!")
return "Win"
CLASSNO = 1
level = 1
Strength = 5
Defence = 5
Stealth = 5
HP = 100
GameEnd = False
battle = MMEnemy(level, HP, Strength, Defence, Stealth, "Irc", CLASSNO)
battle = str(battle)
if battle != "Win" or battle != "Lose":
while battle != "Win" or battle != "Lose":
print("Restarted")
battle = MMEnemy(level, HP, Strength, Defence, Stealth, "Irc", CLASSNO)
battle = str(battle)
if battle == "Win":
print("Battle Won")
GameEnd = True
elif battle == "Lose":
print("Battle lost")
GameEnd = True
else:
print("Nothing Worked")
香港专业教育学院尝试更改循环的标志并简化它,但似乎并没有做很多事情。它应该加载并让您战斗,但它停止了一半,而没有归还任何东西,所以它不会脱离循环
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想提出对代码的改进,并且在评论中发布代码时遇到了麻烦,因此:
此外,正如评论中提到的某人,
&amp;
与不同>和
在Python中。Wanted to suggest an improvement to the code, and was having trouble posting the code in the comments, so here it is:
Also, as someone mentioned in the comments,
&
is not the same asand
in python.