本文整理汇总了Python中Entity.Entity.is_alive方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.is_alive方法的具体用法?Python Entity.is_alive怎么用?Python Entity.is_alive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity.Entity
的用法示例。
在下文中一共展示了Entity.is_alive方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEntityClass
# 需要导入模块: from Entity import Entity [as 别名]
# 或者: from Entity.Entity import is_alive [as 别名]
class TestEntityClass(unittest.TestCase):
def setUp(self):
self.entity = Entity('Baba', 100)
def test_initialisation_atributes(self):
self.assertEqual(self.entity.name, 'Baba')
self.assertEqual(self.entity.health, 100)
def test_get_health(self):
self.assertEqual(self.entity.get_health(), 100)
def test_is_alive(self):
self.assertTrue(self.entity.is_alive())
self.entity = Entity('Baba', 0)
self.assertFalse(self.entity.is_alive())
def test_take_damage(self):
self.assertTrue(self.entity.take_damage(50))
self.assertEqual(self.entity.get_health(), 50)
self.assertTrue(self.entity.take_damage(51))
self.assertEqual(self.entity.get_health(), 0)
self.assertFalse(self.entity.take_damage(10))
def test_take_healing(self):
self.assertTrue(self.entity.take_healing(100))
self.assertEqual(self.entity.get_health(), 100)
self.entity.take_damage(50)
self.assertTrue(self.entity.take_healing(40))
self.assertEqual(self.entity.get_health(), 90)
self.entity = Entity('Baba', 0)
self.assertFalse(self.entity.take_healing(100))
def test_has_weapon(self):
self.assertFalse(self.entity.has_weapon())
def test_equip_weapon(self):
sword = Weapon('Sword', 100, 0.4)
sword2 = Weapon('Sword', 100, 0.4)
self.entity.equip_weapon(sword)
self.assertTrue(self.entity.has_weapon())
self.assertEqual(self.entity.weapon, sword)
self.entity.equip_weapon(sword2)
self.assertNotEqual(self.entity.weapon, sword)
def test_attack(self):
self.assertEqual(self.entity.attack(), 0)
sword = Weapon('Sword', 100, 0)
self.entity.equip_weapon(sword)
self.assertEqual(self.entity.attack(), 100)
sword = Weapon('Sword', 100, 1)
self.entity.equip_weapon(sword)
self.assertEqual(self.entity.attack(), 200)
示例2: Test_Entity
# 需要导入模块: from Entity import Entity [as 别名]
# 或者: from Entity.Entity import is_alive [as 别名]
class Test_Entity(unittest.TestCase):
def setUp(self):
self.entity = Entity("Kung-Fu Balhar", 100)
self.otherentity = Entity("Balha", 100)
self.entity.weapon = Weapon("Kaish", 50, 0.5)
def test_entity_name(self):
output = "Kung-Fu Balhar"
result = self.entity.name
self.assertEqual(result, output)
def test_get_entity_health(self):
output = 100
result = self.entity.get_health()
self.assertEqual(result, output)
def test_is_entity_alive(self):
self.assertTrue(self.entity.is_alive())
def test_entity_take_damage(self):
health_left = 60
damage = 40
result = self.entity.get_health() - damage
self.assertEqual(health_left, result)
def test_entity_take_healing_when_not_dead_and_has_max_hp(self):
self.assertFalse(self.entity.take_healing(10))
def test_entity_take_healing_when_not_dead_and_has_less_than_max_hp(self):
self.entity.health -= 10
self.assertTrue(self.entity.take_healing(10))
def test_entity_take_healing_when__dead(self):
self.entity.health -= 100
self.assertFalse(self.entity.take_healing(10))
def test_has_weapon_when_weapon_not_equipped(self):
result = self.otherentity.has_weapon()
self.assertFalse(result)
def test_has_weapon_when_weapon_equipped(self):
self.weapon = Weapon("Mighty Axe", 25, 0.2)
self.entity.equip_weapon(self.weapon)
result = self.entity.has_weapon()
self.assertTrue(result)
def test_equip_weapon(self):
self.weapon = Weapon("Mighty Axe", 25, 0.2)
result = self.entity.equip_weapon(self.weapon)
self.assertTrue(result)
def test_damage_of_entity_when_weapon_equipped(self):
self.assertEqual(self.entity.attack(), 50)
def test_damage_of_entity_when_weapon_not_equipped(self):
self.assertEqual(self.otherentity.attack(), 0)
示例3: test_is_alive
# 需要导入模块: from Entity import Entity [as 别名]
# 或者: from Entity.Entity import is_alive [as 别名]
def test_is_alive(self):
my_entity = Entity("Furious", 100)
my_entity.health = 0
self.assertFalse(my_entity.is_alive())