def test_when_hero_wants_to_attack_with_weapon_and_has_it_then_return_weapon( self): hero = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) weapon = Weapon(name="The Axe of Destiny", damage=20) weapon.equip_to(hero) self.assertEqual(hero.attack(by='weapon'), weapon)
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_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_when_human_has_equipable_item_and_new_item_is_stronger_then_equip_new_item( self): human = Human(100, 100) weapon = Weapon(name='The Axe of Destiny', damage=20) weapon.equip_to(human) weapon2 = Weapon(name='The Axe of Destiny', damage=30) weapon2.equip_to(human) self.assertEqual(getattr(human, 'weapon'), weapon2)
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)
def test_when_hero_attacks_and_enemy_has_no_armor(self): dungeon = Dungeon('level1.txt') hero = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) hero.equip(Weapon('Axe', 20)) enemy = Enemy(50, 50, 20) expected_damage_taken = 20 result_damage_taken = dungeon.attack(hero, enemy)[0] self.assertEqual(result_damage_taken, expected_damage_taken)
def test_when_hero_has_same_attack_points_as_enemy_armor_points(self): dungeon = Dungeon('level1.txt') hero = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) dungeon.spawn(hero) hero.equip(Weapon('Axe', 20)) hero.equip(Armor('Shield', 20)) enemy = Enemy(50, 50, 20) enemy.equip(Armor('Vest', 20)) result = dungeon._fight(enemy) self.assertTrue('Hero got tired and let his guard down.' in result)
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")
from dungeons_and_pythons.models import Weapon from dungeons_and_pythons.models import Spell right = 'right' up = 'up' down = '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,
def test_when_enemy_fists_are_weaker_than_weapon_then_return_weapon(self): enemy = Enemy(150, 50, 50) weapon = Weapon('Axe', 100) weapon.equip_to(enemy) self.assertEqual(enemy.attack(), weapon)
def test_when_enemy_fists_are_stronger_than_weapons_then_return_fists(self): enemy = Enemy(150, 50, 50) weapon = Weapon('Axe', 10) weapon.equip_to(enemy) self.assertEqual(enemy.attack(), Weapon('Fists', 50))
def test_when_enemy_has_no_weapons_or_spells_then_return_fists(self): test_obj = Enemy(150, 50, 20) self.assertEqual(test_obj.attack(), Weapon('Fists', 20))