0

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)
Community
  • 1
  • 1
ferry
  • 97
  • 6
  • It is not a class variable and you have multiple problems in your code – Padraic Cunningham Dec 19 '15 at 16:40
  • There's so much problems here it is too broad for one question. – timgeb Dec 19 '15 at 16:42
  • Hi both, thanks for your quick replies, care to share some examples? Always willing to learn. – ferry Dec 19 '15 at 16:49
  • @ferry, there are literally dozens, you should strip your program down, test as you go to make sure everything does what you expect. a tut may help http://anandology.com/python-practice-book/object_oriented_programming.html#classes-and-objects, if your indentation as posted is correct then at the very least you should address that. `def __init__(self): self.gothonlife = gothonlife` is not actually in your class, it is in your method enter – Padraic Cunningham Dec 19 '15 at 16:53

0 Answers0