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


Python Enemy.get_health方法代码示例

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


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

示例1: EnemyTests

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

    def setUp(self):
        self.enemy = Enemy()

    def test_is_alive(self):
        self.assertEqual(self.enemy.is_alive(), True)

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

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

    def test_can_cast(self):
        self.assertEqual(self.enemy.can_cast(), True)

    def test_take_healing(self):
        e = Enemy(80, 100, 20)
        e.take_healing(15)
        self.assertEqual(e.get_health(), 95)

    def test_take_mana(self):
        e = Enemy(100, 80, 20)
        e.take_mana(15)
        self.assertEqual(e.get_mana(), 95)
开发者ID:Antoniy7,项目名称:Dungeon,代码行数:28,代码来源:enemy_test.py

示例2: TestEnemy

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

    def setUp(self):
        self._enemy = Enemy(health=100, mana=100, damage=20)

    def test_init(self):
        self.assertTrue(isinstance(self._enemy, Enemy))

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

        with self.assertRaises(ValueError):
            Enemy(health=150, mana=100, damage=20)

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

        with self.assertRaises(ValueError):
            Enemy(health=100, mana=150, damage=20)

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

        with self.assertRaises(TypeError):
            Enemy(health="str", mana=100, damage=20)

        with self.assertRaises(TypeError):
            Enemy(health=100, mana="str", damage=20)

        with self.assertRaises(TypeError):
            Enemy(health=100, mana=100, damage="str")

    def test_get_health(self):
        self.assertEqual(self._enemy.get_health(), self._enemy.health)

    def test_get_mana(self):
        self.assertEqual(self._enemy.get_mana(), self._enemy.mana)

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

    def test_can_cast(self):
        self.assertTrue(self._enemy.can_cast())

    def test_take_healing(self):
        damaged_enemy = Enemy(health=50, mana=100, damage=20)

        self.assertTrue(damaged_enemy.take_healing(30))

    def test_take_mana(self):
        down_mana_enemy = Enemy(health=100, mana=40, damage=20)
        down_mana_enemy.take_mana(30)
        self.assertEqual(down_mana_enemy.mana, 40)

    def test_attack(self):
        pass
开发者ID:vassi95,项目名称:Dungeons-and-pythons,代码行数:58,代码来源:enemy_tests.py

示例3: __init__

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import get_health [as 别名]
class Dungeon:

    def __init__(self, file_name):
        self.file = file_name
        self.map = None
        self.hero = None
        self.enemy = None
        self.treasure = {
                   "heal_potion": [25, 50, 75, 100],
                   "mana_potion": [25, 50, 75, 100],
                   "weapon": [Weapon("Axe", damage=20),
                              Weapon("Sword", damage=25),
                              Weapon("Mace", damage=30)],
                   "spell": [Spell("Frostbolt", 20, 30, cast_range=3),
                             Spell("Fireball", 25, 40, cast_range=2),
                             Spell("Arcanebolt", 30, 50, cast_range=2)],
                   }
        self.generate_map()

    directions = {
                    "left": (-1, 0),
                    "right": (1, 0),
                    "up": (0, -1),
                    "down": (0, +1),
                 }

    def generate_map(self):
        with open(self.file, 'r') as f:
            content = f.read()
            lines = content.split("\n")
            lines = [line for line in lines if line.strip() != ""]
            self.map = [list(line) for line in lines]

    def print_map(self):
        for roll in self.map:
            print("".join(roll))

    def spawn(self, hero_instance):
        if not isinstance(hero_instance, Hero):
            raise TypeError("The hero must be from class Hero")
        self.hero = hero_instance
        found = False
        for roll in self.map:
            for i in range(len(roll)):
                if roll[i] == "S":
                    roll[i] = "H"
                    found = True
                    break
            if found:
                break
        return found

    def check_out_of_range(self, x, y):
        if y < 0 or y > len(self.map) - 1:
            return False
        if x < 0 or x > len(self.map[y]):
            return False
        return True

    def move_to_next_field(self, x, y):
        if self.map[y][x] == "#":
            return False
        elif self.map[y][x] == ".":
            self.map[y][x] = "H"
            return True
        elif self.map[y][x] == "E":
            self.enemy = Enemy(100, 100, 20)
            self.start_fight()
            if self.hero.is_alive():
                return True
            else:
                if not self.spawn(self.hero):
                    print("GAME OVER")
                    return True
        elif self.map[y][x] == "T":
            self.pick_treasure()
            self.map[y][x] = "H"
            return True
        elif self.map[y][x] == "G":
            print("Your quest is complete! Good job!")
            return True

    def pick_treasure(self):
        treasures = ["heal_potion", "mana_potion", "weapon", "spell"]
        loot = random.choice(treasures)
        if loot == "heal_potion":
            heal = random.choice(self.treasure[loot])
            self.hero.take_healing(heal)
            print("Found health potion. Hero health is {}.".format(
                self.hero.get_health()))
        elif loot == "mana_potion":
            mana = random.choice(self.treasure[loot])
            self.hero.take_mana(mana)
            print("Found mana potion. Hero mana is {}.".format(
                self.hero.get_mana()))
        elif loot == "weapon":
            weapon = random.choice(self.treasure[loot])
            self.hero.equip(weapon)
            print("Found a weapon - {}.".format(weapon.name))
        elif loot == "spell":
#.........这里部分代码省略.........
开发者ID:kobso1245,项目名称:Programming101-v3,代码行数:103,代码来源:dungeon.py

示例4: TestEnemy

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import get_health [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

示例5: print

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import get_health [as 别名]
            print('The hero can use only spell or weapon')





map = Dungeon('dungeon.txt')
hero = Hero(name = 'Django', title = 'The Unchained', health = 100, mana = 100, mana_regen  = 2)
enemy = Enemy(health = 80, mana = 100, damage = 20)
w = Weapon('Axe', 20)
s = Spell('Magic', 20, 50, 2)
hero.equip(w)
hero.learn(s)

print(hero.get_health())
print(enemy.get_health())

map._pick_treasure()


map._print_map()
map._spawn('Batman')
map._move_hero('right')
map._print_map()
map._move_hero('down')
map._print_map()
map._move_hero('down')
map._print_map()
map._move_hero('down')
map._print_map()
map._move_hero('right')
开发者ID:ggchilev,项目名称:hack_bulgaria,代码行数:33,代码来源:Dungeon.py

示例6: TestEnemy

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import get_health [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

示例7: test_take_damage

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import get_health [as 别名]
 def test_take_damage(self):
     enemy2 = Enemy(health=100, mana=100, damage=20)
     enemy2.take_damage(30)
     self.assertEqual(enemy2.get_health(), 70)
开发者ID:EmineBasheva,项目名称:Dungeons_and_Pythons,代码行数:6,代码来源:test_enemy.py

示例8: test_take_healing

# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import get_health [as 别名]
 def test_take_healing(self):
     e = Enemy(80, 100, 20)
     e.take_healing(15)
     self.assertEqual(e.get_health(), 95)
开发者ID:Antoniy7,项目名称:Dungeon,代码行数:6,代码来源:enemy_test.py


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