-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