當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。