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


Python Hero.is_alive方法代码示例

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


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

示例1: TestHero

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import is_alive [as 别名]
class TestHero(unittest.TestCase):
    def setUp(self):
        self.hero1 = Hero("Arthur", "knight", 100, 100, 2)
        self.weapon1 = Weapon(name="The Axe of Destiny", damage=20)
        self.spell1 = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)

    def test_init(self):
        self.assertTrue(isinstance(self.hero1, Hero))

    def test_known_as(self):
        self.assertEqual(self.hero1.known_as(), "Arthur the knight")

    def test_is_alive_and_take_damage(self):
        self.assertTrue(self.hero1.is_alive())
        self.hero1.take_damage(70)
        self.assertTrue(self.hero1.is_alive())
        self.assertEqual(self.hero1.get_health(), 30)
        self.hero1.take_damage(40)
        self.assertFalse(self.hero1.is_alive())

    def test_take_healing(self):
        self.hero1.take_damage(50)
        self.hero1.take_healing(20)
        self.assertTrue(self.hero1.get_health() == 70)
        self.assertTrue(self.hero1.take_healing(10))
        self.hero1.take_damage(80)
        self.assertFalse(self.hero1.take_healing(20))

    def test_equip(self):
        self.hero1.equip(self.weapon1)
        self.assertIsInstance(self.hero1.weapon, Weapon)

    def test_learn(self):
        self.hero1.learn(self.spell1)
        self.assertIsInstance(self.hero1.spell, Spell)
开发者ID:anedelcheva,项目名称:Game-Dungeons-and-Pythons,代码行数:37,代码来源:hero_test.py

示例2: FightTest

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

    def setUp(self):
        self.hero_one = Hero("Bron", 100, "DragonSlayer")
        self.orc_one = Orc("Orcy", 150, 1.5)
        self.fight_one = fight.Fight(self.hero_one, self.orc_one)
        self.axe = Weapon("Axe", 20, 0.2)
        self.sword = Weapon("Sword", 12, 0.7)
        self.hero_one.weapon = self.sword
        self.orc_one.weapon = self.axe

    def test_init(self):
        self.assertEqual(self.fight_one.hero, self.hero_one)
        self.assertEqual(self.fight_one.orc, self.orc_one)

    def test_fight(self):
        self.fight_one.simulate_battle()
        # if one of them died
        self.assertFalse(self.orc_one.is_alive() and self.hero_one.is_alive())

    def test_fight_no_weapon(self):
        self.orc_one.weapon = None
        self.fight_one.simulate_battle()
        # orc has no weapon => orc dies
        self.assertFalse(self.orc_one.is_alive())

    def test_fight_equal(self):
        hero_one = Hero("Bron", 100, "DragonSlayer")
        orc_one = Orc("Orcy", 150, 1.5)
        hero_one.weapon = Weapon("Axe", 20, 0.5)
        orc_one.weapon = Weapon("Axe", 20, 0.5)
        self.fight_one.simulate_battle()
        # both has the same weapon, but the orc has berserc_factor,\
        # he should be alive at the end
        self.assertTrue(self.orc_one.is_alive())
开发者ID:GalinaDimitrova,项目名称:Hack,代码行数:37,代码来源:fight_test.py

示例3: TestFight

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

    def setUp(self):
        self.hero = Hero("Aiden", 500, "Daro Wonderer")
        self.orc = Orc("Thrall", 400, 1.4)
        weapon1 = Weapon("The Ash Bringer", 80, 0.5)
        weapon2 = Weapon('DoomHammer', 80, 0.5)
        self.hero.equip_weapon(weapon1)
        self.orc.equip_weapon(weapon2)

        self.fight = Fight(self.hero, self.orc)

    def test_simulate_fight(self):
        self.fight.simulate_fight()
        self.assertTrue(self.hero.is_alive() or self.orc.is_alive())
        self.assertFalse(self.orc.is_alive() and self.hero.is_alive())
开发者ID:NikiMaslarski,项目名称:HackBulgari_Programming101,代码行数:18,代码来源:fight_test.py

