好吧我一直在運行我的前額到一些代碼,我已經確定我只是在黑暗中拍攝此時。出於某種原因讓類點擊是一個真正的屁股疼痛,我想如果我使用自己的個人代碼,它可能是有道理的。所以這裏有一個我寫的試驗小腳本遊戲。 (它很粗糙,我相當新):https://github.com/Villagesmithy/Zombies-.git瞭解類和__Call__方法Py 2.7
我覺得要了解我在做什麼錯我必須讓它在我自己的代碼中指出。我確信有很多類似於我的問題,但他們悲傷地看着我的頭。
我得到的錯誤是這樣的:
Attribute Error: Combat instance has no __Call__ method
這裏就是我認爲是問題類:
class Combat:
def battle(self):
print start.player, " has: ", hp, "."
print "The zombie has: ", zombie.zom_health()
time.sleep(1)
if haf == True:
total_damage = hero_attacks * hero_damage
zombie.zom_health() - total_damage
print "You strike the zombie for %d damage!" %(total_damage)
print "The zombie's health is %d" %zombie.zom_health()
return zombie.zom_health()
time.sleep(3)
elif haf == False:
total_damage = zombie.zom_damage()- hero.hero_armor()
if total_damage > 0:
total_damage - hp
return hp
print "A zombie shambles through the baricade and damages you!"
print "You lost %d hp! Your hp is now: %d" %(total_damage, hp)
combat_loop()
time.sleep(3)
elif total_damage <= 0:
print "A zombie lurches at you but misses!"
time.sleep(3)
combat_loop()
else:
z.zom_killed()
def initv(battle):
bat = battle()
hero_init = random.randint(1,20)
zom_init = random.randint(1,20)
if hero_init >= zom_init:
#global haf Ignoring for now
haf = True
print "You attack first!"
bat.battle()
elif hero_init < zom_init:
#global haf
haf = False
print "The zombie attacks!"
bat.battle()
def start(): #The only fucking code that works
global zombies
zombies = random.randint(20,30)
arm = random.sample(armor,1)
wea = random.sample(weapon, 1)
player = raw_input("What is your name?")
print player, ",\n"
print "Your colony is under attack by %s zombies!" %(zombies)
print "Hold them off so the others can escape."
print "You are wearing an ", arm, "and weilding a", wea
time.sleep(3)
def combat_loop():
combat_call = Combat()
while zombies > 0:
combat_call.initv()
if zombies <= 0:
print "You held off the zombies off long enough to escape!"
print "With the way clear you grab your belongings and follow suit."
print "The end!"
sys.exit()
現在,如果你說這嘖嘖有老兄不知道他在做什麼你會是對的!我只是希望你們能幫助我做點擊。整個計劃可能需要以我不知道的賭注來焚燒。任何幫助你可以提供幫助。
請您提供您的問題充分回溯。 – zondo
你的縮進是正確的嗎?看起來像''Combat''是一個沒有任何東西的類...... – MSeifert
'initv'需要繼承自我。一個好的IDE會爲你找到這些錯誤,我建議你嘗試一下PyCharm。 – Signal