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


Python Dungeon.get_map方法代码示例

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


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

示例1: DungeonTest

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import get_map [as 别名]
class DungeonTest(unittest.TestCase):
    """Simulation dungeon"""
    def setUp(self):
        file_path = "basic_dungeon.txt"
        self.my_dungeon = Dungeon(file_path)
        self.dungeon_map = {
            0: list("S.##......"),
            1: list("#.##..###."),
            2: list("#.###.###."),
            3: list("#.....###."),
            4: list("###.#####S")
        }

        self.my_hero = Hero("Tedi", 100, "Da Geek")
        super_laptop = Weapon("Mind-Control Super-Laptop", 20, 0.5)
        self.my_hero.equip_weapon(super_laptop)
        self.my_orc = Orc("Shrek", 100, 2)
        ugly_weapon = Weapon("Bludgeon", 10, 0.5)
        self.my_orc.equip_weapon(ugly_weapon)

    def test_init_dungeon(self):
        self.assertEqual(self.dungeon_map, self.my_dungeon.get_map())

    def test_spawn_hero(self):
        self.assertTrue(self.my_dungeon.spawn("HackTedi", self.my_hero))
        dungeon_map = self.my_dungeon.get_map()
        self.dungeon_map[0][0] = 'H'
        self.assertEqual(self.dungeon_map, dungeon_map)

    def test_spawn_orc(self):
        self.assertTrue(self.my_dungeon.spawn("UglyOrc", self.my_orc))
        dungeon_map = self.my_dungeon.get_map()
        self.dungeon_map[0][0] = 'O'
        self.assertEqual(self.dungeon_map, dungeon_map)

    def test_spawn_hero_and_orc(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.spawn("UglyOrc", self.my_orc)
        dungeon_map = self.my_dungeon.get_map()
        self.dungeon_map[0][0] = 'H'
        self.dungeon_map[4][9] = 'O'
        self.assertEqual(self.dungeon_map, dungeon_map)

    def test_spawn_more_than_available(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.spawn("UglyOrc", self.my_orc)
        self.assertTrue(not self.my_dungeon.spawn("UglyOrc2", self.my_orc))

    def test_move(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.move("HackTedi", "right")
        self.dungeon_map[0][0] = "."
        self.dungeon_map[0][1] = "H"
        dungeon_map = self.my_dungeon.get_map()
        self.assertEqual(self.dungeon_map, dungeon_map)

        players = self.my_dungeon.get_players()
        self.assertEqual(players["HackTedi"]["position"], (0, 1))

    def test_move_into_obstacle(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.assertTrue(not self.my_dungeon.move("HackTedi", "down"))
        players = self.my_dungeon.get_players()
        self.assertEqual(players["HackTedi"]["position"], (0, 0))

    def test_move_outside_map(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.assertTrue(not self.my_dungeon.move("HackTedi", "up"))
        players = self.my_dungeon.get_players()
        self.assertEqual(players["HackTedi"]["position"], (0, 0))

    def test_move_into_enemy(self):
        file_path = "basic_dungeon_for_fight.txt"
        self.my_dungeon = Dungeon(file_path)

        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.spawn("UglyOrc", self.my_orc)
        self.my_dungeon.move("HackTedi", "right")
        map_string = ""
        dungeon_map = self.my_dungeon.get_map()
        for row in dungeon_map:
            map_string += "".join(dungeon_map[row]) + "\n"
        self.assertTrue(map_string == ".H\n" or map_string == ".O\n")

        players = self.my_dungeon.get_players()
        self.assertEqual(1, len(players))
开发者ID:tblazhev,项目名称:HackBulgaria-Programming101,代码行数:88,代码来源:dungeon_tests.py


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