示例4: FightTest

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

    def setUp(self):
        self.bron_hero = Hero("Bron", 100, "DragonSlayer")
        self.torug_orc = Orc("Torug", 100, 1.2)
        self.new_fight = Fight(self.bron_hero, self.torug_orc)
        self.axe = Weapon("Axe", 20, 0.2)
        self.sword = Weapon("Sword", 12, 0.7)
        self.bron_hero.equip_weapon(self.sword)
        self.torug_orc.equip_weapon(self.axe)

    def test_init(self):
        self.assertEqual(self.new_fight.orc, self.torug_orc)
        self.assertEqual(self.new_fight.hero, self.bron_hero)

    def test_who_is_first(self):
        first_entity = self.new_fight.who_is_first()
        self.assertIn(first_entity, [self.bron_hero, self.torug_orc])

    def test_fight(self):
        self.new_fight.simulate_battle()
        self.assertFalse(self.torug_orc.is_alive() and self.bron_hero.is_alive())

    def test_fight_with_no_weapons(self):
        self.torug_orc.weapon = None
        self.new_fight.simulate_battle()
        self.assertFalse(self.torug_orc.is_alive())
开发者ID:ivaylospasov,项目名称:programming-101,代码行数:29,代码来源:fight_test.py

示例5: TestHero

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

    def setUp(self):
        self.bron = Hero("Bron", 100, "DragonSlayer")

    def test_hero_init(self):
        self.assertEqual(self.bron.name, "Bron")
        self.assertEqual(self.bron.health, 100)
        self.assertEqual(self.bron.nickname, "DragonSlayer")

    def test_known_as(self):
        self.assertEqual(self.bron.known_as(), "Bron the DragonSlayer")

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

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

    def test_is_alive_with_dead(self):
        self.bron.health = 0
        self.assertFalse(self.bron.is_alive())

    def test_take_damage(self):
        self.bron.take_damage(50)
        self.assertEqual(self.bron.health, 50)

    def test_take_damage_max_dmg(self):
        self.bron.take_damage(200)
        self.assertEqual(self.bron.health, 0)
        self.bron.take_damage(20)
        self.assertEqual(self.bron.health, 0)

    def test_take_healing_on_dead(self):
        self.bron.health = 0
        self.assertFalse(self.bron.take_healing(100))

    def test_take_healing_above_maximum_health(self):
        self.bron.take_healing(1 + self.bron._MAX_HEALTH)
        self.assertTrue(self.bron.take_healing(1 + self.bron._MAX_HEALTH))
        self.assertEqual(self.bron.health, self.bron._MAX_HEALTH)

    def test_take_healing(self):
        self.bron.health = 20
        self.assertTrue(self.bron.take_healing(20))
        self.assertEqual(self.bron.health, 40)
开发者ID:svetlio2,项目名称:hackbg,代码行数:48,代码来源:hero_test.py

示例6: TestHero

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

    def setUp(self):
        self.hero = Hero("Bron", 100, "DragonSlayer")

    def test_hero_init(self):
        self.assertEqual(self.hero.name, "Bron")
        self.assertEqual(self.hero.health, 100)
        self.assertEqual(self.hero.nickname, "DragonSlayer")

    def test_known_as(self):
        self.assertEqual(self.hero.known_as(), "Bron the DragonSlayer")

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

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

    def test_take_damage(self):
        self.hero.take_damage(50)
        self.assertEqual(50, self.hero.get_health())
        self.hero.take_damage(10)
        self.assertEqual(40, self.hero.get_health())
        self.hero.take_damage(25)
        self.assertEqual(15, self.hero.get_health())

    def test_take_healing(self):
        self.assertTrue(self.hero.take_healing(25))
        self.assertEqual(100, self.hero.get_health())
        self.hero.take_damage(40)
        self.assertEqual(60, self.hero.get_health())
        self.assertTrue(self.hero.take_healing(15))
        self.assertEqual(75, self.hero.get_health())
        self.hero.take_damage(100)
        self.assertFalse(self.hero.is_alive())
        self.assertFalse(self.hero.take_healing(100))

    def test_take_healing_dead(self):
        pass

    def test_take_healing_overhealing(self):
        pass
