親愛なるStackOverflow天使、なぜ私はAttributeErrorを取得しているのかわかりません
私は本当にこの問題に固執しています。これはコードダンプのように思えるが、私がいない場合
class Room(object):
def __init__(self):
pass
def enter(self):
pass
class Road(Room):
def __init__(self):
pass
def enter(self):
pass
def walk(self):
print "It is afternoon and you stand by the road of Red Village. It is a small, run-down place"
print "with a few shops and houses. A few residents walk about. It is a quiet place. You need"
print "to steal gold to feed yourself and pay your rent. This evening you need to steal 800 gold"
print "to pay your rent and bills. There are houses and businesses in the area. But plan carefully,"
print "the police here are armed and the locals are suspicious of odd outsiders like yourself. But"
print "you can fight, which should help. In front of you is a food shop, a weapons shop,"
print "a medicine shop, a bank and an inn. Where would you like to go first?"
return 'road'
def run(self):
pass
class Engine(object):
def __init__(self, game_map):
self.game_map = game_map
def play(self):
future_scene = self.game_map.launch_scene()
last_scene = self.game_map.next_scene('finished')
while future_scene != last_scene:
returned_scene = future_scene.enter()
future_scene = self.game_map.next_scene(returned_scene)
# make sure you run the last scene
future_scene.enter()
class Map(object):
rooms = {
'road' : Road(),
'food_shop' : FoodShop(),
'weapons_shop' : WeaponsShop(),
'medicine_shop' : MedicineShop(),
'bank' : Bank(),
'inn' : Inn(),
'death' : Death(),
'finished' : Finished()
}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, returned_scene):
val = Map.rooms.get(returned_scene)
return val
def launch_scene(self):
return self.next_scene(self.start_scene)
firstscene = Map('road')
launch = Engine(firstscene)
launch.play()
謝罪:私はゲームをコーディングしていますし、このエラーメッセージ受信しています:ここで
File "VillageGame.py", line 120, in <module>
launch.play()
File "VillageGame.py", line 84, in play
returned_scene = future_scene.enter()
AttributeError: 'NoneType' object has no attribute 'enter'
すると、エラーメッセージが参照するコードですどの部分がエラーメッセージに関連しているのか、どの部分がリンクされていないのかを知ることができます。
誰かが私がこのメッセージから切り抜けることができるコードについての洞察を持っているなら、私はそれも感謝します。将来の質問をもっと短くするのに役立ちます。
こんにちは、私は 'def walk(self)'のすべてのコードを 'def enter(self)'に移動し、このエラーメッセージを受け取ります: 'File" VillageGame.py "、118行目、 launch。 play() ファイル "VillageGame.py"、行77、プレイ中 future_scene = self.game_map。launch_scene() AttributeError: 'Road'オブジェクトに属性がありません 'launch_scene'' –
問題が解決しました。ありがとう! –