创建类的实例时可以调用类的实例吗?

问题描述 投票:0回答:1

我正在尝试编写文字冒险。我为房间中的对象创建了一个类。在以下代码中,

self.door = Object("Door", "There is an {} door in the north.".format("closed" if self.door.openstate == False else "open"), True, False, door_text, True, False)

我希望立即检测门是打开还是关闭,并相应地更改描述。我知道上面的代码肯定是错误的,但是有办法吗?

python python-3.x
1个回答
1
投票

我不确定是否能回答您的问题,但是我认为您需要为门创建一个单独的类,但我不确定100%。我假设您在这样的教室里上课:

class Room:

    def __init__(self):
        self.door = your_code_here
© www.soinside.com 2019 - 2024. All rights reserved.