我正在学习与学习Python硬盘的方式Python和我使用字典和类制作一个“游戏”。代码不完整,但主要问题是AttributeError。AttributeError的:“Nonetype”对象有没有属性“进入”蟒蛇
我坚持了这个错误:
Traceback (most recent call last):
File "juego.py", line 86, in <module>
juego.play()
File "juego.py", line 60, in play
game.enter()
AttributeError: 'NoneType' object has no attribute 'enter'
代码:
class entry(): #OK
def enter(self):
print 'Llegaste a la primera habitacion, miras a tu alrededor...'
print 'y ves un boton rojo en la pared...'
print 'Que haces?'
print 'Apretas el boton?'
print 'O seguis mirando?'
boton_rojo = raw_input('> ')
if 'boton' in boton_rojo:
print 'Apretas el boton y...'
print 'Aparece una puerta adelante tuyo!'
return 'Rescate_Prisionero'
elif 'mir' in boton_rojo:
print 'Seguis mirando...'
print '...'
print 'no encontras nada y decidis apretar el boton rojo'
print 'Apretas el boton y...'
print 'Aparece una puerta adelante tuyo!'
else:
print 'eh? que dijiste?'
class rescate_prisionero():
def enter(self):
print 'parece que si'
return 'Mago_Poderoso'
class mago_poderoso():
def enter(self):
print 'trolo'
return 'Pelea_esqueleto'
class pelea_esqueleto():
def enter(self):
print 'esque'
return 'Habitacion_Vacia'
class habitacion_vacia():
def enter(self):
print 'vac'
return 'Final_Scene'
class final_scene():
def enter(self):
print 'parece que esta todo bien'
class Engine(object):
def __init__(self, primer_escena):
self.primer_escena = primer_escena
def play(self):
ultima_escena = Map.Escenas.get('Final_Scene')
game =self.primer_escena.arranque().enter()
while game != ultima_escena:
game = Map.Escenas.get(game)
game.enter()
class Map():
def __init__(self, primer_escena):
self.primer_escena = primer_escena
def arranque(self):
inicio = Map.Escenas.get(self.primer_escena)
return inicio
Escenas = { 'Entry' : Entry(),
'Rescate_Prisionero' : rescate_prisionero(),
'Mago_Poderoso' : mago_poderoso(),
'Pelea_esqueleto' : pelea_esqueleto(),
'Habitacion_Vacia' : habitacion_vacia(),
'Final_Scene' : final_scene()
}
pepe = Map('Entry')
juego = Engine(pepe)
juego.play()
编辑:对不起,我忘了错误,代码现在已经完成
你忘了给我们的错误消息。 –
你也忘了发布整个代码。 Entry没有定义。 –
我添加了错误,代码是完全 – mavocado