Beispiel #1
0
    def test_check_winner_creature(self):
        """ test if the correct obj is declared winner"""
        
        h,c = Hero("foo"),Creature("bar")
        b = Battle(h,c)

        # mock
        h.charge_attack = True
        c.charge_attack = False

        self.assertEqual(b.check_winner(),"Creature")
Beispiel #2
0
    def test_check_winner_exception(self):
        """ test if the exception is raised"""

        h,c = Hero("foo"),Creature("bar")
        b = Battle(h,c)

        # mock
        h.charge_attack = False
        c.charge_attack = False

        self.assertRaises(ValueError,b.check_winner)
Beispiel #3
0
    def test_max_turns(self):
        """ test if the calls fucntion attr increments corecttly"""
        
        b = Battle(Hero("foo"),Creature("bar"))
        for i in range(20):
            b.fight()

        self.assertEqual(b.fight.calls, 20)
Beispiel #4
0
 def test_default_health(self):
     """ test init without args"""
     self.assertEqual(Hero("orderus").get_health(), 70)
Beispiel #5
0
 def test_hero_magic_shield(self):
     """ test if Hero class implements magic_shield method"""
     o = Hero("orderus")
     self.assertTrue(
         hasattr(o, 'magic_shield') and callable(o.magic_shield))
Beispiel #6
0
 def test_hero_rapidstrike(self):
     """ test if Hero class implements rapidstrike method"""
     o = Hero("orderus")
     self.assertTrue(
         hasattr(o, 'rapid_strike') and callable(o.rapid_strike))
Beispiel #7
0
 def test_health_setter(self):
     """test health setter"""
     o = Hero("orderus")
     o.set_health(20)
     self.assertEqual(o.get_health(), 95)
Beispiel #8
0
        if self.hero.charge_attack == True and self.creature.charge_attack == False:
            print("Creature {0} has won".format(self.creature.name))
            return "Creature"
        elif self.hero.charge_attack == False and self.creature.charge_attack == True:
            print("Hero {0} has won".format(self.hero.name))
            return "Hero"
        else:
            raise ValueError


if __name__ == "__main__":

    # create players
    hero = Hero("Orderus",
                health=randint(70, 100),
                strength=randint(70, 80),
                defence=randint(45, 55),
                speed=randint(40, 50),
                luck=randint(10, 30))
    creature = Creature("Beast",
                        health=randint(60, 90),
                        strength=randint(60, 90),
                        defence=randint(40, 60),
                        speed=randint(40, 60),
                        luck=randint(25, 40))

    print("Battle is starting.....\n")
    first_round = Battle(hero, creature)

    # check who attacks first
    first_round > first_round