我有两份文件。我的类.py为我的比赛准备了所有的课程游戏.py创建所有对象并运行游戏。我想我得到了错误,因为我的GameEngine对象看不到secondRoom对象。我在全球范围内创建了第二个房间。我不明白为什么GameEngine不能看到secondRoom?在
## game.py
from myclasses import *
## Creating objects
smallKey = Key("Small Key")
bossKey = Key("Boss Key")
firstRoom = Room("Room", ['north', 'south'], [smallKey, bossKey])
secondRoom = Room("ROOOM 2", ['south', 'east'], [])
player = Person(raw_input("Please enter your name: "), firstRoom)
## Setting class variables
firstRoom.description = "This is the first room"
secondRoom.description = "This is the second room..."
firstRoom.connects_to = {"north": secondRoom}
secondRoom.connects_to = {"south": firstRoom}
list_of_rooms = [firstRoom, secondRoom]
## Running the game
mygame = GameEngine()
mygame.StartGame(player, firstRoom)
在我的class.py公司名称:
^{pr2}$
把第二个房间传给StartGame:
另外,StartGame方法中的变量应该用
^{pr2}${cd1>以后使用。在
简而言之:全局是指模块全局。在
长回答:实际上,您的引擎不需要看到第二个房间,因为它在
connects_to
中被引用尝试替换:
南方也一样。在
或者更广泛地说:
^{pr2}$甚至:
你给了你的二房一张空的物品清单。在
也许您应该添加一个None值您的init方法参数:
^{pr2}$相关问题 更多 >
编程相关推荐