Pages

Sunday, February 23, 2014

example of Python Class order of operations

##  Meggamuffins is my name!  Eating mushrooms is NOT my game!
#When you run this in terminal, it should show you how the order is written backwards,
# but the computer processes it bottom up.
## ALL props to Zed Shaw and his amazing learning tools.  http://learnpythonthehardway.org
class Meggamuffins(object):

    def __init__(self, gamedata):
       
        self.gamedata = gamedata
        def wingame(self):
            print "wingame = self"
            print "that is the entire list, if it all printed off, then it worked!"
        def endgame(self):
            print "endgame =  endgame"
            wingame(self)
        def battle(storyline, enemy, hero, level_up, npc):
            print "battle = storyline, enemy, hero, level_up, npc"
            endgame(self)
        def level_up(self, hero, inventory, storyline):
            print "self, hero, inventory, storyline"
            battle(storyline, enemy, hero, level_up, npc)
        def enemy_position(self, storyline, areamap, hero):
            print "enemy_position = self, storyline, areamap, hero"
            level_up(self, hero, inventory, storyline)
        def enemy(self, inventory):
            print "enemy = self, inventory)"
            enemy_position(self, storyline, areamap, hero)
        def hero_position(self, storyline, areamap, hero):
            print "hero_position = self, storyline, areamap, hero"
            enemy(self, inventory)
        def hero(self, storyline, areamap, inventory):
            print " Hero = self, storyline, areamap, inventory"
            hero_position(self, storyline, areamap, hero)
        def npc_position(self, storyline, areamap):
            print "npc_position = self, storyline, areamap)"
            hero(self, storyline, areamap, inventory)
        def npc(self, storyline, areamap, inventory):
            print "npc = self, storyline, areamap"
            npc_position(self, storyline, areamap)
        def inventory(self):
            print "inventory =  self"
            npc(self, storyline, areamap, inventory)
        def areamap(self, storyline):
            print "areamap = self, storyline"
            inventory(self)
        def storyline(self, areamap):
            print "storyline"
            areamap(self, storyline)
               
        def start(self):
            print "start"
            storyline(self, areamap)
       
        start(self)
   
   
   
           
           
## I have NO IDEA why we have to rename this object to call it.
## why can't I just type, Meggamuffins.gamedata(object)???
redundantnaming = Meggamuffins(object)
redundantnaming.gamedata()
   
   

No comments:

Post a Comment