所以这是我试图制作的游戏的模型。我认为我遇到的问题是在第68-75行之间发生的。由于某种原因,NMHP或mobHP没有更新。谢谢你的帮助
我想要发生的事情:
该功能应该是" Mobs Chi"(mchi)小于"玩家chi"(phi)采取小怪健康(mobHP)并从中减去玩家伤害致电NMHP。然后我想要更新函数列表的一面。
##ranbat.py
##make random battle for Player
##import random
##import time
##
def mobspawn():
#imports
import random
import time
#list,tup, and dicts
plHP = ["30", "40", "50"]
gchi = [".5", ".6", ".7", ".8", ".9"]
pchi = [".5", ".6", ".7", ".8", ".9"]
mchi = [".5", ".6", ".7", ".8", ".9"]
dam = ["10", "20", "30", "40", "50", "60",]
enList = ["Slime", "Goblin", "Hound", "NyaaTrape", "Navi"]
enHP = ["10", "20", "30", "40", "50", "60",]
enGen = ["he", "She", "it"]
chiC = ["1", "2"]
HELP = [("#", "Name", "Description"),("1", "Attack", "Attacks your enemy with equipped weapon"),("2", "Defend", "Use your equipped weapon to defend"),("3", "Heal", "If player has Med_Kit uses it on player"),("3", "Stats", "Prints players stats"),("5", "Finisher", "A secret technique (Has a 50% chance of a insta-kill)"),("6", "HELP", "This comand displays Help")]
########
player = "Oni"
##############
#Mob stats #
##############
Gen = random.choice(enGen)
mobHP = random.randint(10, 60)
mob = random.choice(enList)
mdam = random.randint(10, 60)
mchi = random.randint(1, 9)
NMHP = 0
mstat = [("HP","NMHP","Damage", "Chi"),(mobHP, NMHP, mdam, mchi)]
##############
time.sleep(1)
print("Vofa: Oh no whats that!,", player, "protect me")
print("")
time.sleep(3)
#print("here 2 ")
print("You have incountered a wild", mob)
print("")
time.sleep(3)
print("Vofa: Looks like", Gen, "has",mobHP , "HP. Best be careful.")
print("")
##############
#Player stats#
##############
plHP = random.randint(10, 60)
pldam = random.randint(10, 60)
pchi = random.randint(1, 9)
plstat = [("HP","Damage", "Chi"),(plHP, pldam, pchi)]
##############
batMenDis()
player=int(input())
while player !=None:
player = int(input())
if player == 1:
print("You have chosen option #1 Attack")
print("You Attack")
time.sleep(3)
if (mchi) < (pchi):
(NMHP) = (mobHP) - (pldam)
(mobHP) = (NMHP)
if mobHP < 0:
print( mob, "is dead")
break
else:
print(mob,"Has",mobHP,"HP left")
if (mchi) > (pchi):
(NpHP) = (plHP) - (mdam)
(pHP) = (NpHP)
if plHP < 0:
print("you're almost dead. but you muster the strength to fight for a bit longer to keep vofa safe")
(pHP) = (pHP) + random.randint(1, 10)
else:
print(player,"Has",plHP,"HP left")
if (mchi) == (pchi):
print("Both you and mob have the same amount of chi")
time.sleep(1)
print("")
print("Coin has been tossed")
chiC = random.choice(chiC)
if chiC == 1:
mobHP = (mobHP) - (pldam)
print(mob,"Has",mobHP,"HP left")
if chiC == 2:
pHP = (plHP) - (mdam)
print(player,"Has",plHP,"HP left")
batMenDis()
if player == 0:
#print("here 2")
print("You have chosen option number 0")
print("Program Now Exiting")
time.sleep(2)
print("Good Bye. Have a nice day! hope to fight with you again")
break
def batMenDis():
print("")
print("What are you going to do")
print("")
print("1 = Attack")
print("2 = Defend")
print("3 = Heal")
print("4 = Print current Stats")
print("5 = Finisher (50% chance of working)")
print("6 = HELP")
def main():
mobspawn()
main()
答案 0 :(得分:1)
问题不在第68-75行之间:
if (mchi) < (pchi):
(NMHP) = (mobHP) - (pldam)
(mobHP) = (NMHP)
if mobHP < 0:
print( mob, "is dead")
break
else:
print(mob,"Has",mobHP,"HP left")
因为当你进入那里时,你的伤害总是大于怪物的HP(HP为1-9且伤害为10-60)。因此结果总是怪物被杀死。
但如果我们看另一个分支:
if (mchi) > (pchi):
(NpHP) = (plHP) - (mdam)
(pHP) = (NpHP) # error here, should be plHP
if plHP < 0:
print("you're almost dead. but you muster the strength to fight for a bit"
"longer to keep vofa safe")
(pHP) = (pHP) + random.randint(1, 10) # same here
else:
print(player,"Has",plHP,"HP left")
你没有减去plHP的损害,而是pHP(直到那时才定义)。这样,plHP始终保持不变。