gpt4 book ai didi

python - 制作一个简单的文本角色扮演游戏,却出现属性错误?

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:11 25 4
gpt4 key购买 nike

所以我一直在做 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 函数没有意义。

关于python - 制作一个简单的文本角色扮演游戏,却出现属性错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52612040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com