名称'开始()'未定义

时间:2017-10-30 00:15:49

标签: python-2.7

我正在制作的游戏中有两个文件(未完成)。它们是同一个目录。当我运行两个文件中的任何一个时,macos Serria中的终端正在给我这个错误(是的,我做了研究,但无济于事)。顺便说一句,谢谢你,StackOverFlow,回答(以及需要时的downvoting)问题。它真的帮助了我。:

File "story.py", line 3, in <module>
    from engine import *
File "SurvivalAdventureGame/Resources/engine.py", line 2, in <module>
    from story import *
File "SurvivalAdventureGame/Resources/story.py", line 5, in <module>
    class Start(Scene):
NameError: name 'Scene' is not defined

这是story.py:

from sys import exit
from random import randint
from engine import *

class Start(Scene):
    print """
    You are flying to Brussels from Seattle. You *are* glad you received the bonus from work, you think to yourself.
    \nUnfortunally, you were only able to put 100$ towards the vacation due to your bastard landlord.
    \nYou muttered to yourself, "If this plane got League Pass, though. Warriors-Raptors would be lit."
    \nYep, your 14-year old son says as he reads The New Jim Crow. Your 9-year old son is playing Minecraft.
    \nThen the speakers boomed, as the crew said, "Hi. My name is Messlia and our pilot is temporarily incapacitated."
    \nA strange mixture of curses, crying, yells of terror, and silence filled the cabin.
    \n"We will land shortly on a grass clearing near trees."
    \nMore panic.
    \nYou cried as You told your panicking sons (and secretly myself) to do
    """
    print "1. Bring only a blanket, some food and water, some clothing, and every medication needed."
    print "2. Bring nothing"
    print "3. Bring everything you possibly can."

    action = raw_input("> ")

    if action == "1":
        print "You survived, crawling out the door with a painful leg injury."
        print "\n Your older son, a safety-first guy, escaped without ANY injury AT ALL. Your other son, however, has a gaping hole in his wrists."
        print "\n He sheds tears, clearly in pain, as you ponder your options."
        print "1. Splash with water and cover it with a blanket"
        print "2. Cover it with a towel."
        print "3. Splash it with water only."

        next = raw_input("> ")

        if next == "1":
            print "Your now have about 50 mL of water left. However, he has calmed down."
            Day1()

        elif next == "2":
            print "You now have to tend to the boy at all times. However, at least he will not get sick, right?"
            Day1()

        elif next == "3":
            print "You now only have 50 mL of water left. At least he calmed down a bit!"
            Day1()

        else:
            Stupid()

    elif actions =="2":
        print "You survive with no injuries, however, you have nothing and your youngest son just suffered a major wrist injury."
        Day1()

    elif next == "3":
        print "You, your sons, and 12 people die because of you delaying everyone else."
        Death()

    else:
        Stupid()

class Death(Scene):
    print "Either you, one or both of your sons or others died. You suck."

class Stupid(Scene):
    print "ERROR: OVERWHELMING STUPIDITY."
    print "You should enter the numbers without the period, without the words"

这是engine.py:

from sys import exit
from story import *

class Scene(object):
    def __init__(self):
        start()
    def start(self):
        print "DOESNOTEXIST!"
        exit(1)

class Engine(object):
    def __init__(self, scene_map):
        self.scene_map = scene_map

    def play(self):
        current_scene = self.scene_map.opening_scene()
        while True:
            print "\n--------"
            next_scene_name = current_scene.start()
            current_scene = self.scene_map.next_scene(next_scene_name)

class Map(object):
    # Won't work now, Gotta finish writing the story!
    scenes = {
    "Start": Start(),
    "Day1": Day1(),
    "Day2": Day2(),
    "Day3": Day3(),
    "Day4": Day4(),
    "Day5": Day5(),
    "Day6": Day6(),
    "Day7": Day7(),
    "Day8": Day8(),
    "Death": Death(),
    "Stupid": Stupid(),
    }


    def __init__(self, start_scene):
        self.start_scene = start_scene()


    def next_scene(self, scene_name):
        return Map.scenes.get(scene_name)


    def opening_scene(self):
        return self.next_scene(self.start_scene)

class play(object, Map):
    def __init__(self, map):
        the_map = Map('Start')
        the_map = Engine(the_map)
        a_game.play()

1 个答案:

答案 0 :(得分:0)

看起来你有一个循环依赖:在故事中你从引擎导入*(一切),反之亦然。这在Python中不受支持。