我是一个新的蟒蛇学习者,我正在阅读Zed Shaw的书: 学习python的艰难之处 我在遵循指示并进行研究训练方面做得非常好。 最近我试图自己制作一个小游戏,但我卡住了,我需要一些帮助 这是我的剧本:
from sys import exit
def starting():
print "Welcome to the abyss of dark"
print "The game is about choosing"
print "if you lose you die if you win you live"
choose_door = raw_input("> ")
if "1" in choose_door or "door 1" or "D1" or "d1":
no_weapon()
elif "2" in choose_door or "door 2" or "D2" or "d2":
Weapon_room()
elif "3" in choose_door or "door 3" or "D3" or "d3":
shortcut()
elif "4" in choose_door or "door 4" or "D4" or "d4":
princess_room()
elif "5" in choose_door or "door 5" or "D5" or "d5":
princess_room()
elif "6" in choose_door or "door 6" or "D6" or "d6":
gards_room()
else:
"7" in choose_door or "door7" or "D7" or "d7"
suicide_room()
start()
def map():
print """"
|------------------------------------------------------------------------------------|
| shortcut D|room of the | room of the| |
| to D4 O|princess | gards | S U I C I D E R O O M |
| O| | | |
| R| | | |
| 4| | | |
|-----DOOR 3---|------DOOR 5-------DOOR 6---------------------DOOR 7----------------|
|Weapon ROOM | |
| | DOOR 2 YOUR |
| | ARE |
| | HERE |
|------------| |
|No Weapon | DOOR 1 |
| | |
|------------|------------------------------------------------------------------------
"""
start()
def no_weapon():
print "You've choosed to continue with no Weapons"
print "What a BRAVE PLAYER!"
print "Choose your door"
print "3 , 5 , 6 , 7"
no_weapon_door = raw_input("> ")
if no_weapon_door == "3":
shortcut
elif no_weapon_door == "5":
princess_room
elif no_weapon_door == "6":
gards_room
else:
suicide_room
def Weapon_room():
print "You are armed now"
print "Which door you choose type just the number"
print "Door 3 or Door 4"
Weapon_room_door = raw_input("> ")
if Weapon_room_door == "3":
shortcut
else:
princess_room
def shortcut():
princess_room
def princess_room():
print "You won"
def gards_room():
print "fight with gards"
print "Yes or No"
fighting = raw_input("> ")
if fighing == "Yes":
princess_room
else:
fighting == "No"
lost
def suicide_room():
print "Die in peace"
lost
def lost():
print "You lost"
print "If you want to reapeat Press R if you wanna exit tye E"
losing = raw_input ("> ")
if losing == "R":
start()
else:
exit()
对我来说,我认为我应该写的一切,但是当我运行我的脚本时,我得到一个错误:
Traceback (most recent call last): File "newgame.py", line 26, in start() NameError: name 'start' is not defined
无法弄清楚 请帮助我,谢谢你
答案 0 :(得分:2)
你应该修改代码的格式,但我相信你的意思是把start()而不是start(),因为你没有一个名为start()的方法。
答案 1 :(得分:0)
您实际上可以将您的启动功能重命名为" start",因为您正在调用start func
答案 2 :(得分:0)
您缺少调用starting()
函数,而是错误地调用了start()
,而整个程序中没有定义{。}}。
因此,要么将程序中的第一个函数命名为start()
,要么将start()
的3个名称重命名为starting()
。