Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
制作游戏的Python问题_Python_Python 2.7_Customization - Fatal编程技术网

制作游戏的Python问题

制作游戏的Python问题,python,python-2.7,customization,Python,Python 2.7,Customization,我是一名新的python学习者,正在阅读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 d

我是一名新的python学习者,正在阅读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 不明白
请帮帮我,谢谢你

你可能应该修改代码的格式,但我相信你是想把start改为start,因为你没有一个名为start的方法。

你实际上可以将start函数重命名为start,因为你正在调用start函数

你没有调用start函数,取而代之的是,你错误地称之为start,它在整个程序中没有定义


因此,可以将程序中的第一个函数命名为start,或者将三次出现的start重命名为starting。

看起来该函数名为starting,但您正在运行start,因此只需将第三行更改为def start:。