开发者ID:modzozo,项目名称:hack101,代码行数:47,代码来源:heroTest.py

示例7: HeroTest

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

    def setUp(self):
        self.bron_hero = Hero("Bron", 100, "DragonSlayer")

    def test_hero_init(self):

        self.assertEqual(self.bron_hero.name, "Bron")
        self.assertEqual(self.bron_hero.health, 100)
        self.assertEqual(self.bron_hero.nickname, "DragonSlayer")

    def test_known_as(self):

        self.assertEqual(self.bron_hero.known_as(), "Bron the DragonSlayer")

    def test_get_health(self):

        self.assertEqual(self.bron_hero.get_health(), 100)

    def test_is_alive_return_false(self):

        self.bron_hero.health = 0
        self.assertFalse(self.bron_hero.is_alive())

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

    def test_take_damage(self):

        self.assertEqual(80, self.bron_hero.take_damage(20))

    def test_take_damage_more_than_health(self):

        self.assertEqual(0, self.bron_hero.take_damage(120))

    def test_take_healing_to_dead_person(self):
        self.bron_hero.health = 0
        self.assertFalse(self.bron_hero.take_healing(20))

    def test_take_healing_more_than_full_health(self):
        self.bron_hero.health = 90
        self.assertFalse(self.bron_hero.take_healing(100))

    def test_take_healing_true(self):
        self.bron_hero.health = 40
开发者ID:vparkov,项目名称:HackBulgaria,代码行数:47,代码来源:hero_test.py

示例8: test_fight

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import is_alive [as 别名]
 def test_fight(self):
     my_Hero = Hero("Ivan", 100, "bad ass")
     my_Orc = Orc("Boko", 100, 1.5)
     my_weapon1 = Weapon("Axe1", 31, 0.2)
     my_weapon2 = Weapon("Axe2", 31, 0.2)
     my_Hero.equip_weapon(my_weapon1)
     my_Orc.equip_weapon(my_weapon2)
     fight1 = Fight(my_Hero, my_Orc)
     fight1.simulate_fight()
     self.assertFalse(my_Orc.is_alive() and my_Hero.is_alive())
开发者ID:Hristiyan-Andreev,项目名称:HackBuglaria,代码行数:12,代码来源:fightingTest.py

示例9: TestFight

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

    def setUp(self):
        self.bron_hero = Hero("Bron", 100, "DragonSlayer")
        self.axe = Weapon("Mighty Axe", 25, 0.2)
        self.sword = Weapon("Mighty Sword", 12, 0.7)
        self.bron_orc = Orc("Bron", 100, 1.3)
        self.my_fight = Fight(self.bron_hero, self.bron_orc)
        self.bron_hero.weapon = self.sword
        self.bron_orc.weapon = self.axe

    def test_fight_init(self):
        self.assertEqual(self.my_fight.hero, self.bron_hero)
        self.assertEqual(self.my_fight.orc, self.bron_orc)

    def test_who_is_first(self):
        flag_hero = False
        flag_orc = False
        for i in range(0, 10):
            self.my_fight.who_is_first()
            if self.my_fight.who_is_first() == self.bron_hero:
                flag_hero = True
            else:
                flag_orc = True
        self.assertTrue(flag_hero and flag_orc)

    def test_simulate_fight(self):
        self.my_fight.simulate_fight()
        self.assertFalse(self.bron_orc.is_alive() and self.bron_hero.is_alive())

    def test_simulate_fight_hero_wtih_wep_vs_hero_without_wep(self):
        self.hero_without_wep = Hero("Toni", 100, "Monster")
        self.fight = Fight(self.bron_hero, self.hero_without_wep)
        self.fight.simulate_fight()
        self.assertFalse(self.hero_without_wep.is_alive())

    def test_simulate_fight_hero_vs_equal_orc(self):
        self.equal_orc = Orc("Toni", 100, 1.5)
        self.equal_orc.weapon = self.sword
        self.fight = Fight(self.bron_hero, self.equal_orc)
        self.fight.simulate_fight()
        self.assertFalse(self.bron_hero.is_alive())
