本文整理汇总了Python中dungeon.Dungeon.go_to_field方法的典型用法代码示例。如果您正苦于以下问题:Python Dungeon.go_to_field方法的具体用法?Python Dungeon.go_to_field怎么用?Python Dungeon.go_to_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dungeon.Dungeon
的用法示例。
在下文中一共展示了Dungeon.go_to_field方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DungeonTests
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import go_to_field [as 别名]
#.........这里部分代码省略.........
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
[['.', '.', 'O', '.', '.']] == self.dungeon.dungeon)
def test_go_to_field(self):
self.dungeon.dungeon = [['.', '.', '.'],
['.', 'S', '.'],
['.', '.', '.']]
self.assertEqual((1, 0), self.dungeon.go_to_field(1, 1, "up"))
self.assertEqual((1, 2), self.dungeon.go_to_field(1, 1, "down"))
self.assertEqual((2, 1), self.dungeon.go_to_field(1, 1, "right"))
self.assertEqual((0, 1), self.dungeon.go_to_field(1, 1, "left"))
def test_go_to_field_out_of_bounds(self):
self.assertFalse(self.dungeon.go_to_field(0, 0, "down"))
def test_go_to_field_wrong_direction(self):
with self.assertRaises(ValueError):
self.dungeon.go_to_field(0, 0, "tomatoe")
def test_entity_at_field(self):
self.dungeon.spawn("player 1", self.hero)
self.dungeon.spawn("player 2", self.orc)
self.assertEqual(("player 2", self.orc),
self.dungeon.entity_at_field(4, 0))
def test_spawn_weapons(self):
self.dungeon.dungeon = [['S', '.']]
weapon = Weapon("Knife", 7, 0.3)
self.dungeon.weapons = [weapon]
self.dungeon.spawn_weapons()
self.assertEqual([['S', 'W']], self.dungeon.dungeon)
self.assertEqual((weapon, 1, 0), self.dungeon.weapons[0])
def test_generate_coordinates(self):
coord = self.dungeon.generate_coordinates()
self.assertEqual('.', self.dungeon.dungeon[coord[1]][coord[0]])
def test_get_weapon(self):
self.dungeon.dungeon = [['S', '.']]
weapon = Weapon("Knife", 7, 0.3)
self.dungeon.weapons = [weapon]
self.dungeon.spawn_weapons()
self.assertEqual(weapon, self.dungeon.get_weapon(1, 0))
self.assertTrue((weapon, 1, 0) not in self.dungeon.weapons)
def tearDown(self):
remove("test_file.txt")