Ejemplo n.º 1
0
    def test_with_given_hero_should_equip_with_default_weapon(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)

        result_equipped_hero = equip_hero_with_default_weapon(hero)
        result_equipped_weapon = result_equipped_hero.result_equipped_weapon
        expected_weapon = Weapon(name=DEFAULT_WEAPON_NAME,
                                 damage=DEFAULT_WEAPON_DAMAGE)

        self.assertEqual(expected_weapon, result_equipped_weapon)
Ejemplo n.º 2
0
    def test_when_hero_can_attack_should_set_correct_information_part_and_enemy_takes_damage_from_attack(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)
        default_weapon = Weapon(name=DEFAULT_WEAPON_NAME, damage=DEFAULT_WEAPON_DAMAGE)
        hero.equip(default_weapon)
        enemy = Enemy()
        initial_enemy_as_string = str(enemy)
        enemy_health_before_attack = enemy.health
        fight = Fight(hero, enemy)

        fight.hero_attack()

        result_enemy_health = fight.enemy.health
        expected_enemy_health = enemy_health_before_attack - default_weapon.damage
        result_information_parts = fight.information_parts
        expected_information_parts = [FIGHT_INITIAL_INFORMATION_PART + initial_enemy_as_string,
                                      FIGHT_HERO_ATTACK_INFORMATION_PART + str(default_weapon.damage)]

        self.assertEqual(expected_enemy_health, result_enemy_health)
        self.assertEqual(expected_information_parts, result_information_parts)
Ejemplo n.º 3
0
def create_hero():
    name, title = read_input_name_and_title_for_hero()
    hero = Hero(
        name=name,
        title=title,
        health=HERO_HEALTH_WHEN_INITIALISING,
        mana=HERO_MANA_WHEN_INITIALISING,
        mana_regeneration_rate=HERO_MANA_REGENERATION_RATE_WHEN_INITIALISING)
    hero = equip_hero_with_default_weapon(hero)
    wait_for_continue_command()
    return hero
Ejemplo n.º 4
0
    def test_with_hero_that_can_not_attack_should_stop_when_hero_is_dead(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)
        enemy = Enemy()
        enemy.damage = hero.health
        fight = Fight(hero, enemy)

        fight.execute()

        result_hero_alive_status = hero.is_alive()
        expected_hero_alive_status = False
        result_enemy_alive_status = enemy.is_alive()
        expected_enemy_alive_status = True
        result_information_parts = fight.information_parts
        expected_information_parts = [FIGHT_INITIAL_INFORMATION_PART + str(enemy),
                                      FIGHT_HERO_CANNOT_ATTACK_INFORMATION_PART,
                                      FIGHT_ENEMY_ATTACK_INFORMATION_PART + str(enemy.damage)]

        self.assertEqual(expected_hero_alive_status, result_hero_alive_status)
        self.assertEqual(expected_enemy_alive_status, result_enemy_alive_status)
        self.assertEqual(expected_information_parts, result_information_parts)
Ejemplo n.º 5
0
    def test_with_given_hero_should_return_correctly(self):
        name = 'Bron'
        title = 'Dragonslayer'
        health = 100
        mana = 100
        mana_regeneration_rate = 2
        h = Hero(name, title, health, mana, mana_regeneration_rate)

        result = h.known_as
        expected = name + ' the ' + title

        self.assertEqual(expected, result)
Ejemplo n.º 6
0
    def test_with_hero_that_can_attack_and_enemy_that_can_not_should_stop_when_enemy_is_dead(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)
        enemy = Enemy()
        weapon = Weapon(name=DEFAULT_WEAPON_NAME, damage=enemy.health)
        hero.equip(weapon)
        fight = Fight(hero, enemy)
        initial_enemy_as_string = str(enemy)

        fight.execute()

        result_hero_alive_status = hero.is_alive()
        expected_hero_alive_status = True
        result_enemy_alive_status = enemy.is_alive()
        expected_enemy_alive_status = False
        result_information_parts = fight.information_parts
        expected_information_parts = [FIGHT_INITIAL_INFORMATION_PART + initial_enemy_as_string,
                                      FIGHT_HERO_ATTACK_INFORMATION_PART + str(weapon.damage)]

        self.assertEqual(expected_hero_alive_status, result_hero_alive_status)
        self.assertEqual(expected_enemy_alive_status, result_enemy_alive_status)
        self.assertEqual(expected_information_parts, result_information_parts)
Ejemplo n.º 7
0
    def test_when_hero_can_not_attack_should_set_correct_information_part_and_enemy_takes_zero_damage(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)
        enemy = Enemy()
        enemy_health_before_attack = enemy.health
        fight = Fight(hero, enemy)

        fight.hero_attack()

        result_information_parts = fight.information_parts
        expected_information_parts = [FIGHT_INITIAL_INFORMATION_PART + str(enemy),
                                      FIGHT_HERO_CANNOT_ATTACK_INFORMATION_PART]

        self.assertEqual(enemy_health_before_attack, enemy.health)
        self.assertEqual(expected_information_parts, result_information_parts)
Ejemplo n.º 8
0
    def test_with_given_correct_arguments_should_initialise_hero(self):
        name = 'Bron'
        title = 'Dragonslayer'
        health = 100
        mana = 100
        mana_regeneration_rate = 2

        h = Hero(name, title, health, mana, mana_regeneration_rate)

        self.assertEqual(Hero, type(h))
        self.assertEqual(name, h.name)
        self.assertEqual(title, h.title)
        self.assertEqual(health, h.health)
        self.assertEqual(mana, h.mana)
        self.assertEqual(mana_regeneration_rate, h.mana_regeneration_rate)
Ejemplo n.º 9
0
    def test_when_enemy_can_attack_should_set_correct_information_part_and_hero_takes_damage_from_attack(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)
        enemy = Enemy()
        fight = Fight(hero, enemy)
        hero_health_before_attack = hero.health

        fight.enemy_attack()

        result_hero_health = fight.hero.health
        expected_hero_health = hero_health_before_attack - enemy.damage
        result_information_parts = fight.information_parts
        expected_information_parts = [FIGHT_INITIAL_INFORMATION_PART + str(enemy),
                                      FIGHT_ENEMY_ATTACK_INFORMATION_PART + str(enemy.damage)]

        self.assertEqual(expected_hero_health, result_hero_health)
        self.assertEqual(expected_information_parts, result_information_parts)
Ejemplo n.º 10
0
    def test_with_given_correct_arguments_should_initialise_correctly(self):
        hero = Hero('hero', 'bravest', 100, 100, 2)
        enemy = Enemy()

        fight = Fight(hero, enemy)

        expected_hero = hero
        expected_enemy = enemy
        expected_distance = 0
        expected_direction = 0
        expected_information_parts = [FIGHT_INITIAL_INFORMATION_PART + str(enemy)]

        self.assertEqual(expected_hero, fight.hero)
        self.assertEqual(expected_enemy, fight.enemy)
        self.assertEqual(expected_distance, fight.distance)
        self.assertEqual(expected_direction, fight.direction)
        self.assertEqual(expected_information_parts, fight.information_parts)