Exemplo n.º 1
0
    def test_attack_method_when_by_spell_when_no_spell(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        result = h.attack(by='spell')

        self.assertEqual(result, 0)
    def test_known_as_representation_works_correctly(self):
        h = Hero(name='Bron',
                 title='Dragonslayer',
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        result = h.known_as()

        self.assertEqual(result, 'Bron the Dragonslayer')
Exemplo n.º 3
0
    def test_equip_hero_weapon_must_be_weapon(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        weapon = Weapon(name='Axe', damage=20)
        h.equip(weapon)

        self.assertEqual(h.weapon, weapon)
    def test_move_hero_right_should_return_true_if_can_move_or_false_if_not(
            self):
        map_ = Dungeon('level1.txt')
        h = Hero('hero', 'the hero', 100, 100, 2)
        map_.spawn(h)
        h.take_mana(-10)

        result = map_.move_hero('right')

        self.assertEqual(result, True)
        self.assertEqual(h.get_mana(), 92)
Exemplo n.º 5
0
    def test_learn_spell_hero_spell_must_be_the_spell(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        spell = Spell(name='Fireball', damage=20, mana_cost=20, cast_range=2)
        h.learn(spell)

        self.assertEqual(h.spell, spell)
Exemplo n.º 6
0
    def test_take_healing_when_hero_is_not_alive_should_return_false(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        h.health = 0
        result = h.take_healing(100)

        self.assertEqual(result, False)
Exemplo n.º 7
0
    def test_attack_method_when_by_spell_when_has_spell(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)
        spell = Spell(name='Fireball', damage=20, mana_cost=20, cast_range=2)
        h.learn(spell)

        result = h.attack(by='spell')

        self.assertEqual(result, 20)
Exemplo n.º 8
0
    def test_attack_method_when_by_weapon_when_has_weapon(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)
        weapon = Weapon(name='Axe', damage=20)
        h.equip(weapon)

        result = h.attack(by='weapon')

        self.assertEqual(result, 20)
Exemplo n.º 9
0
    def test_can_cast_function_should_return_true_if_object_can_cast(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)
        s = Spell(name='Fireball', damage=20, mana_cost=20, cast_range=2)

        h.learn(s)

        result = Mixin.can_cast(h)

        self.assertTrue(result)
Exemplo n.º 10
0
    def test_take_healing_when_hero_is_alive_and_healing_is_less_than_max_health_should_return_True_and_hero_health_is_changed(
            self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        h.health = 10
        result = h.take_healing(50)

        self.assertEqual(result, True)
        self.assertEqual(h.health, 60)
Exemplo n.º 11
0
    def test_take_mana_when_hero_is_alive_and_mana_is_more_than_max_should_return_true_and_make_mana_max(
            self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        h.mana = 0
        result = h.take_mana(120)

        self.assertEqual(result, True)
        self.assertEqual(h.mana, 100)
Exemplo n.º 12
0
    def test_take_healing_when_hero_is_alive_and_healing_is_greater_than_max_should_return_True_and_health_must_be_max(
            self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        h.health = 10
        result = h.take_healing(100)

        self.assertEqual(result, True)
        self.assertEqual(h.health, 100)
Exemplo n.º 13
0
    def test_hero_attack_by_spell_returns_false_if_no_fight(self):
        hero = Hero(name="Bron",
                    title="Dragonslayer",
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        map = Dungeon('level1.txt')
        map.spawn(hero)
        spell = Spell('fireball', 20, 20, 2)
        hero.spell = spell

        result = map.hero_attack(by='spell')

        self.assertEqual(result, False)
Exemplo n.º 14
0
    def test_init_should_raise_type_error_if_hero_or_enemy_not_of_their_type(
            self):
        map_ = Dungeon('level1.txt')
        hero = Hero(name="Bron",
                    title="Dragonslayer",
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        enemy = "enemy"

        exc = None
        try:
            Fight(hero, enemy, level_map=map_.level_map)
        except Exception as e:
            exc = e

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Invalid type.')

        hero = "hero"
        enemy = Enemy(health=100, mana=20, damage=20)

        exc = None
        try:
            Fight(hero, enemy, level_map=map_.level_map)
        except Exception as e:
            exc = e

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Invalid type.')
Exemplo n.º 15
0
    def test_is_alive_function_returns_true_if_get_health_is_not_zero(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        result = Mixin.is_alive(h)

        self.assertTrue(result)
Exemplo n.º 16
0
    def test_get_mana_should_return_current_mana(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        mana = Mixin.get_mana(h)

        self.assertEqual(mana, 100)
Exemplo n.º 17
0
    def test_pick_treasure_should_return_random_weapon_or_spell(self):
        map = Dungeon('level1.txt')
        hero = Hero(name='Bron',
                    title='Dragonslayer',
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        map.spawn(hero)
        treasure = map.pick_treasure()

        self.assertIn(type(treasure), [Weapon, Spell, str])
Exemplo n.º 18
0
    def test_hero_attack_by_spell_returns_true_if_fight_starts(self):
        hero = Hero(name="Bron",
                    title="Dragonslayer",
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        map_ = Dungeon('level1.txt')
        map_.spawn(hero)
        weapon = Weapon('Axe', damage=20)
        hero.equip(weapon)
        spell = Spell('fireball', 20, 20, 2)
        hero.spell = spell
        map_.move_hero('right')
        map_.move_hero('down')
        map_.move_hero('down')
        map_.move_hero('down')

        result = map_.hero_attack(by='spell')

        self.assertEqual(result, True)
Exemplo n.º 19
0
    def test_get_health_function_should_return_current_health(self):

        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        result = Mixin.get_health(h)

        self.assertEqual(result, 100)
Exemplo n.º 20
0
    def test_if_spawn_function_populates_first_spawning_point_correctly(self):
        level_map = Dungeon('level1.txt')

        h = Hero(name='Bron',
                 title='Dragonslayer',
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        result = level_map.spawn(h)

        self.assertTrue(result)
Exemplo n.º 21
0
    def test_instantiating_hero_with_wrong_type_name_should_raise_error(self):

        exc = None

        try:
            Hero(name=123,
                 title='Dragonslayer',
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Name should be string')
Exemplo n.º 22
0
    def test_instantiating_hero_with_wrong_type_mana_should_raise_error(self):

        exc = None

        try:
            Hero(name='Bron',
                 title='Dragonslayer',
                 health=100,
                 mana='asd',
                 mana_regeneration_rate=2)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Mana should be positive integer')
Exemplo n.º 23
0
    def test_take_damage_should_reduce_health_with_damage_points(self):
        h = Hero(name="Bron",
                 title="Dragonslayer",
                 health=100,
                 mana=100,
                 mana_regeneration_rate=2)

        reduced_health = Mixin.take_damage(h, 65)

        self.assertEqual(reduced_health, 35)

        reduced_health2 = Mixin.take_damage(h, 50)

        self.assertEqual(reduced_health2, 0)

        health = Mixin.get_health(h)

        self.assertEqual(health, 0)
Exemplo n.º 24
0
    def test_init_fight_should_save_hero_and_enemy(self):
        map_ = Dungeon('level1.txt')
        hero = Hero(name="Bron",
                    title="Dragonslayer",
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        weapon = Weapon('Axe', 20)
        spell = Spell('Fireball', 20, 50, 2)
        hero.equip(weapon)
        hero.learn(spell)
        enemy = Enemy(health=100, mana=20, damage=20)

        fight = Fight(hero, enemy, level_map=map_.level_map)

        self.assertEqual((hero, enemy), (fight.hero, fight.enemy))
Exemplo n.º 25
0
    def move_hero(self, direction):
        if my_hero.is_alive():
            my_hero.mana_regeneration_rate += 2
            if my_hero.mana_regeneration_rate > 100:
                my_hero.mana_regeneration_rate = 100

        pass



map = Dungeon.create_from_file("level1.txt")
# map.print_map()
# print(map.map)
# map.spawn(1)
# map.print_map()
# map.hero_location()

my_hero = Hero()
# print(my_hero.known_as())
# print(my_hero.is_alive())
my_hero.take_damage(99)
print(my_hero.is_alive())
# my_hero.take_damage(99)
print(my_hero.is_alive())
print(my_hero.health)
my_hero.take_healing(40)
print(my_hero.health)
my_hero.take_healing(400)
print(my_hero.mana_regeneration_rate)
map.move_hero('dd')
print(my_hero.mana_regeneration_rate)