我试图编写一个游戏,在这个游戏中你要经历9层地狱,以便通过“艰难的学习Python”#34;但是,当我试图进入游戏中的下一个场景时,我无法弄清楚为什么我会收到某个错误消息:
class Scene(object): # class Scene has-a function named enter
def enter(self): # create enter function
pass
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
last_scene = self.scene_map.next_scene('Lust')
current_scene = self.scene_map.opening_scene()
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
current_scene.enter()
class Death(Scene):
def enter(self):
pass
class Limbo(Scene):
def enter(self):
print """ In Limbo reside the unbaptized and the virtuous pagans
who, although not sinful, did not accept Christ.
Without baptism, they lacked the hope for something
greater than rational minds can conceive.
You find yourself within Limbo, even though you weren't
a Pagan. How strange! You look around, and see a man
that looks like someone important, but you don't know
who he is. What do you do?"""
action = raw_input("> ")
if raw_input == "Walk around" or raw_input == "walk around":
print "You walk around for a bit, admiring the scenery. You get bored quickly."
elif raw_input == "talk to the man":
print ""
else:
print 'Lust'
class Lust(Scene):
def enter(self):
pass
class Map(object):
scenes = { # create a dictionary of the scenes you want to use
'limbo': Limbo(),
'lust': Lust(),
}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
val = Map.scenes.get(scene_name)
return val
def opening_scene(self):
return self.next_scene(self.start_scene)
当我运行它时,我可以通过第一个"级别"但是当我进入操作提示并输入内容时,它会取消错误代码:
File "game.py", line 21, in play
current_scene.enter()
AttributeError: 'NoneType' object has no attribute 'enter'
并且无法找出原因。