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


Python Dungeon.convert_map_to_changeable_tiles方法代码示例

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


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

示例1: DungeonTest

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

    def setUp(self):
        self.mapfile = "testmap.txt"
        self.mapcontents = """ZZZZZZZZZZZZZZZZZZZ\nZ#...#.##.########Z
Z#.S.#.....N....K.Z\nZ#...#..#.....####Z
Z#...#..#.....N..#Z\nZ....#..#......#.#Z
Z#......#..N...#.#Z\nZ..............#C#Z
Z..###########....Z\nZZZZZZZZZZZZZZZZZZZ"""
        with open(self.mapfile, "w+") as f:
            f.write(self.mapcontents)

        self.dungeon = Dungeon("testmap.txt")
        self.hero = Hero("Arthas", 500, "Lich King")
        self.orc = Orc("Thrall", 500, 1.6)

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

    def test_init(self):
        self.assertEqual(self.dungeon.map, self.mapcontents)

    def test_load_map_with_valid_file(self):
        result = self.dungeon.load_map("testmap.txt")
        self.assertEqual(result, self.mapcontents)

    def test_load_map_with_invalid_file(self):
        result = self.dungeon.load_map("not_exists.txt")
        self.assertEqual(result, "")

    def test_map_with_empty_file(self):
        with open(self.mapfile, "w") as f:
            f.write("")

        result = self.dungeon.load_map("testmap.txt")
        self.assertEqual(result, "")

    def test_print_map_with_valid_file(self):
        result = self.dungeon.print_map()
        self.assertEqual(result, self.mapcontents)

    def test_print_map_with_empty_file(self):
        self.dungeon.map = ""
        result = self.dungeon.print_map()
        self.assertEqual(result, "No valid map loaded.")

    def test_print_map_after_battle(self):
        hero = Hero("Alan", 1, "Turing")
        hero.weapon = Weapon("Stick", 1, 0.1)
        self.dungeon.map = "ZSNZ"
        self.dungeon.spawn("1", hero)
        self.dungeon.spawn_npcs()

        self.dungeon.move_player("1", "right")
        self.assertEqual(self.dungeon.map, "Z.OZ")

    def test_valid_spawn(self):
        self.dungeon.spawn("Player 1", self.hero)
        contents = """ZZZZZZZZZZZZZZZZZZZ\nZ#...#.##.########Z
Z#.H.#.....N....K.Z\nZ#...#..#.....####Z
Z#...#..#.....N..#Z\nZ....#..#......#.#Z
Z#......#..N...#.#Z\nZ..............#C#Z
Z..###########....Z\nZZZZZZZZZZZZZZZZZZZ"""
        self.assertEqual(self.dungeon.map, contents)

    def test_spawn_when_char_is_ingame(self):
        self.dungeon.spawn("Player 1", self.hero)
        result = self.dungeon.spawn("Player 1", self.hero)
        self.assertEqual(result, "Character is already spawned.")

    def test_spawn_when_no_free_slots(self):
        self.dungeon.spawn("Player 1", self.hero)
        self.dungeon.spawn("Player 2", self.orc)
        testchar = Hero("Arthas", 200, "Lich")
        result = self.dungeon.spawn("Player 3", testchar)
        self.assertEqual(result, "No free spawn slot.")

    def test_map_conversion(self):
        actual = [["Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z",
                   "Z", "Z", "Z", "Z", "Z", "Z", "Z"],
                  ["Z", "#", ".", ".", ".", "#", ".", "#", "#", ".", "#", "#",
                   "#", "#", "#", "#", "#", "#", "Z"],
                  ["Z", "#", ".", "S", ".", "#", ".", ".", ".", ".", ".", "N",
                   ".", ".", ".", ".", "K", ".", "Z"],
                  ["Z", "#", ".", ".", ".", "#", ".", ".", "#", ".", ".", ".",
                   ".", ".", "#", "#", "#", "#", "Z"],
                  ["Z", "#", ".", ".", ".", "#", ".", ".", "#", ".", ".", ".",
                   ".", ".", "N", ".", ".", "#", "Z"],
                  ["Z", ".", ".", ".", ".", "#", ".", ".", "#", ".", ".", ".",
                  ".", ".", ".", "#", ".", "#", "Z"],
                  ["Z", "#", ".", ".", ".", ".", ".", ".", "#", ".", ".", "N",
                   ".", ".", ".", "#", ".", "#", "Z"],
                  ["Z", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".",
                   ".", ".", ".", "#", "C", "#", "Z"],
                  ["Z", ".", ".", "#", "#", "#", "#", "#", "#", "#", "#", "#",
                   "#", "#", ".", ".", ".", ".", "Z"],
                  ["Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z",
                   "Z", "Z", "Z", "Z", "Z", "Z", "Z"]]
        result = self.dungeon.convert_map_to_changeable_tiles()
        self.assertEqual(result, actual)
#.........这里部分代码省略.........
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:103,代码来源:test_all.py

示例2: GraphicalUserInterface

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import convert_map_to_changeable_tiles [as 别名]
class GraphicalUserInterface():
    def __init__(self):
        self.exit = False
        self.is_created = False
        self.map_loaded = False
        self.validator = None
        self.input = None

        self.colors = {"Z": "grey", "#": "black", ".": "white", "H": "green",
                       "O": "red", "C": "brown", "K": "yellow",
                       "S": "blue", "N": "red"}
        self.color_codes = {
            "black": (0, 0, 0), "white": (255, 255, 255), "green": (0, 255, 0),
            "red": (255, 0, 0), "brown": (153, 76, 0), "yellow": (255, 255, 0),
            "blue": (0, 0, 255), "grey": (128, 128, 128)}

    def load_map(self, map_path):
        self.validator = MapValidator(map_path)
        if not self.validator.validate_map():
            return self.validator.generate_message()
        else:
            self.dungeon = Dungeon(map_path)
            if self.dungeon.map:
                self.map_loaded = True
                self.grid = self.dungeon.convert_map_to_changeable_tiles()
                self.map_row = len(self.grid)
                self.map_col = len(self.grid[0])
                return self.validator.generate_message()

    def display_map(self):
        cell_width = 20
        cell_height = 20
        cell_margin = 5

        scr_width = (cell_margin + cell_width) * self.map_col + cell_margin
        scr_height = (cell_margin + cell_height) * self.map_row + cell_margin

        ss = [scr_width, scr_height]
        screen = pygame.display.set_mode(ss)

        pygame.display.set_caption("Treasure Dungeon")
        pygame.init()
        for row in range(self.map_row):
            for column in range(self.map_col):
                color = self.color_codes[self.colors[self.grid[row][column]]]
                pygame.draw.rect(
                    screen,
                    color,
                    [(cell_margin + cell_width) * column + cell_margin,
                     (cell_margin + cell_height) * row + cell_margin,
                     cell_width, cell_height])
        done = False
        # # Used to manage how fast the screen updates
        # clock = pygame.time.Clock()

        pygame.display.flip()

        # make this global for every object
        while not done:
            for event in pygame.event.get():
                print(event.type)
                if event.type == pygame.QUIT:
                    done = True

        pygame.quit()

    def start(self):
        self.display_map()
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:70,代码来源:GUI.py


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