-1
因此,这是我尝试制作的游戏的模型。我遇到的问题发生在第68 - 75行之间,我想。出于某种原因,NMHP或mobHP没有更新。三江源任何帮助变量不会更新
我想做的发生:
的功能应该是“暴民志”(MCHI)小于“的玩家志”(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()
这不是一个简单的例子;请减少重现问题所需的代码。 – chepner 2014-09-26 18:10:37
@AdamSmith:不,首先,'(垃圾邮件)'不是元组;元组总是有逗号。其次,将双方包装在一个元组中将具有与包装一样的效果(这将是一件愚蠢的事情,但它不会破坏事物),同时包装一方而不包含另一方(除非权利边碰巧是一些其他类型的迭代)引发'TypeError:'int'对象不可迭代'或类似。 – abarnert 2014-09-26 18:12:33
@abarnert感谢您的更正。我仍然努力记住所有错综复杂的语言,而不需要拉扯解释器并尝试:) – 2014-09-26 18:13:49