开发者ID:AlexanderTankov,项目名称:HackBulgaria-Programming-101,代码行数:44,代码来源:fight_test.py

示例10: game

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import is_alive [as 别名]
def game():
    map = Dungeon("dungeon_map")
    goshko = Hero("Hero", 100, "Hero")
    Orko = Orc("Orko", 100, 1.5)
    map.spawn("Goshko", goshko)
    map.spawn("Orko", Orko)
    map.print_map()
    while goshko.is_alive() and Orko.is_alive():
        move_hero = input("Move the hero! ")
        map.move("Goshko", move_hero)
        map.print_map()
        move_orc = input("Move the orc! ")
        map.move("Orko", move_orc)
        map.print_map()
    if not goshko.is_alive():
        print ("The Orc won!")
        return
    else:
        print ("The Hero won!")
        return
开发者ID:skdls-,项目名称:Python,代码行数:22,代码来源:dungeon_remake.py

示例11: FightTest

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import is_alive [as 别名]
class FightTest(unittest.TestCase):
	def setUp(self):
		self.orc = Orc("Gorlag", 100, 3) # ili self.orc_one
		self.hero = Hero("Bron", 100, "DragonSlayer") # ili self.hero_one
		self.fight = fight_new.Fight(self.orc,self.hero) # ili self.fight_one
		self.axe = Weapon("Axe", 20, 0.2)
		self.sword = Weapon("Sword", 12, 0.7)
		self.hero.equiped_weapon = self.sword
		self.orc.equiped_weapon = self.axe # izpozlvame self.hero.weapon za da ne zavisi testa ni ot drygiq test za weapon eqiped

	def test_orc_init(self):
		self.assertTrue(isinstance(self.fight.orc, Orc))
		self.assertEqual(self.fight.orc.name, "Gorlag")
		self.assertEqual(self.fight.orc, self.orc)

	def test_hero_init(self):
		self.assertTrue(isinstance(self.fight.hero, Hero))
		self.assertEqual(self.fight.hero.name, "Bron")
		self.assertEqual(self.fight.hero.nickname, "DragonSlayer")
		self.assertEqual(self.fight.hero, self.hero)

	def test_attack_first(self):
		result = []
		for x in range(10):
			result.append(self.fight.flip_coin())
		self.assertTrue(self.hero in result)
		self.assertTrue(self.orc in result)

	def test_simulate_fight_(self):
		self.orc.health = 0
		self.assertTrue(self.orc.is_alive() or self.hero.is_alive())

	def test_fight(self):
		self.fight.simulate_fight()
		self.assertFalse(self.orc.is_alive() and self.hero.is_alive())

	def test_fight_with_no_weapons(self):
		self.orc.equiped_weapon = None

		self.fight.simulate_fight()
		self.assertFalse(self.orc.is_alive())
开发者ID:ksvulchev,项目名称:Programing101,代码行数:43,代码来源:fight_test.py

示例12: TestHero

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

    def setUp(self):
        self.h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2)
        self.w = Weapon(name="The Axe of Destiny", damage=20)
        self.s = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)

    def test_init(self):
        self.assertEqual(self.h.name, "Bron")
        self.assertEqual(self.h.title, "Dragonslayer")
        self.assertEqual(self.h.health, 100)
        self.assertEqual(self.h.mana, 100)
        self.assertEqual(self.h.mana_regeneration_rate, 2)
        self.assertEqual(self.h.start_mana, 100)
        self.assertEqual(self.h.damage, 0)

    def test_known_as(self):
        result = "Bron the Dragonslayer"
        self.assertEqual(self.h.known_as(), result)

    def test_is_alive(self):
        self.assertTrue(self.h.is_alive() is True)

    def test_take_damage(self):
        damage = self.h.take_damage(40)
        self.assertTrue(self.h.health is 60)

    def test_can_cast(self):
        self.assertTrue(self.h.can_cast() is True)

    def test_take_healing(self):
        self.h.take_damage(100)
        self.new_health = self.h.take_healing(30)
        self.assertTrue(self.h.health is 0)

    def test_take_mana(self):
        self.h.learn(self.s)
        self.h.attack(by="spell")
        self.h.take_mana(10)
        self.assertEqual(self.h.mana, 60)

    def test_attack(self):
        self.h.equip(self.w)
        self.assertEqual(self.h.attack(by="weapon"), 20)
        self.h.learn(self.s)
        self.assertEqual(self.h.attack(by="spell"), 30)

    def test_exception(self):
        self.h.learn(self.s)
        self.assertEqual(self.h.attack(by="spell"), 30)
        with self.assertRaises(NotEnaughMana):
            self.s.mana_cost = 50
            self.h.attack(by="spell")
