本文整理汇总了Python中dungeon.Dungeon.spawn_weapons方法的典型用法代码示例。如果您正苦于以下问题:Python Dungeon.spawn_weapons方法的具体用法?Python Dungeon.spawn_weapons怎么用?Python Dungeon.spawn_weapons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dungeon.Dungeon
的用法示例。
在下文中一共展示了Dungeon.spawn_weapons方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DungeonTests
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import spawn_weapons [as 别名]
class DungeonTests(unittest.TestCase):
def setUp(self):
file = open("test_file.txt", "w")
content = ["S...S", "", "Spoon 4 0.2", "RustyFork 6 0.7"]
file.write("\n".join(content))
file.close()
self.dungeon = Dungeon("test_file.txt")
self.hero = Hero("Don Quixote", 20, "The Common Sense")
self.orc = Orc("Oplik", 20, 1.5)
def test_init(self):
self.assertEqual([['S', '.', '.', '.', 'S']], self.dungeon.dungeon)
weapons = list(map(lambda x: x.type, deepcopy(self.dungeon.weapons)))
self.assertEqual(["Spoon", "RustyFork"], weapons)
self.assertEqual({}, self.dungeon.players)
def test_load_map(self):
self.assertEqual([['S', '.', '.', '.', 'S']],
self.dungeon.load_map("test_file.txt"))
def test_is_map_row(self):
self.assertTrue(self.dungeon.is_map_row("#..S..#"))
self.assertFalse(self.dungeon.is_map_row("##Not.really.a.row"))
def test_set_weapons(self):
self.dungeon.weapons = []
self.dungeon.set_weapons(["Knife 7 0.3"])
self.assertEqual("Knife", self.dungeon.weapons[0].type)
self.assertEqual(7.0, self.dungeon.weapons[0].damage)
self.assertEqual(0.3, self.dungeon.weapons[0].critical_strike_percent)
def test_print_map(self):
self.assertTrue(self.dungeon.print_map())
def test_free_spawning_points(self): # help function
self.dungeon.dungeon = [['T'], ['T']]
self.assertFalse(self.dungeon.free_spawning_points())
self.dungeon.dungeon = [['T'], ['S']]
self.assertTrue(self.dungeon.free_spawning_points())
def test_spawn(self):
self.assertTrue(self.dungeon.spawn("player 1", self.hero))
self.assertTrue(self.dungeon.spawn("player 2", self.orc))
self.assertEqual({"player 1": (self.hero, 0, 0),
"player 2": (self.orc, 4, 0)}, self.dungeon.players)
def test_spawn_player_not_unique_value_error(self):
self.dungeon.spawn("player 1", self.hero)
with self.assertRaises(ValueError):
self.dungeon.spawn("player 1", self.hero)
def test_spawn_no_spawning_points(self):
self.dungeon.dungeon = [['.', '.']]
self.assertFalse(self.dungeon.spawn("player 1", self.hero))
def test_entity_kind(self):
self.assertEqual('H', self.dungeon.entity_kind(self.hero))
self.assertEqual('O', self.dungeon.entity_kind(self.orc))
def test_entity_kind_wrong_instance(self):
with self.assertRaises(ValueError):
self.dungeon.entity_kind("tomatoe")
def test_move(self):
self.dungeon.dungeon = [['S', '.']]
self.dungeon.spawn("player", self.hero)
self.dungeon.move("player", "right")
self.assertEqual([['.', 'H']], self.dungeon.dungeon)
def test_move_obstacle(self):
self.dungeon.dungeon = [['S', '#']]
self.dungeon.spawn("player", self.hero)
self.assertFalse(self.dungeon.move("player", "right"))
def test_move_out_of_bounds(self):
self.dungeon.spawn("player", self.hero)
self.assertFalse(self.dungeon.move("player", "up"))
def test_move_weapon_found(self):
self.dungeon.dungeon = [['S', '.']]
weapon = Weapon("Knife", 7, 0.3)
self.dungeon.weapons = [weapon]
self.dungeon.spawn_weapons()
self.dungeon.spawn("player", self.hero)
self.dungeon.move("player", "right")
self.assertEqual(weapon, self.dungeon.players["player"][0].weapon)
self.assertEqual([['.', 'H']], self.dungeon.dungeon)
def test_move_start_fight(self):
self.dungeon.spawn("player 1", self.hero)
self.dungeon.spawn("player 2", self.orc)
self.dungeon.spawn_weapons()
self.dungeon.move("player 1", "right")
self.dungeon.move("player 1", "right")
self.dungeon.move("player 2", "left")
self.dungeon.move("player 2", "left")
self.assertTrue([['.', '.', 'H', '.', '.']] == self.dungeon.dungeon or
#.........这里部分代码省略.........