def reset_hero_attributes(hero: Hero): from items.weapon import Weapon from items.spell import Spell hero.health = hero.MAX_HEALTH hero.mana = hero.MAX_MANA hero.weapon = Weapon.create_weapon(random.choice(WEAPON_NAMES)) hero.spell = Spell.create_spell(random.choice(SPELL_NAMES))
def test_if_constructor_sets_attributes_correctly(self): s = Spell(name='Fireball', damage=20, mana_cost=5, cast_range=3) self.assertEqual(s.name, 'Fireball') self.assertEqual(s.damage, 20) self.assertEqual(s.mana_cost, 5) self.assertEqual(s.cast_range, 3)
def test_if_take_mana_returns_false_if_character_is_dead(self): a = Skeleton(health=20, mana=10) a.spell = Spell('Fireball', 5, 6, 1) a.reduce_mana() a.take_damage(300) self.assertFalse(a.take_mana(20))
def test_if_attack_with_spell_range_works_when_cast_range_is_0(self): health = 1 hero = Hero() hero.spell = Spell(cast_range=0) enemy = Enemy(health=health) attack_with_spell_range(hero, enemy) self.assertEqual(enemy.health, health)
def test_if_take_mana_restores_mana(self): a = Skeleton(health=20, mana=10) a.spell = Spell('Fireball', 5, 6, 1) a.reduce_mana() a.take_mana(3) self.assertEqual(a.mana, 7)
def create_hero(cls): # add except name = input('Hero name: ') title = input('Hero title: ') weapon = Weapon.create_weapon(random.choice(WEAPON_NAMES)) spell = Spell.create_spell(random.choice(SPELL_NAMES)) return cls(name=name, title=title, weapon=weapon, spell=spell)
def test_if_attack_with_spell_range_works_when_enemy_is_killed_during_the_attack(self): health = 1 hero = Hero() hero.spell = Spell(damage=1, cast_range=1) enemy = Enemy(health=health) exp = 0 attack_with_spell_range(hero, enemy) self.assertEqual(enemy.health, exp)
def test_if_create_spell_class_method_creates_a_Spell_instance(self): s = Spell.create_spell('Fireball') range_damage = range(1, 21) range_mana_cost = range(1, 11) range_cast_range = range(1, 4) self.assertEqual(Spell, type(s)) self.assertEqual(s.name, 'Fireball') self.assertTrue(s.damage in range_damage) self.assertTrue(s.mana_cost in range_mana_cost) self.assertTrue(s.cast_range in range_cast_range)
def __init__(self, health: int = 1, mana: int = 0): self.verify_health(health) self.health = health self.MAX_HEALTH = health self.verify_number_value(mana) self.mana = mana self.MAX_MANA = mana self.weapon = Weapon() self.spell = Spell()
def generate_random_value_of_treasure(treasure: str): from items.weapon import Weapon from items.spell import Spell dict_treasure_values = { 'health': random.randint(1, 20), 'mana': random.randint(1, 20), 'weapon': Weapon.create_weapon(random.choice(WEAPON_NAMES)), 'spell': Spell.create_spell(random.choice(SPELL_NAMES)) } treasure_value = dict_treasure_values[treasure] return treasure_value
def __init__(self, name: str = "Hero", title: str = "No title", health: int = 100, mana: int = 100, mana_regeneration_rate: int = 5, weapon: Weapon = Weapon(), spell: Spell = Spell()): super().__init__(health=health, mana=mana) self.verify_attributes(name, title, mana_regeneration_rate) self.name = name self.title = title self.mana_regeneration_rate = mana_regeneration_rate self.weapon = weapon self.spell = spell
def test_if_attack_by_spell_returns_spell_damage(self): h = Hero() h.spell = Spell('Fireball', 10, 5, 1) self.assertEqual(h.attack(), 10)
def test_if_attack_returns_weapon_damagae_if_it_is_stronger(self): h = Hero() h.spell = Spell('Fireball', 10, 5, 1) h.weapon = Weapon('Bat', 20) self.assertEqual(h.attack(), 20)