Ejemplo n.º 1
0
    def test_troll_take_damage_1(self):
        troll = Troll(name='Org')
        troll.take_damage(10)
        self.assertEqual(troll.hit_points, 13)
        self.assertEqual(troll.lives, 1)

        troll.take_damage(13)
        self.assertEqual(troll.hit_points, 0)
        self.assertEqual(troll.lives, 0)

        troll.take_damage(5)
        self.assertEqual(troll.hit_points, 0)
        self.assertEqual(troll.lives, 0)
Ejemplo n.º 2
0
    john.level = 3
    print(john)

    tim.lives = -1
    tim.level = 0

    print("-" * 40)

    enemy = Enemy("Ogre")
    print(enemy)

    bigogre = Enemy("BigOgre", 25, 1)
    print(bigogre)
    bigogre.take_damage(10)

    troll = Troll("Ug")
    print(troll)
    print("troll taking damage 30 ")
    troll.take_damage(30)

    print("-" * 40)

    vamp = Vampire("dracula")
    print(vamp)
    print("dracula taking damage 15 ")
    vamp.take_damage(15)

    vamp2 = Vampire("dracula_2")
    print(vamp2)
    print("dracula_2 taking damage 55 ")
    vamp2.take_damage(55)
print(random_monster)

# ==========================================
# Now we call the subclass Troll
# ==========================================

# NOTE we imported Troll above

# We don't pass any parameters to ugly_troll hence it has default name "Enemy" Hit points = 0 and Lives = 1

print("=" * 40)
print("Calling Troll")
print()

print("=" * 20)
ugly_troll = Troll()
print("Ugly Troll = {}".format(ugly_troll))

# Now we create ugly_troll2 and pass it parameters
# this one prints the parameters we gave it. It overides the default parameters

print("=" * 20)
ugly_troll2 = Troll("Ugly_troll2", 18, 1)
print("Ugly Troll_2 = {}".format(ugly_troll2))

# We can also make another troll and pass it two parameters and it will take default live of 1

print("=" * 20)
ugly_troll3 = Troll("Ugly_troll3", 25)
print("Ugly Troll_2 = {}".format(ugly_troll3))
Ejemplo n.º 4
0
from player import Player
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")
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:
Ejemplo n.º 5
0
 def test_troll_default_init(self):
     troll = Troll(name='Ug')
     self.assertEqual(troll.name, 'Ug')
     self.assertEqual(troll.hit_points, 23)
     self.assertEqual(troll.lives, 1)
Ejemplo n.º 6
0
print(monster)
monster.take_damage(12)
print(monster)

monster.take_damage(8)
print(monster)

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")
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
"""
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()
Ejemplo n.º 9
0
from player import Player
from enemy import Enemy, Troll, Vampyre, VampyreKing

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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
from enemy import Enemy, Troll, Vampyre

ugly_troll = Troll("pug")
print("ugly_troll- {}".format(ugly_troll))

another_troll = Troll("ur")
print(another_troll)
another_troll.take_damage(18)
print(another_troll)

brother = Troll("urg")
print(brother)

ugly_troll.grunt()
another_troll.grunt()
brother.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)

Vamp._lives = 0
Vamp._hit_points = 1
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
from vampire import Vampire
from vampire_king import VampireKing

# player is how the file is named

tim = Player('Tim')
random_monster = Enemy('Basic Enemy', 12, 1)

"""
    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)
Ejemplo n.º 16
0
from enemy import Enemy, Troll

ugly_troll = Troll()
print("Ugly troll - {}".format(ugly_troll))

another_troll = Troll("Ug", 18, 1)
print("Another troll - {}".format(another_troll))

brother = Enemy("Urg", 23)
print(brother)
Ejemplo n.º 17
0
random_monster.take_damage(4)
print(random_monster)

random_monster.take_damage(8)
print(random_monster)

# this is the final hit the monster can take, on taking, it looses 1 life
random_monster.take_damage(1)
print(random_monster)

# 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)
Ejemplo n.º 18
0
from enemy import Enemy, Troll, Vampyre, VampyreKing

# random_monster = Enemy('Small', 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('Pug')
print('ugly troll - {}'.format(ugly_troll))

another_troll = Troll('Ug')
print('Another troll - {}'.format(another_troll))
another_troll.take_damage(18)

brother = Troll('Urg')
print(brother)

ugly_troll.grunt()
another_troll.grunt()
brother.grunt()

vamp = Vampyre("Vlad")
print(vamp)
Ejemplo n.º 19
0
# random_monster = Enemy("Basic Enemy", 12, 1)
# print(random_monster)
#
# random_monster.take_damage(4)
# print(random_monster)
#
# random_monster.take_damage(4)
# print(random_monster)

# troll = Troll("Pug")
# print("Ugly troll - {}",format(troll))
#
# another_troll = Troll("Ug")
# print("Another troll - {}".format(another_troll), end="\n\n")
#
brother = Troll("Urg")
print(brother)

a = 5

# another_troll.grunt()

# dracula = Vampyre("Dracula")
# print(dracula)
# dracula.take_damage(10)
#
# print(dracula)
#
# dracula.take_damage(4)
# print(dracula.points_revive)
# print(dracula)
Ejemplo n.º 20
0
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 = Troll("Urg")
print("Brother troll - {}".format(brother_troll))

basic_vampire = Vampire("Vlad")
print("Vlad - {}".format(basic_vampire))

ugly_troll.grunt()
another_troll.grunt()
brother_troll.grunt()

print("-" * 40)

while basic_vampire.alive:
    basic_vampire.take_damage(6)
    print(basic_vampire)

print("-" * 40)

dracula = VampireKing("Dracula")
print(dracula)
dracula.take_damage(12)
print(dracula)
Ejemplo n.º 21
0
from player import Player
from enemy import Enemy, Troll

phil = Player("Phil")

random_monster = Enemy("basic enemy", 12, 1)
print(random_monster)

random_monster.take_damage(4)
print(random_monster)

# doing this a new troll object is created with its name being blargh, and it will
# have the lives and hit points from the enemy class because the super class
# init is being called from the subclass
ugly_troll = Troll("blargh")
print("ugly troll - {}".format(ugly_troll))

ugly_troll.grunt()
Ejemplo n.º 22
0
from player import Player

tim = Player("Tim")

from enemy import Enemy, Troll, Vampire
#
# random_monster = Enemy("Basic enemy", 12, 1)
# print(random_monster)
#
# 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)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
from enemy import Enemy, Troll, vampire

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("pug")
print("Ugly troll -{}".format(ugly_troll))

another_troll = Troll("UG")
print("Ugly troll -{}".format(another_troll))
another_troll.take_damage(18)
print(another_troll)

ugly_troll.grunt()
another_troll.grunt()
ugly_troll.grunt()

vamp = vampire("vall")
print(vamp)
vamp.take_damage(5)
print(vamp)
Ejemplo n.º 26
0
#
# brother = Troll("Urg", 23)
# print("Urg's Brother : \n{}".format(brother))
# # O/P:
# # 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: