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


Python Enemy.equip方法代码示例

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


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

示例1: make_enemy

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import equip [as 别名]
    def make_enemy():
        random_health = randint(0, 100)
        random_mana = randint(0, 100)
        random_damage = randint(0, 20)

        enemy = Enemy(random_health, random_mana, random_damage)
        enemy.equip(Weapon("Bow", 10))
        enemy.learn(Spell("Golden Arrow", 10, 10, 2))

        return enemy
开发者ID:stilyantanev,项目名称:Dungeons-And-Pythons,代码行数:12,代码来源:fights.py

示例2: TestEnemy

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import equip [as 别名]
class TestEnemy(unittest.TestCase):
    
    def setUp(self):
        self.enemy = Enemy(health=100, mana=100, damage=20)

    def test_damage_negative(self):
        with self.assertRaises(ValueError):
            enemy2 = Enemy(health=100, mana=100, damage=-20)

    def test_take_damage(self):
        enemy2 = Enemy(health=100, mana=100, damage=20)
        enemy2.take_damage(30)
        self.assertEqual(enemy2.get_health(), 70)

    def test_attack_with_weapon(self):
        w = Weapon('Axe', 30)
        self.enemy.equip(w)
        self.assertEqual(self.enemy.attack('weapon'), 30)

    def test_attack(self):
        self.assertEqual(self.enemy.attack(), 20)
开发者ID:EmineBasheva,项目名称:Dungeons_and_Pythons,代码行数:23,代码来源:test_enemy.py

示例3: TestEnemy

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import equip [as 别名]
class TestEnemy(unittest.TestCase):

    def setUp(self):
        self.enemy = Enemy(health=110, mana=110, damage=35)

    def test_create_new_instance(self):
        self.assertTrue(isinstance(self.enemy, Enemy))

    def test_valid_members(self):
        self.assertEqual(self.enemy.health, 110)
        self.assertEqual(self.enemy.mana, 110)
        self.assertEqual(self.enemy.damage, 35)

        self.assertEqual(self.enemy.max_health, 110)
        self.assertEqual(self.enemy.max_mana, 110)

    def test_is_alive(self):
        self.assertTrue(self.enemy.is_alive())
        self.enemy.health = 0
        self.assertFalse(self.enemy.is_alive())

    def test_can_cast_without_spell(self):
        self.assertFalse(self.enemy.can_cast())

    def test_can_cast_with_more_mana(self):
        self.enemy.spell = Spell("Chilling Poison", 20, 20, 2)
        self.assertTrue(self.enemy.can_cast())

    def test_can_cast_with_less_mana(self):
        self.enemy.spell = Spell("Chilling Poison", 20, 20, 2)
        self.enemy.mana = 0
        self.assertFalse(self.enemy.can_cast())

    def test_get_health(self):
        self.assertEqual(self.enemy.get_health(), 110)

    def test_get_mana(self):
        self.assertEqual(self.enemy.get_mana(), 110)

    def test_take_damage_more_than_health(self):
        self.enemy.take_damage(150)
        self.assertEqual(self.enemy.health, 0)

    def test_take_damage_less_than_health(self):
        self.enemy.take_damage(100)
        self.assertEqual(self.enemy.health, 10)

    def test_take_healing_dead_enemy(self):
        self.enemy.health = 0
        self.assertFalse(self.enemy.take_healing(200))

    def test_take_healing_with_more_points_than_max_health(self):
        self.enemy.health = 80
        self.assertTrue(self.enemy.take_healing(200))
        self.assertEqual(self.enemy.health, 110)

    def test_take_healing_with_less_points_than_max_health(self):
        self.enemy.health = 90
        self.assertTrue(self.enemy.take_healing(10))
        self.assertEqual(self.enemy.health, 100)

    def test_take_mana_with_more_points_than_max_mana(self):
        self.enemy.mana = 80
        self.enemy.take_mana(200)
        self.assertEqual(self.enemy.mana, 110)

    def test_take_mana_with_negative_mana(self):
        self.enemy.mana = 50
        self.enemy.take_mana(-60)
        self.assertEqual(self.enemy.mana, 0)

    def test_take_mana_with_less_points_than_max_mana(self):
        self.enemy.mana = 65
        self.enemy.take_mana(20)
        self.assertEqual(self.enemy.mana, 85)

    def test_equip(self):
        knife = Weapon("Knife", 10)
        self.enemy.equip(knife)
        self.assertEqual(self.enemy.weapon, knife)

    def test_learn(self):
        mind_blast = Spell("Mind Blast", 20, 55, 2)
        self.enemy.learn(mind_blast)
        self.assertEqual(self.enemy.spell, mind_blast)

    def test_attack_without_equiped_weapon(self):
        self.assertEqual(self.enemy.attack(by="weapon"), 0)

    def test_attack_with_equiped_weapon(self):
        knife = Weapon("Sword", 50)
        self.enemy.equip(knife)
        self.assertEqual(self.enemy.attack(by="weapon"), 50)

    def test_attack_without_learned_spell(self):
        self.assertEqual(self.enemy.attack(by="spell"), 0)

    def test_attack_with_learned_spell(self):
        fire_blast = Spell("Fire Blast", 40, 30, 1)
        self.enemy.learn(fire_blast)
