Exemple #1
0
    def test_can_cast_when_human_has_spell_but_no_mana_to_cast_then_return_false(
            self):
        human = Human(50, 50)
        spell = Spell('abrakadarba', 20, 70, 2)
        spell.equip_to(human)

        self.assertFalse(human.can_cast())
Exemple #2
0
    def test_can_cast_when_human_has_spell_and_enough_mana_then_return_true(
            self):
        human = Human(50, 50)
        spell = Spell('abrakadarba', 20, 30, 2)
        spell.equip_to(human)

        self.assertTrue(human.can_cast())
Exemple #3
0
    def test_when_enemy_fists_are_weaker_than_spell_then_return_spell(self):
        enemy = Enemy(150, 50, 50)
        spell = Spell(name="Fireball", damage=150, mana_cost=50, cast_range=2)

        spell.equip_to(enemy)

        self.assertEqual(enemy.attack(), spell)
        self.assertEqual(getattr(enemy, 'mana'), 0)
    def test_when_hero_wants_to_attack_with_magic_and_has_it_but_has_no_mana_then_return_none(
            self):
        hero = Hero(name="Bron",
                    title="Dragonslayer",
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        spell = Spell(name="Fireball", damage=30, mana_cost=150, cast_range=2)

        spell.equip_to(hero)

        self.assertEqual(hero.attack(by='magic'), None)
Exemple #5
0
    def test_when_weapon_is_equal_to_spell_then_return_weapon(self):
        human = Human(100, 100)
        weapon = Weapon(name='The Axe of Destiny', damage=20)
        weapon.equip_to(human)

        spell = Spell(name='The Fireball of Destiny',
                      damage=20,
                      mana_cost=10,
                      cast_range=2)
        spell.equip_to(human)

        self.assertEqual(human.get_strongest_mean(), weapon)
    def test_when_hero_wants_to_attack_with_magic_and_has_and_can_cast_spell_then_return_spell(
            self):
        hero = Hero(name="Bron",
                    title="Dragonslayer",
                    health=100,
                    mana=100,
                    mana_regeneration_rate=2)
        spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)

        spell.equip_to(hero)

        self.assertEqual(hero.attack(by='magic'), spell)
        self.assertEqual(getattr(hero, 'mana'), 50)
Exemple #7
0
    def test_when_human_has_no_equipable_item_then_equip_new_item(self):
        human = Human(100, 100)

        weapon = Weapon(name='The Axe of Destiny', damage=20)
        spell = Spell(name='Abrakadarba',
                      damage=20,
                      mana_cost=30,
                      cast_range=2)
        armor = Armor(name='The protector', armor_points=5)

        weapon.equip_to(human)
        spell.equip_to(human)
        armor.equip_to(human)

        self.assertEqual(getattr(human, 'weapon'), weapon)
        self.assertEqual(getattr(human, 'spell'), spell)
        self.assertEqual(getattr(human, 'armor'), armor)
    def test_treasures_init(self):
        test_filename = 'level1.txt'
        dungeon = Dungeon(test_filename)
        expected_result = [
            Potion('mana', 40),
            Weapon('sword', 20),
            Armor('vest', 40),
            Spell('Fireball', 40, 20, 6)
        ]

        self.assertEqual(getattr(dungeon, 'treasures'), expected_result)
Exemple #9
0
def demo():
    h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2)

    w = Weapon(name="The Axe of Destiny", damage=20)
    h.equip(w)

    s = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)
    h.equip(s)

    map = Dungeon("level1.txt")
    map.spawn(h)

    map.move_hero("right")

    map.move_hero("down")

    map.hero_attack(by="magic")

    map.move_hero("down")
    map.move_hero("down")

    map.move_hero("right")

    map.move_hero("right")
    map.move_hero("right")
    map.move_hero("right")
    map.move_hero("up")
    map.move_hero("up")
    map.move_hero("up")
    map.move_hero("right")
    map.move_hero("right")
    map.move_hero("right")
    map.move_hero("right")
    map.move_hero("down")
    map.move_hero("down")
    map.move_hero("down")
    map.move_hero("down")
left = 'left'
spell = 'spell'
weapon = 'weapon'
enemy_name = 'Enemy'
health_potion = 'health potion'
mana_potion = 'mana potion'
available_directions = [right, up, down, left]
directions = {'u': up, 'r': right, 'l': left, 'd': down}

weapon_one = Weapon('Widowmaker', 40)
weapon_two = Weapon('Blade of the Reaper', 50)
weapon_three = Weapon('Poisonous daggers', 30)
weapon_four = Weapon('Moonlight Idol', 25)
weapon_five = Weapon('Netherbane, Might of the Void', 55)

spell_one = Spell('Frostbolt', 30, 30, 1)
spell_two = Spell('Fireball', 40, 40, 2)
spell_three = Spell('Arcane Missiles', 10, 10, 1)
spell_four = Spell('Flamestrike', 50, 50, 3)
spell_five = Spell('Deadly shot', 35, 20, 2)

dict_of_treasures = {
    weapon: weapon_one,
    weapon: weapon_two,
    weapon: weapon_three,
    weapon: weapon_four,
    weapon: weapon_five,
    spell: spell_one,
    spell: spell_two,
    spell: spell_three,
    spell: spell_four,
Exemple #11
0
	def test_when_mana_cost_is_negative_number_then_raise_error(self):
		with self.assertRaisesRegex(AssertionError, 'Mana cost can`t be a negative number.'):
			spell = Spell('Fireball', 30, -5, 6)
Exemple #12
0
	def test_when_damage_is_negative_number_then_raise_error(self):
		with self.assertRaisesRegex(AssertionError, 'Damage dealt can`t be a negative number.'):
			spell = Spell('Fireball', -30, 5, 6)
Exemple #13
0
	def test_when_cast_range_is_negative_number_then_raise_errors(self):
		with self.assertRaisesRegex(AssertionError, 'Cast range can`t be a negative number.'):
			spell = Spell('Fireball', 30, 5, -6)