2012-10-31 180 views
0

因此,我正在製作一個角色扮演遊戲,並且我正在製作一個地圖功能。該錯誤位於腳本頂部的def中,名爲map1。請哈欠我!無論你有什麼解決方案,你可以請解釋它做什麼,我很新。我得到TypeError:int object not callable

weap = 0 
fate = 0 
gold = 100 

#--------------------------------------------------------------------------------- 
def map1(dellon, forrest, fate): 
    print(dellon) 
    print("MAP") 
    print("---------------------------------------------------------------------------------") 
    print("type one of the following numbers, then press enter.") 
    if dellon == 1: 
     print("\n(1) Dellon") 
    if forrest == 1: 
     print("(2) Darkwood Forrest") 
    if fate == 1: 
     print("(3) Fate") 
    choice = float(input()) 
    if choice == 1: 
     dellon(0) 
    elif choice == 2: 
     forrest() 
    elif choice == 3: 
     fate() 
#--------------------------------------------------------------------------------- 
def forrest(): 
    print("What do you chose to do:") 
    print("(1) Go North\n(2) Go South\n(3) Go East\n(4) Go West\n(5) Go hunting") 
    choice = input() 
    if choice == 1: 
     print("You find Donna picking berries, do you wish to talk to her?") 
     print("(1) Yes\n(2) No") 
     talk = input() 
     if talk == 1: 
      pass 
     elif talk == 2: 
      forrest() 
    elif choice == 2: 
     Fate() 
     fate = 1 
    elif choice == 5: 
     from random import randint 
     hunt = randint(1,3) 
     if hunt == 1: 
      animal = randint(1,5) 
      if animal == 1: 
       print("You where ambushed by a wild bear.") 
       input() 
      elif animal == 2: 
       print("You have been ambushed by a wild wolf.") 
       input() 
      elif animal == 3: 
       print("You have been ambushed by a wild bobcat.") 
       input() 
      elif animal == 4: 
       print("You have been ambushed by a wild cyote.") 
      elif animal == 5: 
       pass 
       input() 
#--------------------------------------------------------------------------------- 
def kingsquestdone(gold, dellon, forrest, fate): 
    print("KING: I see you have the potions, good work!") 
    print("Give them to me, and I will have") 
    print("before you leave, here is your pay. I'll give") 
    print("my servant deliver them to the hospital. And I will give") 
    print("you 300 gold for your troubles.") 
    gold = gold + 300 
    print("Your current gold is "+ str(gold) +".") 
    choice = float(input("(1) Go into Dellon\n(2) Map: ")) 
    if choice == 2: 
     map1(dellon, forrest, fate) 
    elif choice == 1: 
     indellon(1) 
#--------------------------------------------------------------------------------- 
def lockfail(): 
    print("You have failed to pick the lock.") 
    game0() 

#--------------------------------------------------------------------------------- 
def king(name): 
    print("KING: Hello "+ name +", I requested your presence because") 
    print("we, the people of Dellon, need your help.") 
    print("We need you to seek out a berry called") 
    print("a jutish berry. It is for the public hospital, they need") 
    print("it to make healing remidies for the sick, and injured.") 
    print("--------------------------------------------------------------") 
    print("What do you want to say:") 
    print("1: Ok, I'll help.\n2: Maybe later.") 
    choice = float(input()) 
    if choice == 1: 
     print("KING: Good, the berry is found Darkwood Forrest. A woman named Donna.") 
     print("She has much exxperience in picking these berries, talk to") 
     print("her to learn how, and where to pick them. After you pick") 
     print("three bushes, return to me, and I will give you your pay.") 
     input("Press enter to continue into Darkwood Forrest.") 
     dforrestent() 
#--------------------------------------------------------------------------------- 
def allberriespicked(): 
    print("-----------------------------------------------------------------") 
    print("\nDONNA: Good, you have collected all of the needed berries.") 
    print("I'll take those, and make them into the potions that you need.") 
    print("You can return here any time you want to pick some berries") 
    print("for me to earn some extra coin. Return to the King, and deliver") 
    print("those berries to him.") 
    input("\nPress enter to travel to the king.") 
    kingsquestdone(gold) 