#.........这里部分代码省略.........
开发者ID:stilyantanev,项目名称:Dungeons-And-Pythons,代码行数:103,代码来源:enemy_test.py

示例4: TestEnemy

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import equip [as 别名]
class TestEnemy(unittest.TestCase):

    def setUp(self):
        self.enemy_alive = Enemy(100, 0, 20)
        self.enemy_1fourthalive = Enemy(25, 0, 20)
        self.enemy_dead = Enemy(0, 50, 20)
        self.enemy_halfalive = Enemy(50, 0, 20)
        self.enemy_3fourthsalive = Enemy(75, 5, 60)
        self.knife = Weapon("knife", 20)
        self.spell = Spell("Fireball", 30, 50, 2)

    def test_init(self):
        self.assertTrue(isinstance(self.enemy_alive, Enemy))
        self.assertTrue(isinstance(self.enemy_dead, Enemy))
        self.assertTrue(isinstance(self.enemy_halfalive, Enemy))

    def test_get_health(self):
        self.assertEqual(self.enemy_alive.get_health(), 100)
        self.assertEqual(self.enemy_dead.get_health(), 0)

    def test_get_mana(self):
        self.assertEqual(self.enemy_alive.get_mana(), 0)
        self.assertEqual(self.enemy_dead.get_mana(), 50)

    def test_is_alive(self):
        self.assertTrue(self.enemy_alive.is_alive())
        self.assertFalse(self.enemy_dead.is_alive())

    def test_can_cast(self):
        self.assertTrue(self.enemy_dead.can_cast())
        self.assertFalse(self.enemy_alive.can_cast())

    def test_take_healing(self):
        with self.assertRaises(CannotHealWithNonPositivePoints):
            self.enemy_1fourthalive.take_healing(-10)
        self.assertFalse(self.enemy_dead.take_healing(20))
        with self.assertRaises(EnemyHasMaxHealth):
            self.enemy_alive.take_healing(10)
        self.assertTrue(self.enemy_halfalive.take_healing(60))
        self.enemy_1fourthalive.take_healing(75)
        self.assertEqual(self.enemy_1fourthalive.get_health(), 100)
        self.enemy_3fourthsalive.take_healing(10)
        self.assertEqual(self.enemy_3fourthsalive.get_health(), 85)

    def test_take_mana(self):
        self.assertFalse(self.enemy_1fourthalive.take_mana())
        self.assertFalse(self.enemy_3fourthsalive.take_mana())
        self.assertFalse(self.enemy_alive.take_mana())
        self.assertFalse(self.enemy_dead.take_mana())
        self.assertFalse(self.enemy_halfalive.take_mana())

    def test_equip(self):
        self.enemy_alive.equip(self.knife)
        self.assertEqual(self.enemy_alive.weapon, self.knife)

    def test_learn(self):
        self.enemy_halfalive.learn(self.spell)
        self.assertEqual(self.enemy_halfalive.spell, self.spell)

    def test_attack(self):
        self.assertEqual(self.enemy_halfalive.attack(by="weapon"), 0)
        self.assertEqual(self.enemy_1fourthalive.attack(by="spell"), None)
        self.enemy_alive.equip(self.knife)
        self.assertEqual(self.enemy_alive.attack(by="weapon"), 20)
        self.enemy_3fourthsalive.learn(self.spell)
        with self.assertRaises(Exception):
            self.enemy_3fourthsalive.attack(by="spell")
开发者ID:anedelcheva,项目名称:Game-Dungeons-and-Pythons,代码行数:69,代码来源:enemy_test.py


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