Liebe StackOverflow Angels,Ich kann nicht herausfinden, warum ich AttributeError
Ich bin wirklich mit diesem Problem fest. Ich entwickle ein Spiel und erhalte diese Fehlermeldung:
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'
Hier ist der Code, der von der Fehlermeldung verwiesen wird:
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()
Entschuldigt, wenn dies wie ein Code-Dump scheint, aber ich weiß nicht wissen, welche Teile für die Fehlermeldung relevant sind und welche Teile nicht damit verbunden sind - weil ich ziemlich neu darin bin, sehen Sie.
Wenn jemand einen Einblick hat, welchen Code ich aus dieser Nachricht herausschneiden könnte, würde ich das auch schätzen. Es würde mir helfen, zukünftige Fragen kürzer zu halten.
Hallo, ich habe den ganzen Code in der 'def gehen (Selbst)' auf 'def eingeben (Selbst)' und ich bekomme diese Fehlermeldung: 'Datei" VillageGame.py ", Zeile 118, in starten. play() Datei "VillageGame.py", Zeile 77, im Spiel future_scene = self.game_map.launch_scene() AttributeError: 'Road' Objekt hat kein Attribut 'launch_scene'' –
Problem gelöst. Vielen Dank! –