#--------------------------------------------------------------------------------- 
def dforrestent(): 
    def jutish4(): 
     from random import randint 
     berry = randint(1, 2) 
     if berry == 1: 
      print("---------------------------------------------------------------------") 
      print("\nYou have picked one jutish berry bush.") 
      input("Press enter to return to Donna.") 
      allberriespicked() 
     elif berry == 2: 
      print("---------------------------------------------------------------------") 
      print("\nYou didn'd find the correct bush this time, try again.") 
      input("Press enter to continue looking.") 
      jutish4() 
    def jutish3(): 
     from random import randint 
     berry = randint(1,2) 
     if berry == 1: 
      print("---------------------------------------------------------------------") 
      print("\nYou have picked one jutish berry bush.") 
      input("Press enter to continue picking the berries.") 
      jutish4() 
     elif berry == 2: 
      print("\nYou didn'd find the correct bush this time, try again.") 
      input("Press enter to continue looking.") 
      jutish3() 
    def jutish2(): 
     from random import randint 
     berry = randint(1, 2) 
     if berry == 1: 
      print("---------------------------------------------------------------------") 
      print("\nYou have picked one jutish berry bush.") 
      input("Press enter to continue picking the berries.") 
      jutish3() 
     elif berry == 2: 
      print("\nYou didn'd find the correct bush this time, try again.") 
      input("Press enter to continue looking.") 
      jutish2() 

    def jutish1(): 
     print("You enter a field type area with many different types of bushes.") 
     input("\nPress enter to look for more jutish berry bushes.") 
     from random import randint 
     berry = randint(1, 2) 
     if berry == 1: 
      print("\nYou have picked one jutish berry bush.") 
      input("Press enter to continue picking the berries.") 
      jutish2() 
     elif berry == 2: 
      print("\nYou didn'd find the correct bush this time, try again.") 
      input("Press enter to look again.") 
      jutish1() 
    forrest = 1 
    print("you have entered the forrest. You must search") 
    print("for Donna as the King has mentioned.") 
    print("") 
    print("1: Go West\n2: Go North\n3: Go East\n4: Go South") 
    choice = float(input("Enter a number to travel in that direction: ")) 
    if choice == 1: 
     print("You end up walking for hours, and never find Donna.") 
     print("You end up back at the enterance to Darkwood Forrest.") 
    elif choice == 2: 
     print("You find Donna, and speak to her.") 
     print("\nDONNA: Hello traveler, you must be the one") 
     print("delivering the jutish berries for the Dellon hospital.") 
     print("To find these berries, you must go to the enterance of the") 
     print("forrest, and then travel East, then you will find a") 
     print("short, and prickly bush with bright red berries, those are") 
     print("the jutish berries you are looking for. Pick berries from") 
     print("four of the bushes, then return to me.") 
     input("\nPress enter to continue.") 
     jutish1() 
#--------------------------------------------------------------------------------- 
def indellon(first): 
    if first == 0: 
     print("a man approaches you with a letter.") 
     print("MAN: Hello sir, what is your name?") 
     name = input("Name: ") 
     print("MAN: Ah, good to meet you, "+ name +", I have a") 
     print("message for from the King himself. He says that") 
     print("he wishes to discuss something that will relieve") 
     print("your bounty. I suggest you talk to him imidiatly.") 
     print("\nPress enter to conitinue.") 
     first = 1 
     input() 
     king(name) 
    elif first == 1: 
     print("What do you want to do?") 
     print("(1) Leave Dellon") 
     print("(2) Go to shops") 
     print("(3) Go to residential homes") 
     print("(4) Go to the King's castle") 
     print("(5) Map") 
     choice = input() 
     if choice == 1: 
      dellonsign() 
     elif choice == 2: 
      dellonshops() 
     elif choice == 3: 
      dellonhomes() 
     elif choice == 4: 
      kingscastle() 
     elif choice == 5: 
      map1(dellon, forrest, fate) 

#--------------------------------------------------------------------------------- 
def fight1(dellon): 
    print("you decide to confront the gaurd.") 
    en_hp = 10 
    pl_hp = 10 
    print("press (1) to attack") 
    choice = float(input()) 
    if choice == 1: 
     while True: 
      if weap == 1: 
       from random import randint 
       en_damage = randint (1,8) 
       pl_damage = randint (5,15) 
      elif weap == 0: 
       from random import randint 
       en_damage = randint (1,8) 
       pl_damage = randint (1,10) 
      en_hp = en_hp - pl_damage 
      pl_hp = pl_hp - en_damage 
      print("enemy hp is now:") 
      print(en_hp) 
      print("your hp is now:") 
      print(pl_hp) 
      print("press enter to attack again.") 
      input() 
      if en_hp < 1: 
       print("You win this battle, and continue onwards.") 
       input("press enter to continue") 
       dellon = 1 
       dellon(0) 
       break 
      if pl_hp < 1: 
       print("You died.") 
       input("press enter to continue") 
       fight1() 
       break 

#--------------------------------------------------------------------------------- 
def dellon(dellong): 
    if dellong == 1: 
     print("as you approach Dellon's city gates, you see") 
     print("a gaurd, do you want to try to sneak past him") 
     print("or confront him?") 
     print("(1) sneak past") 
     print("(2) confront") 
     choice = float(input()) 
     if choice == 1: 
      from random import randint 
      n = randint(1,2) 
      if n == 1: 
       print("you failed to sneak past the gaurd, and must") 
       print("commenc battle.") 
       fight1(0) 
      elif n == 2: 
       print("you have succesfully snuck past that gaurd and enter") 
       print("the city.") 
       dellon = 1 
       input() 
     elif choice == 2: 
      fight1(dellon) 
    elif dellong == 0: 
     print("(1) enter Dellon") 
     print("(2) map") 
     choice1 = float(input()) 
     if choice1 == 1: 
      indellon(0) 
     elif choice1 == 2: 
      map1(dellon, forrest, fate) 
