def test_vampyre_king_take_damage(self): from random import randint vampyre_king = VampyreKing('Vampire King') while vampyre_king.lives != 0: damage = randint(1, 140) lives_b4 = vampyre_king.lives hit_points_b4 = vampyre_king.hit_points vampyre_king.take_damage(damage) self.assertTrue( TestVampyreKing._damage_inflicted_correctly( damage, lives_b4, hit_points_b4, vampyre_king))
from enemy import Enemy, Troll, Vampyre, VampyreKing #random_monster = Enemy("Basic enemy", 12, 1) #print(random_monster) #random_monster.take_damage(4) #print(random_monster) #random_monster.take_damage(8) #print(random_monster) #random_monster.take_damage(9) #print(random_monster) #ugly_troll = Troll() #print("Ugly troll - {}".format(ugly_troll)) # #another_troll = Troll("ug", 18, 1) #print("Another troll - {}".format(another_troll)) # #brother = Troll("Urg", 23) #print(brother) #brother.grunt() #brother.take_damage(5) vamp = Vampyre("Vlad") while vamp.alive: vamp.take_damage(1) # print(vamp) vampTheGreat = VampyreKing("Big Vlad") while vampTheGreat.alive: vampTheGreat.take_damage(8)
# troll2.take_damage(4) # print(troll2) print('------------------------') # Creating Vampyre instances vam1 = Vampyre('vam1') print(vam1) vam2 = Vampyre('vam2') print(vam2) vam1.take_damage(5) print(vam1) vam1.take_damage(8) print(vam1) vam3 = Vampyre('vam3') print(vam3) while vam3._alive: vam3.take_damage(1) print(vam3) print('---------Vampyre King---------') dracula = VampyreKing('Dracula') print(dracula) dracula.take_damage(12) print(dracula)
vamp.take_damage(4) print(vamp) another_vamp = Vampyre("Akash") print("another_vamp - {}".format(another_vamp)) another_vamp.take_damage(3) print("*" * 40) another_troll.take_damage(35) print(another_troll) vamp._live = 0 vamp._hit_points = 1 print(vamp) king = VampyreKing("Piyush") print("VampyreKing - {}".format(king)) king.take_damage(12) print(king) king.take_damage(15) print(king) king.take_damage(700) print(king) king.take_damage(15) print(king)
random_monster = Enemy("Basic enemy", 12, 1) print(random_monster) random_monster.take_damage(4) print(random_monster) ugly_troll = Troll("Pug") ugly_troll.take_damage(20) print("Ugly Troll - {}".format(ugly_troll)) another_troll = Troll("Ug") print("Another Troll - {}".format(another_troll)) brother_troll = Troll("Urg") print("Brother - {}".format(brother_troll)) ugly_troll.grunt() another_troll.grunt() brother_troll.grunt() vamp = Vampyre("Vlad") vamp.take_damage(7) print(vamp) king = VampyreKing("Dracula") while vamp._alive: vamp.take_damage(1) king.take_damage(10) print(king)
from enemy import Enemy, Troll, Vampyre, VampyreKing # dracula = VampyreKing("Something") print(dracula) dracula.take_damage(12) print(dracula) # ugly = Troll("Guys") # print(ugly) # # ugl = Troll("Maatokni") # print(ugl) # # uzi = Troll("Gun") # print(uzi) # # ump45 = Vampyre("SMG") # print(ump45) # # m416 = Vampyre("Assaulter") # print(m416) # # uzi.take_damage(8) # m416.take_damage(13) # print(m416) # # # while m416.alive: # # m416.take_damage(6) # # print(m416) # # # while m416.alive:
from player import Player #refer to the player class as "Player" #don't use getters and setters in Python since no objects are hidden! #getter: a method used to get the value of a class data attribute #setter: a method used to set the value of a class data attribute from enemy import Enemy, Troll, Vampyre, VampyreKing king = VampyreKing("King") print(king) king.take_damage(12) print(king) # 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() # test_vamp = Vampyre("Vamp") # print(test_vamp) # test_vamp.take_damage(2) # print(test_vamp)
from enemy import Enemy, Troll, Vampyre, VampyreKing # random_monster = Enemy("Basic_Enemy", 12, 1) # print(random_monster) # random_monster.take_damage(4) # print(random_monster) ugly_troll = Troll("pug") print("ugly troll : {0}".format(ugly_troll)) another_troll = Troll("Ug", 3) print("another_troll : {0}".format(another_troll)) brother = Troll("Urg") print(brother) ugly_troll.grunt() brother.grunt() vamp1 = Vampyre("vamp1") print(vamp1) print("*" * 40) while vamp1.alive: vamp1.take_damage(5) print(vamp1) vampK = VampyreKing('suresh') print(vampK) vampK.take_damage(10) print(vampK)
# print(brother) # brother.take_damage(3) # print(brother) # brother.take_damage(5) # print(brother) # ugly_troll.grunt() # another_troll.grunt() # brother.grunt() # vampyre_instance = Vampyre("FirstVampyre") # print(vampyre_instance) # vampyre_instance.take_damage(4) # print(vampyre_instance) # vampyre_instance.take_damage(6) # print(vampyre_instance) # while vampyre_instance.alive: # vampyre_instance.take_damage(1) # print(vampyre_instance) vamp = VampyreKing("VKing") print(vamp) vamp.take_damage(8) print(vamp)
from enemy import Troll, Vampyre, VampyreKing from player import Player a = 3 b = "tim" c = 1, 2, 3 print(a) print(b) print(c) p1 = Player("Peter") print(p1) t1 = Troll("To") t1.take_damage(5) print(t1) v1 = Vampyre("Vlad") print(v1) v1.take_damage(3) print(v1) v2 = VampyreKing("Dave") print(v2) v2.take_damage(16) print(v2)
vamp.take_damage(10) print(vamp) print("-" * 40) another_troll.take_damage(30) print(another_troll) vamp.take_damage(20) print(vamp) while vamp.alive: vamp.take_damage(4) print(vamp) # Vampyre King insert ###### print("-" * 40) dracula = VampyreKing("The Vlad") print(dracula) dracula.take_damage(22) print(dracula) ######################### # Testing for the player print() # tim = player.Player("Tim") tim = Player("Tim") print(tim.name) print("lives: ", tim.lives) tim.level -= 1 tim.level += 3
# troll_2 = Enemy("Bog", 10, 1) # print(troll_2) # # # using a subclasses methods # troll_1.grunt() # # # as troll 2 is not a Troll object it cannot use the sub classes methods # # troll_2.grunts() # # Dr_Acula = Vampyre("Dr. Acula") # print(Dr_Acula) # # # subclass using superclasses methods # troll_1.take_damage(10) # print(troll_1) # Dr_Acula.take_damage(13) # print(Dr_Acula) print("=" * 40) # while Dr_Acula.alive: # Dr_Acula.take_damage(1) # print(Dr_Acula) VampKing = VampyreKing("Vampyre King") print(VampKing) VampKing.take_damage(17) print(VampKing)
then below code will print the values for the enemy class. in any other language like C++ or Java we have to declare three constructors one for each case with different input parameters, but python doesn't have the concept of overloaded methods. """ # ugly_troll = Troll("Pug") # ugly_troll.take_damage(4) # ugly_troll.take_damage(9) # ugly_troll.take_damage(10) # ugly_troll.take_damage(11) # print("Ugly troll - {}".format(ugly_troll)) # # another_troll = Troll("Ug") # print("Another troll - {}".format(another_troll)) # # brother = Troll("Urg") # print("brother - {}".format(brother)) """ before extending the Vampire class """ # vampire1 = Vampire("Vampire") # vampire1.take_damage(5) # print(vampire1) # # while vampire1._alive: # vampire1.take_damage(1) # # print(vampire1) vampK = VampyreKing("Vlad") vampK.take_damage(8) print(vampK)
# print(another_troll) # another_troll.take_damage(18) # print (another_troll) # # brother = Troll("Urg") # print(ugly_troll) # print(brother) # # # # ugly_troll.grunt() # another_troll.grunt() # # vamp = Vampyre("Vam") # print(vamp) # vamp.take_damage(2) # vamp.dodges() # # print("__" *20) # another_troll.take_damage(30) # print(another_troll) # # while vamp._alive: # vamp.take_damage(1) print("--" * 20) dracula = VampyreKing("drac") print(dracula) dracula.take_damage(55) print(dracula)
# # another_troll = Troll("Ug") # print("Another troll - {}".format(another_troll)) # # brother = Troll("Urg") # print(brother) # # vlad = Vampyre("Vlad") # print(vlad) # # ugly_troll.grunt() # another_troll.grunt() # brother.grunt() # brother.take_damage(2) # # print("=" * 40) # another_troll.take_damage(30) # print(another_troll) # # # while vlad.alive: # # vlad.take_damage(1) # # print(vlad) # # vlad._lives = 0 # vlad._hit_points = 1 # print(vlad) dunitru = VampyreKing("Dunitru") while dunitru._alive: dunitru.take_damage(8)
# print("Ugly troll - {}".format(ugly_troll)) # # another_troll = Troll("Ug") # print(another_troll) # # brother_troll = Troll("Urg") # print(brother_troll) # # ugly_troll.grunt() # another_troll.grunt() # brother_troll.grunt() # ugly_troll.take_damage(22) # print(ugly_troll) # # ugly_troll.take_damage(5) # print(ugly_troll) # blood_vampyre = Vampyre("Vlad") # print(blood_vampyre) # # while blood_vampyre._alive: # blood_vampyre.take_damage(4) # print(blood_vampyre) king = VampyreKing("Dracul") print(king) king.take_damage(40) print(king)
""" short game to showcase basics of inheritance and composiition in object oriented python! choose actions as the hero to defeat trolls vampires, and even a vampire king! """ from enemy import Enemy, Troll, Vampyre, VampyreKing from Hero import Paladin, Wizard from encounter import Fight if __name__ == '__main__': Mr_Peanut = Paladin('Mr. Peanut, The Emancipator') Steve = Wizard('The Fantastic Steve') Blorgnar = Troll('Blorgnar') Glorbnar = Troll('Glorbnar') SirSuck = VampyreKing('Sir Suck') encounter = Fight(Mr_Peanut, Blorgnar) encounter.initative_order() encounter.fight() encounter2 = Fight(Steve, Glorbnar) encounter2.initative_order() encounter2.fight()
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)
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) print(oldVampyre) kingOfVampyres = VampyreKing('Vlad') print(kingOfVampyres) while kingOfVampyres.alive: kingOfVampyres.takeDamage(100) print(kingOfVampyres)
brother.grunt() dracula = Vampyre("Dracula") print(dracula) dracula.take_damage(4) print(dracula) print("-" * 40) another_troll.take_damage(30) print(another_troll) while dracula._alive: dracula.take_damage(1) #print(dracula) vlad = VampyreKing("Vlad") print(vlad) while vlad._alive: vlad.take_damage(4) # print(tim.name) # print(tim.lives) # tim.lives -= 1 # print(tim.lives) # print(tim) # tim._set_level(3) # print(tim)
# print(f"Another troll {another_troll}") # # brother = Troll('Urg') # print(brother) # # ugly_troll.grunt() # another_troll.grunt() # brother.grunt() # # blood = Vampyre("Blood") # print(blood) # # blood.take_damage(1) # print(blood) # # # while blood.alive: # # blood.take_damage(1) # # blood._lives = 0 # blood._hit_points = 1 # print(blood) dracula = VampyreKing("Dracula") print(dracula) dracula.take_damage(12) dracula.take_damage(12) dracula.take_damage(12) dracula.take_damage(12) dracula.take_damage(12) print(dracula)
another_troll = Troll("Ug") print("Another troll - {}".format(another_troll)) another_troll.take_damage(18) print(another_troll) brother_troll = Troll("Urg") print("Brother troll - {}".format(brother_troll)) ugly_troll.grunt() another_troll.grunt() brother_troll.grunt() vamp = Vampyre("Vlad") print(vamp) vamp.take_damage(5) print(vamp) print("-" * 40) another_troll.take_damage(30) print(another_troll) while vamp.alive: vamp.take_damage(1) # print(vamp) vamp_king = VampyreKing("Dracula") print(vamp_king) vamp_king.take_damage(8) print(vamp_king)
def test_vampyre_king_default_init(self): vampyre_king = VampyreKing('Vampire King') self.assertEqual(vampyre_king.hit_points, 140) self.assertEqual(vampyre_king.lives, 3)
from player import Player from enemy import Enemy, Troll, Vampyre, VampyreKing vking = VampyreKing("Vking") print(vking) vking.take_damage(12) print(vking) # # random_monster = Enemy("Basic Enemy",12,1) # # print(random_monster) # # # # random_monster.take_damage(8) # # print(random_monster) # # # ''' # pug = Troll("Pug") # print("pug - {} ".format(pug)) # # another_troll = Troll("Ug") # another_troll.take_damage(18) # print("Ug - {} ".format(another_troll)) # # bro = Troll("Urg") #brother = Enemy("Urg",23) -< This statment will also give the same result # print("bro - {} ".format(bro), end = " ") # print(bro) # # pug.grunt() ''' # # # vamp = Vampyre("Vlad") # # #print(vamp) # # #vamp.take_damage(3)