所以,我正在制作角色扮演游戏,而我正在制作地图功能。错误位于脚本顶部名为map1的def中。请哈利!无论你有什么解决方案,请你解释它的作用,我有点新鲜。
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()
答案 0 :(得分:2)
在你的函数中,你有这样的陈述:
if dellon == 1:
print("\n(1) Dellon")
这是检查dellon
是否等于1,因此我假设想要查看dellon
是否为整数(正如@Blender所说,这会更容易完全追溯)。然后你这样做
if choice == 1:
dellon(0)
假设dellon
实际上是一个整数,您现在将其视为一个函数,并以0
作为参数调用它。你实际上有一个dellon
函数,可以通过参数调用,所以你可能需要看看你试图用if dellon == 1:
做什么。快速查看程序的其余部分,您将以dellon
的方式传递,这似乎是函数形式,您不需要这样做,因为它不会返回任何内容并且可用于其他函数已经
答案 1 :(得分:0)
您遇到的问题是您正在使用dellon
函数中的参数隐藏函数map1
(在模块级别声明)。
这是函数声明:
def dellon(dellong):
...
但是你无法从map1
访问它,因为有一个同名的参数。由于参数是函数中的局部变量,它会“遮蔽”外部函数定义,因此无法实现(至少不容易):
def map1(dellon, forrest, fate):
...
在你尝试调用函数的map1
中稍微触发异常,但是获取参数(可能是整数):
if choice == 1:
dellon(0)
这应该很容易修复。只需重命名map1
或dellon
函数中的参数。