コード例 #1
0
ファイル: test_units.py プロジェクト: creazero/python_rpg
    def test_handling_weapon_level(self):
        """
        Testing handling of weapons
        """
        self.player.hit_points = 100
        self.player.add_item_to_backpack(
            database.get_item_from_db("Test spear"))
        self.player.use_item("Test spear")

        enemies = [Human(["Name", 20, 0, 2, 1, 50, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 0, 2, 1, 50, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 0, 2, 1, 50, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 0, 2, 1, 50, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 0, 2, 1, 50, 50, None, None, None, None,
                          None, None, None, None, None]),
                  ]

        for enemy in enemies:
            fight(self.player, enemy)
            self.assertEqual(enemy.hit_points, 0)
            self.assertEqual(enemy.given_damage, 0)

        self.assertEqual(self.player.spear_level, 2)
        self.assertEqual(int(self.player.damage
                             - self.player.weapon_type_damage(
                                 self.player.right_hand)), 6)
コード例 #2
0
ファイル: test_units.py プロジェクト: creazero/python_rpg
    def test_player_dying(self):
        """
        Testing death of main hero
        """
        enemy = Human(["Name", 20, 40, 2, 1, 50, 50, None, None, None, None,
                       None, None, None, None, None])

        self.assertIsNotNone(enemy)

        with self.assertRaises(DeadHero):
            fight(self.player, enemy)

        self.assertEqual(self.player.hit_points, 0)
        self.assertGreaterEqual(enemy.given_damage, self.player.hit_points)
        self.assertFalse(self.player.is_alive())
コード例 #3
0
ファイル: test_units.py プロジェクト: creazero/python_rpg
    def test_fight(self):
        """
        Testing fight between two units
        """
        enemy = Human(["Name", 20, 5, 2, 1, 50, 50, None, None, None, None,
                       None, None, None, None, None])
        self.assertIsNotNone(enemy)

        fight(self.player, enemy)

        self.assertLessEqual(enemy.hit_points, 0)
        self.assertLessEqual(self.player.hit_points,
                             self.player.max_hit_points)
        self.assertEqual(self.player.experience, enemy.reward_experience)
        self.assertEqual(self.player.gold, enemy.reward)
        self.assertTrue(self.player.is_alive())
コード例 #4
0
ファイル: test_units.py プロジェクト: creazero/python_rpg
    def test_handling_armor_level(self):
        """
        Testing handling of armor level
        """
        self.player.add_item_to_backpack(
            database.get_item_from_db("Heavy helmet"))
        self.player.add_item_to_backpack(
            database.get_item_from_db("Test chest"))
        self.player.add_item_to_backpack(
            database.get_item_from_db("Test arms"))
        self.player.add_item_to_backpack(
            database.get_item_from_db("Test legs"))

        self.player.use_item("Heavy helmet")
        self.player.use_item("Test chest")
        self.player.use_item("Test arms")
        self.player.use_item("Test legs")

        self.assertIsNotNone(self.player.head)
        self.assertIsNotNone(self.player.chest)
        self.assertIsNotNone(self.player.arms)
        self.assertIsNotNone(self.player.legs)

        self.assertEqual(self.player.armor
                         - sum(self.player.create_armor_set()), 2)

        enemies = [Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                   Human(["Name", 20, 30, 2, 1, 3, 50, None, None, None, None,
                          None, None, None, None, None]),
                  ]

        for enemy in enemies:
            fight(self.player, enemy)
            self.assertEqual(enemy.hit_points, 0)
            self.player.hit_points = self.player.max_hit_points
        self.assertEqual(self.player.heavy_armor_level, 2)