所以我一直在做 LPTHW,你知道我们应该做的“制作一款基于文本的角色扮演游戏”吗?嗯,我确实一直在这样做,但是每次我尝试运行它时,都会弹出此错误:
File "DimensionSpace.py", line 826, in <module>
a_game.play()
File "DimensionSpace.py", line 22, in play
next_scene_name = current_scene.enter()
AttributeError: 'function' object has no attribute 'enter'
我其实很困惑。这部分是我坚持读这本书的部分。代码如下所示:
from sys import exit
from random import randint
from textwrap import dedent
class Scene(object):
def enter(self):
print("This scene is not yet configured.")
print("Subclass it and implement enter().")
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
last_scene = self.scene_map.next_scene('credits')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
current_scene.enter()
有人可以帮我吗?
我认为您在播放功能中缺少括号:
current_scene = self.scene_map.opening_scene()
因为您没有调用该函数,因此没有取回场景对象,所以您将函数本身分配给 current_scene
。在函数对象上调用 Enter 函数没有意义。
我是一名优秀的程序员,十分优秀!