コード例 #1
0
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))
コード例 #2
0
    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)
コード例 #3
0
    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))
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
    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)
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    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()
コード例 #10
0
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
コード例 #11
0
    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
コード例 #12
0
    def test_if_attack_by_spell_returns_spell_damage(self):
        h = Hero()
        h.spell = Spell('Fireball', 10, 5, 1)

        self.assertEqual(h.attack(), 10)
コード例 #13
0
    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)