Tuesday, August 20, 2019

The class to create monsters

# The class to create monsters
class Monster:
    def __init__(self, color, heads):
        self.color = color
        self.heads = heads
       
    def attack(self):
        print("Just attacked a Hero, Mu...hahahaha!!!")
   
    def announce(self):
        print("Behold !  I am here")
       
       
# Creating some real monsters
fogthing = Monster("Black", 5)
mournsnake = Monster("Yellow", 4)
tangleface = Monster("Red", 3)



# Checking whether those monsters got different existence in memory or not
print('I have ' + str(fogthing.heads) + ' heads and I\'m ' + fogthing.color)
print('I also have ' + str(mournsnake.heads) + ' heads and I\'m ' + mournsnake.color)
print('I got ' + str(tangleface.heads) + ' heads and I\'m ' + tangleface.color)

print("\n \n mournsnake comes in \n \n ")
# Making mournsnake talk   
print('I am a ' + str(mournsnake.heads) + ' headed monster.')

# Announce ownself
mournsnake.announce()


# Make an attack by the mournsnake
mournsnake.attack()

No comments:

Post a Comment