Exemplo n.º 1
0
    def test_defeat(self):
        mage = heroes.Mage()
        dragon = monsters.RedDragon(level=99)
        participants = [mage, dragon]

        battle = Battle(participants)

        with self.assertRaises(Defeat):
            battle.start()
Exemplo n.º 2
0
 def test_participants(self):
     participants = [
         heroes.Warrior(),
         heroes.Mage(),
         monsters.Orc(),
         monsters.GreenDragon()
     ]
     battle = Battle(participants)
     for unit in participants:
         self.assertIn(unit, battle.participants)
Exemplo n.º 3
0
 def test_first_attacker(self):
     participants = [
         heroes.Warrior(),
         heroes.Mage(),
         monsters.Orc(),
         monsters.GreenDragon()
     ]
     battle = Battle(participants)
     self.assertTrue(
         isinstance(battle.current_attacker(), monsters.GreenDragon))
Exemplo n.º 4
0
    def test_defeat(self):
        mage = heroes.Mage()
        dragon = monsters.RedDragon(level=99)
        participants = [mage, dragon]

        battle = Battle(participants)

        with self.assertRaises(Defeat):
            output = []
            while not battle.is_hero_turn():
                battle.next_turn()
            else:
                battle.next_turn()
Exemplo n.º 5
0
 def test_mage_levelling(self):
     self.hero = heroes.Mage(level=4)
     self.assertEqual(self.hero.level, 4)
     expected_stats = {'str': 7,
                       'con': 7,
                       'int': 21,
                       'spd': 9,
                       'maxhp': 110,
                       'maxmp': 78}
     actual_stats = {'str': self.hero.strength,
                     'con': self.hero.constitution,
                     'int': self.hero.intelligence,
                     'spd': self.hero.speed,
                     'maxhp': self.hero.maxhp,
                     'maxmp': self.hero.maxmp}
     self.assertEqual(actual_stats, expected_stats)
     self.assertEqual(self.hero.hp, self.hero.maxhp)
     self.assertEqual(self.hero.mp, self.hero.maxmp)
Exemplo n.º 6
0
    def test_one_round_of_combat(self):
        warr = heroes.Warrior()
        mage = heroes.Mage()
        orc = monsters.Orc()
        dragon = monsters.GreenDragon()
        participants = [warr, mage, orc, dragon]
        battle = Battle(participants)

        expected_output = [('GreenDragon hits', 'with poison breath for',
                            'damage!'),
                           ('Orc hits', 'with blood rage for', 'damage!'),
                           ('Orc takes', 'self-inflicted damage!'),
                           ("Mage's turn!", )]
        output = []
        while not battle.is_hero_turn():
            output.extend(battle.next_turn())
        else:
            output.extend(battle.next_turn())

        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)

        expected_output = [('Mage hits Orc with fireball for', 'damage!'),
                           ("Warrior's turn!", )]
        output = battle.execute_command('fireball', orc)

        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)

        expected_output = [
            ('Warrior hits Orc with shield slam for', 'damage!'),
            ('Orc dies!', ), ('XP rewarded!', ), ('is now level 2!', ),
            ('is now level 2!', ),
            ('GreenDragon hits', 'with tail swipe for', 'damage!'),
            ("Mage's turn!")
        ]
        output = battle.execute_command('shield_slam', orc)

        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)
Exemplo n.º 7
0
 def setUp(self):
     self.hero = heroes.Mage()
     self.dummy = TargetDummy()