所以,是的,我正在制作一個角色扮演游戲,但戰斗不太可靠……如果你能弄清楚為什么,那就太好了!
#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")
我試過改變回圈的標志并簡化它,但它似乎沒有做太多。它應該加載并讓你投入戰斗,但它會中途停止而不回傳任何東西,所以它不會脫離回圈
uj5u.com熱心網友回復:
想提出改進代碼的建議,并且在評論中發布代碼時遇到問題,所以這里是:
hp_string = ""
if HPPercent > 0:
full_hp = "█"
current_hp = "▓"
used_hp = "?"
for i in range(int((HPPercent-HPPercent % 10)/10)):
hp_string = full_hp
hp_string = current_hp
if HPPercent <= 90:
for i in range(9 - int((HPPercent-HPPercent % 10)/10)):
hp_string = used_hp
HealthBar = (hp_string " | ", HP, " / ",(100 * PL))
else:
HealthBar = "Unknown Health!!"
另外,正如評論中提到的&那樣,與andpython中的不同。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/453321.html
上一篇:計算引數在一定范圍內的時間問題
