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


Python Effect.__del__方法代码示例

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


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

示例1: TestPlayer

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import __del__ [as 别名]
class TestPlayer(unittest.TestCase):

	def setUp(self):
		self.default_effect = Effect(Damage(5,5), Damage(5,5), Stats(5,5,5,5))
		self.default_weapon = Item("Rusty Sword", self.default_effect, "WEAPON", 2)
		self.default_armor = Item("Leather Armor", self.default_effect, "ARMOR", 2)
		self.test_player = Player("Alice", Stats(1,1,1,1), 10, "female", 1, Race("Human"), self.default_weapon, self.default_armor)
		

	def tearDown(self):
		self.test_player.__del__()
		self.default_effect.__del__()
		self.default_armor.__del__()
		self.default_weapon.__del__()

	# test default init
	def test_init(self):
		self.assertEqual(self.test_player.name, 'Alice')

	def test_total_defense(self):
		# magic = weapon: 5 + armor: 5 + total_int: 13 + race: 25
		# physical = weapon: 5 + armor: 5 + total_strength: 13 + race: 25
		self.assertEqual(self.test_player.total_defense(), (48,48))

	def test_total_attack(self):
		# magic = weapon: 5 + armor: 5 + total_int: 13
		# physical = weapon: 5 + armor: 5 + total_str: 13
		self.assertEqual(self.test_player.total_attack(), (23,23))

	def test_total_strength(self):
		# base: 1 + race: 2 + weapon: 5 + armor: 5
		self.assertEqual(self.test_player.total_strength(), 13)

	def test_total_hp(self):
		# base: 1 + race: 0 + armor: 5 + weapon: 5
		self.assertEqual(self.test_player.total_hp(), 11)

	def test_total_intelligence(self):
		# base: 1 + race: 2 + armor: 5 + weapon: 5
		self.assertEqual(self.test_player.total_intelligence(), 13)

	def test_total_agility(self):
		# base: 1 + race: 1 + armor: 5 + weapon: 5
		self.assertEqual(self.test_player.total_agility(), 12)

	def test_dodge_chance(self):
		# total_agility / 100
		self.assertEqual(self.test_player.dodge_chance(), .12)

	def test_critical_chance(self):
		# total_agility / 100
		self.assertEqual(self.test_player.critical_chance(), .12)

	def test_critical_damage(self):
		# total_damage + round(total_damage*critical_chance)
		self.assertEqual(self.test_player.critical_damage(), (25,25))

	def test_level_up_valid(self):
		self.test_player.level_up((1,0,0))
		self.assertEqual(self.test_player.get_stats().strength, 2)

	def test_level_up_invalid(self):
		self.test_player.level_up((1,1,1))
		expected_stats = Stats(1,1,1,1)
		self.assertEqual(self.test_player.get_stats(), expected_stats)

	def test_add_gold(self):
		self.test_player.add_gold(1)
		self.assertEqual(11, self.test_player.get_gold())

	def test_new_weapon(self):
		new_weapon = Item("Axe", self.default_effect, 'WEAPON', 5)
		self.test_player.replace_weapon(new_weapon)
		self.assertEqual(new_weapon, self.test_player.weapon)

	def test_new_armor(self):
		new_armor = Item("Iron Armor", self.default_effect, 'ARMOR', 5)
		self.test_player.replace_armor(new_armor)
		self.assertEqual(new_armor, self.test_player.armor)

	def test_str(self):
		armor_string = str(self.test_player.armor)
		weapon_string = str(self.test_player.weapon)
		stats_string = str(self.test_player.stats)
		summary_string = 'Alice - 1...10g'
		expected = '{}\t{}\n\t{}\n\t{}'.format(summary_string, stats_string, weapon_string, armor_string)
		self.assertEqual(self.test_player.__str__(), expected)
开发者ID:brandonDeen,项目名称:Text_RPG_Python,代码行数:89,代码来源:player_test.py


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