本文整理汇总了Python中orc.Orc.is_alive方法的典型用法代码示例。如果您正苦于以下问题:Python Orc.is_alive方法的具体用法?Python Orc.is_alive怎么用?Python Orc.is_alive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orc.Orc
的用法示例。
在下文中一共展示了Orc.is_alive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FightTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例2: FightTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例3: OrcTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
class OrcTest (unittest.TestCase):
def setUp(self):
self.orc = Orc("Gosho", 100, 1.25)
def test_orc_init(self):
self.assertEqual(self.orc.name, "Gosho")
self.assertEqual(self.orc.health, 100)
self.assertEqual(self.orc.berserk_factor, 1.25)
def test_get_health(self):
self.assertEqual(self.orc.get_health(), 100)
def test_is_alive_return_false(self):
self.orc.fight_health = 0
self.assertFalse(self.orc.is_alive())
def test_is_alive(self):
self.assertTrue(self.orc.is_alive())
def test_take_damage(self):
self.assertEqual(80, self.orc.take_damage(20))
def test_take_damage_more_than_health(self):
self.assertEqual(0, self.orc.take_damage(120))
def test_take_healing_to_dead_person(self):
self.orc.health = 0
self.assertFalse(self.orc.take_healing(20))
def test_take_healing_more_than_full_health(self):
self.orc.health = 90
self.assertFalse(self.orc.take_healing(100))
def test_take_healing_true(self):
self.orc.health = 40
def test_berserk_factor_below_one(self):
self.orc.berserk_factor = 0.4
self.assertEqual(self.orc.berserk_factor_check(), 1)
def test_berserk_factor_over_two(self):
self.orc.berserk_factor = 2.14
self.assertEqual(self.orc.berserk_factor_check(), 2)
def test_orc_attack_with_weapon(self):
self.orc.equip_weapon(Weapon("Pipe", 35, 0.5))
self.assertEqual(self.orc.attack(), 70)
def test_orc_attack_without_weapon(self):
self.assertEqual(self.orc.attack(), 0)
示例4: TestOrc
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
class TestOrc(unittest.TestCase):
def setUp(self):
self.orc = Orc("Monster", 100, 2)
def test_orc_init(self):
self.assertEqual(self.orc.name, "Monster")
self.assertEqual(self.orc.health, 100)
self.assertEqual(self.orc.berserk_factor, 2)
def test_orc_limit_bf_more(self):
orc = Orc("Monster", 100, 5)
with self.assertRaises(ValueError):
Orc(2)
def test_orc_limit_bf_more(self):
orc = Orc("Monster", 100, 1)
self.assertEqual(orc.berserk_factor, 1)
def test_orc_limit_bf_more(self):
orc = Orc("Monster", 100, 2)
self.assertEqual(orc.berserk_factor, 2)
def test_get_health(self):
self.assertEqual(100, self.orc.get_health())
def test_is_alive(self):
self.assertTrue(self.orc.is_alive())
def test_is_alive_death(self):
self.orc.health = 0
self.assertFalse(self.orc.is_alive())
def test_take_damage(self):
self.assertEqual(self.orc.take_damage(80),20)
def test_take_damage_more(self):
self.assertEqual(self.orc.take_damage(123),0)
def test_take_healing_deathed_hero(self):
self.orc.health = 0
self.assertFalse(self.orc.take_healing(10))
def test_take_healing(self):
self.assertTrue(self.orc.take_healing(10))
def test_take_healing_limit_health_invalid(self):
self.orc.take_healing(10)
self.assertEqual(100, self.orc.health)
def test_take_healing_limit_health_valid(self):
self.orc.health = 80
self.orc.take_healing(10)
self.assertEqual(90, self.orc.health)
示例5: OrcTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
class OrcTest (unittest.TestCase):
def setUp(self):
self.orc = Orc("The DragonSlayer killer", 100, 1.5)
def test_hero_init(self):
self.assertEqual(self.orc.name, "The DragonSlayer killer")
self.assertEqual(self.orc.maxhealth, 100)
self.assertEqual(self.orc.berserk_factor, 1.5)
def test_get_health(self):
self.assertEqual(self.orc.get_health(), 100)
def test_is_alive_return_false(self):
self.orc.maxhealth = 0
self.assertFalse(self.orc.is_alive())
def test_is_alive(self):
self.assertTrue(self.orc.is_alive())
def test_take_damage(self):
self.assertEqual(80, self.orc.take_damage(20))
def test_take_damage_more_than_health(self):
self.assertEqual(0,self.orc.take_damage(120))
def test_take_healing_to_dead_person(self):
self.orc.maxhealth = 0
self.assertFalse(self.orc.take_healing(20))
def test_take_healing_more_than_enough(self):
self.orc.maxhealth = 90
self.assertFalse(self.orc.take_healing(100))
def test_take_healing_true(self):
self.orc.maxhealth = 40
def test_berserk_factor_below_one(self):
self.orc.berserk_factor = 0.5
self.assertEqual(self.orc.berserk_factor_check(), 1)
def test_berserk_factor_above_two(self):
self.orc.berserk_factor = 2.15
self.assertEqual(self.orc.berserk_factor_check(), 2)
示例6: TestFight
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例7: test_start_fight_both_alive
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
def test_start_fight_both_alive(self):
fight_map = Dungeon("fight_map.txt")
blademaster = Orc("Yurnero", 120, 1.2)
fight_map.spawn("player_1", self.paladin)
fight_map.spawn("player_2", blademaster)
fight_map.move("player_1", "right")
fight_map.move("player_2", "left")
fight_map.move("player_1", "right")
self.assertTrue(self.paladin.is_alive())
self.assertTrue(blademaster.is_alive())
示例8: test_fight
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例9: TestOrc
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
class TestOrc(unittest.TestCase):
def setUp(self):
self.pesho = Orc("Pesho", 100, 2.2)
def test_orc_init(self):
self.assertEqual(self.pesho.name, "Pesho")
self.assertEqual(self.pesho.health, 100)
self.assertEqual(self.pesho.berserk_factor, 2)
def test_get_health(self):
self.assertEqual(100, self.pesho.get_health())
def test_is_alive(self):
self.assertTrue(self.pesho.is_alive())
def test_is_alive_dead(self):
self.pesho.health = 0
self.assertFalse(self.pesho.is_alive())
def test_take_demage(self):
self.pesho.take_demage(10)
self.assertEqual(90, self.pesho.health)
def test_take_demage_two(self):
self.pesho.take_demage(110)
self.assertEqual(0, self.pesho.health)
def test_take_healing(self):
self.pesho.take_demage(100)
self.assertFalse(self.pesho.take_healing(10))
def test_take_healing_two(self):
self.pesho.take_demage(10)
self.pesho.take_healing(200)
self.assertEqual(100, self.pesho.health)
def test_take_healing_three(self):
self.pesho.take_demage(10)
self.pesho.take_healing(200)
self.assertTrue(self.pesho.is_alive())
示例10: FightTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例11: TestFight
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例12: test_start_fight_paladin_dead
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
def test_start_fight_paladin_dead(self):
axe = Weapon("axe", 10, 0.5)
blademaster = Orc("Yurnero", 120, 1.2)
blademaster.equip_weapon(axe)
fight_map = Dungeon("fight_map.txt")
fight_map.spawn("player_1", self.paladin)
fight_map.spawn("player_2", blademaster)
fight_map.move("player_1", "right")
fight_map.move("player_2", "left")
fight_map.move("player_1", "right")
expected_arr = [['.', '.', 'O', '.']]
self.assertFalse(self.paladin.is_alive())
self.assertTrue(blademaster.is_alive())
#testing _make_changes_after_fight
self.assertEqual(fight_map.map_array, expected_arr)
示例13: TestFight
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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())
示例14: game
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc 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
示例15: TestOrc
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import is_alive [as 别名]
class TestOrc(unittest.TestCase):
def setUp(self):
self.orc = Orc("orc", 90, 1.4)
def test_orc_init(self):
self.assertEqual(self.orc.name, "orc")
self.assertEqual(self.orc.health, 90)
self.assertEqual(self.orc.berserk_factor, 1.4)
def test_orc_init_weak_orc(self):
weak_orc = Orc("orc", 20, 0.2)
self.assertEqual(weak_orc.name, "orc")
self.assertEqual(weak_orc.health, 20)
self.assertEqual(weak_orc.berserk_factor, 1)
def test_orc_init_strong_orc(self):
strong_orc = Orc("orcc", 200, 20)
self.assertEqual(strong_orc.name, "orcc")
self.assertEqual(strong_orc.health, 200)
self.assertEqual(strong_orc.berserk_factor, 2)
def test_get_health(self):
self.assertEqual(self.orc.get_health(), 90)
def test_is_alive(self):
self.assertTrue(self.orc.is_alive())
def test_is_alive_with_dead(self):
self.orc.health = 0
self.assertFalse(self.orc.is_alive())
def test_take_damage(self):
self.orc.take_damage(50)
self.assertEqual(self.orc.health, 40)
def test_take_damage_max_dmg(self):
self.orc.take_damage(200)
self.assertEqual(self.orc.health, 0)
self.orc.take_damage(20)
self.assertEqual(self.orc.health, 0)
def test_take_healing_on_dead(self):
self.orc.health = 0
self.assertFalse(self.orc.take_healing(100))
def test_take_healing_above_maximum_health(self):
self.orc.take_healing(1 + self.orc._MAX_HEALTH)
self.assertTrue(self.orc.take_healing(1 + self.orc._MAX_HEALTH))
self.assertEqual(self.orc.health, self.orc._MAX_HEALTH)
def test_take_healing(self):
self.orc.health = 20
self.assertTrue(self.orc.take_healing(20))
self.assertEqual(self.orc.health, 40)
def test_attack(self):
weapon = Weapon("Mighty Axe", 25, 0.2)
self.orc.equip_weapon(weapon)
if self.orc.weapon.critical_hit():
self.assertEqual(self.orc.attack(), self.orc.weapon.damage * self.orc.berserk_factor *2)
else:
self.assertEqual(self.orc.attack(), self.orc.weapon.damage * self.orc.berserk_factor)