Pages

Saturday, March 8, 2014

Class and inheritance in Python

# my example to show a shell for class's for a game in Python
# I'm sure there is a better way, but this will kinda show you how to make the inheritance, and class thing
# work together. You can switch the modules around to any class, as long as the class is defined before you #use them. 

##  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.  Same as the other shell, but in all classes.

## ALL props to Zed Shaw and his amazing learning tools.  http://learnpythonthehardway.org

class State(object):
    #could store global variables here, instead of making them global
    def __init__(self, name):
        self.name = name
       
       
class Wingame(object):
    def __init__(self, chicken_dinner):
        self.chicken_dinner = chicken_dinner
    def winner(self):
        print "winner winner , chicken dinner! %s"

class Endgame(Wingame):
    def __init__(self, wawa):
        self.wawa = wawa
    def end_credits(self):  #game over
        print " You LOSE - Nellie Tobey - shell designer"
        Wingame(object).winner()
       
class Battle(Endgame):
    def __init__(self, charge):
        self.charge = charge
    def fight(self):
        print "Lets get ready to wooooop azz."
        Endgame(object).end_credits()

class Level_up(Battle):
    def __init__(self, woot):
        self.woot = woot
    def stats(self):
        print " congrats, you are level -impotent-"
        Battle(object).fight()
       
class Enemy_pos(Level_up):
    def __init__(self, pos_badguy):
        self.pos_badguy = pos_badguy
    def point_enemy(self):
        print "There he goes!  Gettim!"
        Level_up(object).stats()
       
class Enemy(Enemy_pos):
    def __init__(self, badguy):
        self.badguy = badguy
    def Rawwwr(self):
        print " we need more chose to be the badguy games!"
        Enemy_pos(object).point_enemy()
       
class Hero_pos(Enemy):
    def __init__(self, sexy_pos):
        self.sexy_pos = sexy_pos
    def point_hero(self):
        print " There he goes with that swaaard again!"
        Enemy(object).Rawwwr()
       
class Hero(Hero_pos):
    def __init__(self, sexy):
        self.sexy = sexy
    def mighty(self):
        print "FF is better at female lead roles then American cinema"
        Hero_pos(object).point_hero()
       
class Npc_pos(Hero):
    def __init__(self, poser):
        self.poser = poser
    def point_npc(self):
        print "character is at point (2, 3)"
        Hero(object).mighty()

class Npc(Npc_pos):
    def __init__(self, cpu):
        self.cpu = cpu
    def char_dialog(self):
        print "You have a quest, let me give you arbitrary things to do!"
        Npc_pos(object).point_npc()
       
class Inventory(Npc):
    def __init__(self, stuffing):
        self.stuffing = stuffing
    def stuff(self):
        print "inventory = this, that, the other thing"
        Npc(object).char_dialog()

class Images(Inventory):
    def __init__(self, image):
        self.image = image
    def show_image(self):
        print " ******************* "
        print " **     INTRO     ** "
        print " ******************* "
       
        Inventory(object).stuff()

class Storyline(Images):
    def __init__(self, story):
        self.story = story
    def storyintro(self):
        print "story introduction"
        Images(object).show_image()

class Start(Storyline):
    def __init__(self, heregoes):
        self.heregoes = heregoes
    def game_instructions(self):
        print "start, game instructions"
        Storyline(object).storyintro()


Gamestart = Start(object).game_instructions()

       

No comments:

Post a Comment