I was trying to pass the value from getattr
to another class Map()
, but it still tell me that there is no this argument in the class Engine. The thing is that how do I pass the attribute to the class Map? It keep looking the attribute in the class Engine()
.
class Engine(object):
def __init__(self,start):
self.map = start
self.quips = [
"You died. You kinda suck at this.",
"Your mom would be proud. If she were smarter.",
"Such a luser.",
"I have a small puppy that's better at this."
]
def death(self):
print (self.quips[randint(0,len(self.quips) - 1)])
exit(1)
def play(self):
next = self.map
while True:
print ("\n------------------")
# Trying to get attribute of object and pass to class Map.
Map = getattr(self, next)
next = Map()
class Map():
def __init__(self, next):
self.map = next
def central_corridor(self):
print ("The Gothons of planet Percal #25 have invaded your ship and destryoed")
if action == "shoot!":
print ("Quick on the draw you yank out your blaster and fire)
return 'death'
elif action == 'tell a joke':
print ("Lucky for you they made you learn Gothon insults in the academy")
return 'Go to bridge'
def go_to_bridge(self):
print ("You burst onto the Bridge with the neutron destruct bomb")
a_game = Engine("central_corridor")
a_game.play()
Traceback
Traceback (most recent call last):
File"c:\Learn_Python_In_the_hard_way\SourceCode\E42_Class_Execrise.py", line 175, in <module> a_game.play()
File "c:\Learn_Python_In_the_hard_way\SourceCode\E42_Class_Execrise.py", line 27, in play Map = getattr(self, next)
AttributeError: 'Engine' object has no attribute 'central_corridor'