New learner here. I tried the methods indicated here but was unsuccessful. Can you please help me out with the following code. I can't seem to get the Escape Pod class to access the gothonlife variable in the Central Corridor class. Keep getting this error message "type object 'CentralCorridor' has no attribute 'gothonlife'? Thank you!
class Scene(object):
def enter(self):
pass
class Engine(object):
def __init__(self, scene_map):
print "On the floor you find a map with the following options. \n 1) Central Corridor \n 2) Laser Weapon Armory \n 3) The Bridge \n 4) Escape Pod. \n Where do you want to go?"
door = raw_input("> ")
count = 0
while (count < 1):
if door == "Central Corridor":
count = count + 1
object1 = CentralCorridor()
object1.enter()
elif door == "Laser Weapon Armory":
count = count + 1
elif door == "The Bridge":
count = count + 1
elif door == "Escape Pod":
count = count + 1
object5 = EscapePod()
object5.enter()
else:
print "Erm... where exactly do you want to go again?"
door = raw_input("> ")
class Death(Scene):
def enter(self):
print "You die, thanks for playing. Hope you had fun."
class CentralCorridor(Scene):
def enter(self):
print "There stands a Gothon. What do you want to do with him? \n 1) Offensive attack \n 2) Defensive attack \n 3) Suicide"
gothonlife = 10
herolife = 10
def __init__(self):
self.gothonlife = gothonlife
while (gothonlife > 0 and herolife > 0):
action = raw_input("What now? Offensive attack, defensive attack or suicide?")
if action == "Offensive attack":
gothonlife = gothonlife -3
herolife = herolife -2
print "your life stands at %s, the enemy life be at %s" % (herolife, gothonlife)
elif action == "Defensive attack":
gothonlife = gothonlife -2
herolife = herolife -0
print "your life stands at %s, the enemy life be at %s" % (herolife, gothonlife)
elif action == "Suicide":
herolife = herolife -11
print "your life stands at %s, the enemy life be at %s" % (herolife, gothonlife)
else:
print "Erm... where exactly do you want to go again?"
if herolife <0:
object2 = Death()
object2.enter()
elif herolife >0:
print "You defeated the Gothon, where do you want to go next?"
object3 = EscapePod()
object3.enter()
class LaserWeaponArmory(Scene):
def enter(self):
pass
class TheBridge(Scene):
def enter(self):
pass
class EscapePod(CentralCorridor):
def enter(self):
if CentralCorridor.gothonlife > 0:
print "A gothon stands guarding the escape pod."
object4 = CentralCorridor()
object4.enter()
elif CentralCorridor.gothonlife < 0:
print "You escape from Gothon! Congrats!"
class Map(object):
def __init__(self, start_scene):
print "You are at the entrance, there is a Gothon in front of you"
def next_scene(self, scene_name):
pass
def opening_scene(self):
pass
a_map = Map('central_corridor')
a_game = Engine(a_map)