开发者ID:pgenev,项目名称:HackBG-Programing-101-v3,代码行数:55,代码来源:test_hero.py

示例13: TestFight

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

    def setUp(self):
        self.orc = Orc("Berserk", 1000, 2)
        self.hero = Hero("Bron", 1000, "DragonSlayer")
        self.weapon = Weapon("Mighty Axe", 25, 0.3)
        self.orc.equip_weapon(self.weapon)
        self.hero.equip_weapon(self.weapon)
        self.fight = Fight(self.hero, self.orc)

    def test_simulate_fight(self):
        self.fight.simulate_fight()
        self.assertTrue(not self.orc.is_alive() or not self.hero.is_alive())
开发者ID:antonpetkoff,项目名称:Programming101,代码行数:15,代码来源:fight_test.py

示例14: compleate_fight

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import is_alive [as 别名]
 def compleate_fight(self, player_name, enemy_pos):
     enemy_name = self.get_entity_name(enemy_pos)
     #get player from dict
     player_one = Hero("Bron", 10, "DragonSlayer")
     player_two = Orc("Bron", 10, 1.3)
     for keys in self.heroes_dict:
         if self.heroes_dict[keys] == "%s" % (enemy_name) or self.heroes_dict[keys] == "%s" % (player_name):
             if self.heroes_dict[keys] == "%s" % (player_name):
                 player_one = keys
             if self.heroes_dict[keys] == "%s" % (enemy_name):
                 player_two = keys
     fight = Fight(player_one, player_two)
     fight.simulate_fight()
     return player_one.is_alive()
开发者ID:AlexanderTankov,项目名称:HackBulgaria-Programming-101,代码行数:16,代码来源:dungeon.py

示例15: Test

# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import is_alive [as 别名]
class Test(unittest.TestCase):
    def setUp(self):
        self.w = Weapon("axe", 20)
        self.spell = Spell("love spell", 70, 2, 4)
        self.h = Hero("Arthur", "great", 100, 100, 100, 2, self.w, self.spell)

    def test_hero_init(self):
        self.assertEqual(self.h.get_name(), "Arthur")
        self.assertEqual(self.h.get_title(), "great")
        self.assertEqual(self.h.get_health(), 100)
        self.assertEqual(self.h.get_start_health(), 100)
        self.assertEqual(self.h.get_mana(), 100)
        self.assertEqual(self.h.get_mana_rate(), 2)
        self.assertEqual(self.h.get_weapon(), "axe")

    def test_hero_init(self):
        self.assertEqual(str(self.h), "Arthur great 100 100 2")

    def test_hero_known_as(self):
        self.assertEqual(self.h.known_as(), "Arthur the great")

    def test_hero_is_alive(self):
        self.assertTrue(self.h.is_alive())

    def test_hero_is_dead(self):
        self.assertFalse(self.h.is_dead())

    def test_hero_can_cast(self):
        self.assertTrue(self.h.can_cast())

    def test_hero_take_damage(self):
        self.assertEqual(self.h.take_damage(70), 30)

    def test_hero_take_healing(self):
        self.h.take_damage(70)
        self.assertEqual(self.h.take_healing(20), 50)

    def test_hero_equip(self):
        self.assertEqual(self.h.equip(self.w), "Equipped with axe, damage: 20")

    def test_hero_attack(self):
        self.assertEqual(self.h.attack("weapon"), 20)
开发者ID:AdelinaMancheva,项目名称:Dungeons-and-Pythons,代码行数:44,代码来源:test_hero.py


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