from enemy import Enemy, Troll, Vampire, VampireKing ugly_troll = Troll("Pug") print("Ugly troll - {}".format(ugly_troll)) another_troll = Troll("Ug") print("Another troll - {}".format(another_troll)) brother = Troll("Urg") print(brother) ugly_troll.grunt() another_troll.grunt() brother.grunt() # will fail # monster = Enemy("Basic enemy") # monster.grunt() ugly_troll.take_damage(12) marty = Vampire("Marty") marty.take_damage(10) print(marty) print("-" * 40) ugly_troll.take_damage(30) print(ugly_troll) # while marty.alive: # marty.take_damage(1)
from enemy import Troll, Vampyre, VampyreKing uglyTroll = Troll('Pug') print('Ugly troll - {}'.format(uglyTroll)) anotherTroll = Troll('Ug') print('Another troll - {}'.format(anotherTroll)) brother = Troll('Urg') print(brother) uglyTroll.grunt() anotherTroll.grunt() brother.grunt() uglyTroll.takeDamage(12) print(uglyTroll) uglyTroll.takeDamage(20) print(uglyTroll) oldVampyre = Vampyre('Drake') print(oldVampyre) youngVampyre = Vampyre('Lestat') print(youngVampyre) youngVampyre.takeDamage(25) print(youngVampyre) while oldVampyre.alive: oldVampyre.takeDamage(1)
monster.take_damage(4) print(monster) monster.take_damage(2) print(monster) print('><' * 50) ugly_troll = Troll("grr") print("Here comes the Ugly - {} ".format(ugly_troll)) toll = Troll("Yuck") print("Here comes another one - {} ".format(toll)) ugly_troll.grunt() toll.grunt() # toll.take_damage(12) # print(toll) print('><' * 50) kuro = Vampire("kuro") shiro = Vampire("shiro") print(kuro) print(shiro) kuro.take_damage(134) shiro.take_damage(24) print(kuro)
ugly_troll3 = Troll4("Ugly_troll3") print("Ugly Troll_2 = {}".format(ugly_troll3)) # ========================================================= # Now we will call subclass Troll5 # ========================================================= from enemy import Troll5 print("=" * 40) print("Calling Troll5 - grunt") print() print("=" * 20) ugly_troll = Troll5("Ugly_troll") ugly_troll.grunt() print("=" * 20) ugly_troll2 = Troll5("Ugly_troll2") ugly_troll2.grunt() print("=" * 20) ugly_troll3 = Troll5("Ugly_troll3") ugly_troll3.grunt() ugly_troll3.take_damage(5) print(ugly_troll3) # =============================================== # Test Vampire class # ===============================================
# This also shows an example of Overloading and Subclassing # Overloading: same name, different arguments, or different signature troll1 = Troll( 'Troll-1' ) # will take the init method of its superclass Enemy with default arguments's value print(troll1) troll2 = Troll('Troll-2') print(troll2) troll3 = Troll('Troll-3') print(troll3) troll1.grunt() troll2.grunt() troll1.take_damage(4) print(troll1) troll1.take_damage(20) print(troll1) troll2.take_damage(20) print(troll2) troll2.take_damage(2) print(troll2) troll2.take_damage(1)
# random_monster.take_damage(4) # print(random_monster) # # random_monster.take_damage(10) # print(random_monster) beautiful_troll = Troll("Pug") print("Beautfiful Troll - {}".format(beautiful_troll)) another_troll = Troll("Ug") print("Another troll - {}".format(another_troll)) brother = Troll("Urg") print(brother) beautiful_troll.grunt() another_troll.grunt() brother.grunt() dracula = Vampire("Dracula") # print(dracula) # dracula.take_damage(5) # print(dracula) # dracula.take_damage(6) # print(dracula) # dracula.reincarnate() while dracula.alive: dracula.take_damage(1) print(dracula)
from player import Player from enemy import Enemy, Troll, Vampire, VampireKing barney = Troll("Barney") print("Ugly troll - {0._name}".format(barney)) barney.grunt() barney.take_damage(15) print(barney) print("*" * 40) gerard = Vampire("Gerard") print(gerard) gerard.take_damage(10) print(gerard) while gerard._alive: gerard.take_damage(1) print(gerard) print("*" * 40) king = VampireKing("King") print(king) king.take_damage(8) print(king)
kyle = Player("Kyle") print(kyle) hatdog = Enemy("Hatdog", 11, 12) print(hatdog) random_monster = Troll("Jorb") print("Ugly troll - {}".format(random_monster)) another_troll = Troll("Ug") print(another_troll) broda = Troll("Urg") print(broda) broda.grunt() another_troll.grunt() random_monster.grunt() drac = Vampyre("Drac") print(drac) # while drac._alive: # drac.take_damage(1) # #print(drac) king = VampyreKing("Robert") print(king) while king._hit_points >= 0 and king._lives > 0: king.take_damage(200) print(king)
from enemy import Enemy, Troll, Vampire, VampireKing random_monster = Enemy("Gupta", 12, 1) print(random_monster) random_troll = Troll("Pug") print(random_troll) brother = Troll("Kauwa") print(brother) brother.grunt() brother.take_damage(51) vamp = Vampire("Ujjwal") print(vamp) vampKing = VampireKing("ad") print(vampKing)
from player import Player from enemy import Enemy, Troll, Vampire tim = Player('Tim') ugly_troll = Troll('Pug') print('Ugly troll - {}'.format(ugly_troll)) another_troll = Troll('Ug') print('Another troll - {}'.format(another_troll), end='\n') brother = Troll('Urg') print('Brother troll - {}'.format(brother)) ugly_troll.grunt() another_troll.grunt() brother.grunt() dracula = Vampire('Drac') print('Vampire - {}'.format(dracula)) dracula.take_damage(10) print(dracula) dracula.take_damage(3) print(dracula) brother.take_damage(4) print(brother)
Getters and Setters in python follow the same principle like in java or c sharp but syntax stays the same after they are defined """ print("*** GAME START ***") pug = Troll('Pug') print("Ugly Troll - {}".format(pug)) ug = Troll('Ug') print("Another Troll - {}".format(ug)) urg = Troll('Urg') print(urg) pug.grunt() ug.grunt() urg.grunt() drakula = Vampire('drakula') print(drakula) pug.take_damage(2) print(pug) drakula.take_damage(2) print(drakula) while drakula._alive: drakula.take_damage(1) #print(drakula)
# # Urg's Brother : # # Name : Urg Hit_points : 23 Lives : 1 # # """We can observe that we are using Three different constructors even without making them. # we can say that its a type of constructor overloading. But this is not true. # This is because python does not supports method overloading. # If we try, the last method we defined in the coned will be the only ine be exist. # Actually above all constructors are same, they have different no of parameters because # we have specified the default values of the rest parameters in the base class. # """ ug_troll = Troll("Ug") print(ug_troll) # O/p: # Name : Ug Hit_points : 23 Lives : 1 ug_troll.grunt() blood_drinker = Vampire("Blood Drinker") print(blood_drinker) blood_drinker.take_damage(6) print(blood_drinker) blood_sipper = Vampire("Blood Sipper") print(blood_sipper) # while blood_sipper._alive: # blood_sipper.take_damage(1) # print(blood_sipper) blood_king = VampireKing("Blood King")