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


Python Dungeon._get_row_length方法代码示例

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


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

示例1: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import _get_row_length [as 别名]
class TestDungeon(unittest.TestCase):

    def setUp(self):
        self.existing_file = str(uuid4)
        self.test_map = \
            "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S"
        with open(self.existing_file, "w") as writeFile:
            writeFile.write(self.test_map)
        self.dungeon = Dungeon(self.existing_file)

        self.hero = Hero("Hero", 100, "Nick")
        self.orc = Orc("Orc", 100, 2)

    def tearDown(self):
        remove(self.existing_file)

    def test_dungeon_init_existing_file(self):
        self.assertEqual(self.dungeon.map, self.test_map)
        self.assertEqual(10, self.dungeon._get_row_length())

    def test_dungeon_init_nonexisting_file(self):
        fileName = str(uuid4())
        with self.assertRaises(FileNotFoundError):
            Dungeon(fileName)

    def test_spawn_success(self):
        self.assertTrue(self.dungeon.spawn("the_hero", self.hero))
        self.test_map = self.test_map.replace("S", "H", 1)
        self.assertEqual(self.dungeon.map, self.test_map)
        self.assertEqual(self.dungeon.player_pos["the_hero"], 0)

        self.assertTrue(self.dungeon.spawn("the_orc", self.orc))
        self.test_map = self.test_map.replace("S", "O", 1)
        self.assertEqual(self.dungeon.map, self.test_map)
        self.assertEqual(self.dungeon.player_pos["the_orc"],
                         len(self.test_map) - 1)

    def test_spawn_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.spawn("new_hero", self.hero))

    def test_spawn_type_error(self):
        with self.assertRaises(TypeError):
            self.dungeon.spawn("Dingo")

    def test_move_invalid_direction(self):
        self.dungeon.spawn("the_hero", self.hero)

        with self.assertRaises(ValueError):
            self.dungeon.move("the_hero", "dooooooown")

    def test_move_invalid_player_name(self):
        with self.assertRaises(ValueError):
            self.dungeon.move("invalid", "down")

    def test_move_right_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.assertTrue(self.dungeon.move("the_hero", "right"))

    def test_move_right_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.move("the_orc", "right"))

    def test_move_left_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.move("the_hero", "right")
        self.assertTrue(self.dungeon.move("the_hero", "left"))

    def test_move_left_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.move("the_hero", "left"))
        self.assertFalse(self.dungeon.move("the_orc", "left"))

    def test_move_up_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertTrue(self.dungeon.move("the_orc", "up"))

    def test_move_up_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.assertFalse(self.dungeon.move("the_hero", "up"))

    def test_move_down_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.move("the_hero", "right")
        self.assertTrue(self.dungeon.move("the_hero", "down"))
        self.assertTrue(self.dungeon.move("the_hero", "down"))

    def test_move_down_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.move("the_hero", "down"))
        self.assertFalse(self.dungeon.move("the_orc", "down"))

    def test_move_fight(self):
        self.dungeon.map = self.dungeon.map.replace(".", "S", 1)
        self.dungeon.spawn("the_hero", self.hero)
#.........这里部分代码省略.........
开发者ID:antonpetkoff,项目名称:Programming101,代码行数:103,代码来源:dungeon_test.py


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