#--------------------------------------------------------------------------------- 
def freedome(): 
    print("as you step outside, you see two signs, one says") 
    print("capitol city of Dellon, and the other says Red Bird Forrest.") 
    print("which path do you wish to choose?") 
    print("(1) Dellon") 
    print("(2) Forrest") 
    choice = float(input()) 
    if choice == 2: 
     forrest() 
    if choice == 1: 
     dellong = 1 
     dellon(1) 
#--------------------------------------------------------------------------------- 
def fightwin(): 
    print("do you wish to search this body? If you do, you may") 
    print("run into more gaurds, if not, you won't get a better weapon.") 
    print("(1) yes") 
    print("(2) no") 
    choice = float(input()) 
    if choice == 1: 
     print("you find a long sword, and continue out the jail") 
     print("doors and into freedome once more.") 
     weap = 1 
     freedome() 
    elif choice == 2: 
     print("you decide to ignore the body, and continue out the jail") 
     print("doors and into freedome once more.") 
     weap = 0 
     freedome() 
#--------------------------------------------------------------------------------- 
def fight(): 
    print("You have succesfully busted through the wall, and escaped your cell, but there's a gaurd on the other side! What do you want to do?") 
    en_hp = 10 
    pl_hp = 10 
    print("(1) attack") 
    choice = float(input()) 
    if choice == 1: 
     while True: 
      from random import randint 
      en_damage = randint(1,8) 
      pl_damage = randint(1,10) 
      en_hp = en_hp - en_damage 
      pl_hp = pl_hp - pl_damage 
      print("enemy hp is now:") 
      print(en_hp) 
      print("your hp is now:") 
      print(pl_hp) 
      print("press enter to attack again.") 
      input() 
      if en_hp < 1: 
       print("You win this battle.") 
       input("press enter to continue") 
       fightwin() 
       break 
      if pl_hp < 1: 
       print("You died.") 
       input("press enter to continue") 
       game0() 
       break 
#-------------------------------------------------------------------------------------- 
def lockgen(): 
    from random import randint 
    number = randint(1,2) 
    if number == 1: 
     lfight() 
    if number == 2: 
     lockfail() 
#-------------------------------------------------------------------------------------- 
def game0(): 
    print("You wake up very fatigued in a prison cell.") 
    print("Your location is unkown, and you must break out.") 
    print("Your only choice is to attempt to escape by digging your way") 
    print("through the wall with a stone you have found.") 
    print("-----------------------------------------------------") 
    print("1: Dig through wall") 
    prisonchoice = float(input()) 
    if prisonchoice == 1: 
     fight() 
    else: 
     game0() 
def gameover(): 
    input("Game Over. Press enter to exit.") 

print("") 
print("welcome to THE role playing game.") 
print("(1) Start game") 
print("(2) Type in checkpoint key") 
startchoice = float(input()) 
if startchoice == 2: 
    print("Enter in the code.") 
    code = float(input()) 
    if code == 123: 
     dellon = 1 
     forrest = 1 
     fate = 0 
     kingsquestdone(gold, dellon, forrest, fate) 
elif startchoice == 1: 
    game0() 
+2

發佈*全*回溯。 – Blender

回答

2

在你的功能,你有這樣的語句:

if dellon == 1: 
    print("\n(1) Dellon") 

這是檢查是否dellon等於1,所以我假設,想看看是否dellon是一個整數(就像@Blender所說的那樣,完整的回溯會更容易)。然後,你這樣做

if choice == 1: 
    dellon(0) 

假設dellon實際上是一個整數,你現在對待它,如果它是一個函數,並與0作爲參數調用它。你確實有一個dellon函數可以用參數調用,所以你可能需要看看你想用if dellon == 1:做什麼。快速瀏覽一下程序的其餘部分,你會看到dellon這個函數形式,你不需要這樣做,因爲它不會返回任何東西,並且已經可用於其他函數。

0

您遇到的問題是您正在使用map1函數中的參數對函數dellon(在模塊級聲明)進行遮蔽。

這裏的函數聲明:

def dellon(dellong): 
    ... 

但你不能從map1訪問它,因爲存在具有相同名稱的參數。由於參數是在函數中的局部變量,它「陰影」外函數定義,所以你不能得到它(至少不容易):

def map1(dellon, forrest, fate): 
    ... 

異常被觸發遠一點倒在map1,你試圖調用函數,而是得到了論證(這大概是一個整數):

if choice == 1: 
     dellon(0) 

這應該很容易解決。只需重命名map1中的參數或dellon函數即可。

相關問題