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


Python Monster.set_location方法代码示例

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


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

示例1: __init__

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import set_location [as 别名]
class Game:

    def __init__(self):
        """
        Sets up a game gui with the player and starts it
        :return:
        """
        pygame.init()
        self.view = View()
        self.map = Map()
        self.map.player = Player()
        self.map.player_loc = (1*TILE_SIZE, 1*TILE_SIZE)
        self.player = self.map.player
        self.player.set_location(self.map.player_loc)
        #self.time = pygame.time.Clock()
        self.map.set_player_location(self.map.player_loc)
        self.treasure = Treasure()
        self.inventory_button = Button("Inventory", 480, 0, 20, 20)
        self.save_button = Button("Save", 590, 0, 20, 20)
        self.load_button = Button("Load", 590, 50, 20, 20)
        self.view.draw_layers(self.map, self.treasure, self.map.player.inventory, self.inventory_button, self.save_button, self.load_button)
        self.monster = Monster()
        self.map.monster_loc = self.monster.loc
        while self.map.set_monster_location(self.monster.loc) is False:
            self.monster.set_location()
        self.map.treasure_loc = self.treasure.x_y
        while self.map.add_item(self.treasure.x_y) is False:
            self.treasure = Treasure()

    def move_player(self, direction):
        """
        Moves the player in a certain direction given a keypress
        :param direction: direction to move in
        :return:
        """
        oldx, oldy = self.map.player_loc
        x, y = oldx + direction[0], oldy + direction[1]
        x_limit = (ROW-1) * TILE_SIZE
        y_limit = (COLUMN-1) * TILE_SIZE
        #don't do anything if the location is too much
        if x > x_limit or x < 0 or y > y_limit or y < 0:
            return
        ret_move_player = self.map.set_player_location((x, y))
        self.player.set_location((x, y))
        if ret_move_player is True:
            self.map.player.add_to_inventory(self.treasure.item)
            self.treasure = Treasure()
            self.map.treasure_loc = self.treasure.x_y
            print(self.map.player.inventory.get_items())
            self.map.add_item(self.treasure.x_y)
        elif ret_move_player is 2:
            print("COMBAT")
            hp = Combat(self.map.player, self.monster, self.view).init_combat()
            print(hp)
            if hp[0] <= 0:
                self.end_game()
                return False
                #self.quit()
            else:
                self.map.player.hp = hp[0]
            self.monster = Monster()
            while self.map.set_monster_location(self.monster.loc) is False:
                self.monster.set_location()
            self.map.monster_loc = self.monster.loc
            self.map.add_monster(self.monster.loc)

    def get_inventory(self):
        """
        Gets the inventory. This is called when the button is clicked
        :return:
        """
        self.view.draw_inventory(self.player.inventory)
        pygame.display.flip()

    def refresh(self, inventory):
        """
        Refreshes the current view
        :param inventory: inventory to include
        :return:
        """
        self.view.draw_player(self.map.player_loc)
        self.view.draw_monster(self.map.monster_loc)
        self.view.draw_layers(self.map, self.treasure, inventory, self.inventory_button, self.save_button, self.load_button)

    def end_game(self):
        """
        Returns a game over screen
        :return:
        """
        self.view.draw_end_game()

    def quit(self):
        """
        Simple end game thing
        :return:
        """
        sys.exit()

#Game()
开发者ID:dguan4,项目名称:HanStory,代码行数:101,代码来源:game.py


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