当前位置: 首页>>代码示例>>Python>>正文


Python Hero.has_weapon方法代码示例

本文整理汇总了Python中hero.Hero.has_weapon方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.has_weapon方法的具体用法?Python Hero.has_weapon怎么用?Python Hero.has_weapon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hero.Hero的用法示例。


在下文中一共展示了Hero.has_weapon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HeroTest

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import has_weapon [as 别名]
class HeroTest(unittest.TestCase):

    def setUp(self):
        self.hero = Hero("Arthas", 1000, "Lich King")
        self.hero.weapon = Weapon("Frostmourne", 35, 0.7)

    def test_init(self):
        self.assertEqual(self.hero.name, "Arthas")
        self.assertEqual(self.hero.health, 1000)
        self.assertEqual(self.hero.nickname, "Lich King")

    def test_known_as(self):
        self.assertEqual(self.hero.known_as(), "Arthas the Lich King")

    def test_has_weapon_when_present(self):
        self.assertEqual(self.hero.has_weapon(), True)

    def test_has_weapon_when_not_present(self):
        self.hero.weapon = None
        self.assertEqual(self.hero.has_weapon(), False)

    def test_equip_stronger_weapon(self):
        test_weapon = Weapon("Stick", 500, 0.1)
        self.hero.equip_weapon(test_weapon)
        self.assertEqual(self.hero.weapon, test_weapon)

    def test_equip_weaker_weapon(self):
        test_weapon = Weapon("Stick", 5, 0.1)
        self.hero.equip_weapon(test_weapon)
        self.assertNotEqual(self.hero.weapon, test_weapon)

    def test_attack_when_no_weapon_is_equipped(self):
        self.hero.weapon = None
        self.assertEqual(self.hero.attack(), 0)

    def test_attack_when_weapon_is_equipped(self):
        self.assertIn(self.hero.attack(), [35, 70])
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:39,代码来源:test_all.py

示例2: int

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import has_weapon [as 别名]
                    elif x == 2:
                        weapon_crit += output[i]
        weapon_damage = int(weapon_damage)
        weapon_crit = float(weapon_crit)

        weapon = Weapon(weapon_name, weapon_damage, weapon_crit)
        global weapons
        weapons = []
        weapons.append(weapon)
        self.weapons[weapon_name] = weapon
        random_slot = randint(0, len(free_slots))
        output[free_slots[random_slot]] = 'W'
        self.reinitialize_file(self.filepath, output)


orc = Orc("2", 100, 1.3)
hero1 = Hero("1", 100, "Tester")
testmap = Dungeon('testmap')
testmap.spawn_weapons()
testmap.spawn("1", hero1)
testmap.spawn("2", orc)
print (testmap.print_map())

# print (testmap.spawnlist)
# print (testmap.spawnedplayers)

testmap.move("1", "right")
print (hero1.has_weapon())
testmap.print_map()
print (entities)
开发者ID:VasilVasilev93,项目名称:HackBulgaria,代码行数:32,代码来源:Dungeon.py

示例3: EntityTest

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import has_weapon [as 别名]
class EntityTest(unittest.TestCase):
    def setUp(self):
        self.shosh_hero = Hero('Shosh', 100, 'GraveRobber')
        self.zaithan_orc = Orc('Zaithan', 150, 0.5)
        self.destroyer_weapon = Weapon('Destroyer Axe', 30, 0.7)
        self.crystal_weapon = Weapon('Crystal Dagger', 15, 0.2)
        self.molten_weapon = Weapon('Molten Sword', 27, 0.4)

    def test_init(self):
        self.assertEqual(self.shosh_hero.name, 'Shosh')
        self.assertEqual(self.shosh_hero.health, 100)
        self.assertEqual(self.shosh_hero.nickname, 'GraveRobber')

    def test_get_health(self):
        self.assertEqual(self.shosh_hero.get_health(), 100)

    def test_is_alive(self):
        self.assertTrue(self.shosh_hero.is_alive())

    def test_is_dead(self):
        self.shosh_hero.health = 0
        self.assertFalse(self.shosh_hero.is_alive())

    def test_take_damage_integer_value(self):
        self.shosh_hero.take_damage(25)
        self.assertEqual(self.shosh_hero.get_health(), 75)

    def test_take_damage_decimal_value(self):
        self.shosh_hero.take_damage(0.5)
        self.assertEqual(self.shosh_hero.get_health(), 99.5)

    def test_take_huge_amount_of_damage(self):
        self.shosh_hero.take_damage(150)
        self.assertEqual(self.shosh_hero.get_health(), 0)

    def test_take_huge_amount_of_damage_decimal(self):
        self.shosh_hero.take_damage(120.5)
        self.assertEqual(self.shosh_hero.get_health(), 0)

    def test_take_healing_when_dead(self):
        self.shosh_hero.health = 0
        self.assertFalse(self.shosh_hero.take_healing(30))

    def test_take_hiper_super_big_healing(self):
        self.shosh_hero.health = 70
        self.assertTrue(self.shosh_hero.take_healing(200))
        self.assertEqual(self.shosh_hero.health, self.shosh_hero.get_health())

    def test_take_healing(self):
        self.shosh_hero.health = 20
        self.assertTrue(self.shosh_hero.take_healing(50))
        self.assertEqual(self.shosh_hero.health, 70)

    def test_has_weapon(self):
        self.zaithan_orc.weapon = None
        self.shosh_hero.weapon = self.crystal_weapon
        self.assertTrue(self.shosh_hero.has_weapon())
        self.assertFalse(self.zaithan_orc.has_weapon())

    def test_equip_weapon(self):
        self.shosh_hero.equip_weapon(self.destroyer_weapon)
        self.assertTrue(self.shosh_hero.has_weapon())
        self.assertEqual(self.shosh_hero.weapon.type, 'Destroyer Axe')

    def test_equip_weapon_and_discard_the_old_one(self):
        self.assertFalse(self.zaithan_orc.has_weapon())
        self.zaithan_orc.equip_weapon(self.crystal_weapon)
        self.assertTrue(self.zaithan_orc.has_weapon())
        self.assertEqual(self.zaithan_orc.weapon.type, 'Crystal Dagger')
        self.zaithan_orc.equip_weapon(self.molten_weapon)
        self.assertTrue(self.zaithan_orc.has_weapon())
        self.assertNotEqual(self.zaithan_orc.weapon.type, 'Crystal Dagger')
        self.assertEqual(self.zaithan_orc.weapon.type, 'Molten Sword')

    def test_attack_without_weapon(self):
        self.assertEqual(self.shosh_hero.attack(), 0)

    def test_attack_with_weapon(self):
        self.shosh_hero.equip_weapon(self.destroyer_weapon)
        self.assertIn(self.shosh_hero.attack(), [30, 60])
开发者ID:Shosh,项目名称:hackBulgaria_programming101,代码行数:82,代码来源:entity_test.py


注:本文中的hero.Hero.has_weapon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。