コード例 #1
0
ファイル: test_battle.py プロジェクト: dejanu/turnbased_game
    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")
コード例 #2
0
ファイル: test_battle.py プロジェクト: dejanu/turnbased_game
    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)
コード例 #3
0
ファイル: test_battle.py プロジェクト: dejanu/turnbased_game
    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)
コード例 #4
0
ファイル: test_hero.py プロジェクト: dejanu/turnbased_game
 def test_default_health(self):
     """ test init without args"""
     self.assertEqual(Hero("orderus").get_health(), 70)
コード例 #5
0
ファイル: test_hero.py プロジェクト: dejanu/turnbased_game
 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))
コード例 #6
0
ファイル: test_hero.py プロジェクト: dejanu/turnbased_game
 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))
コード例 #7
0
ファイル: test_hero.py プロジェクト: dejanu/turnbased_game
 def test_health_setter(self):
     """test health setter"""
     o = Hero("orderus")
     o.set_health(20)
     self.assertEqual(o.get_health(), 95)
コード例 #8
0
ファイル: Battleground.py プロジェクト: dejanu/turnbased_game
        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