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


Python Graphics.show_stats方法代码示例

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


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

示例1: Game

# 需要导入模块: from graphics import Graphics [as 别名]
# 或者: from graphics.Graphics import show_stats [as 别名]
class Game(object):
    ''' Handles a game instance '''

    def __init__(self):
        ''' Initialize starting state'''
        self.graphics = Graphics()
        self.log = logging.getLogger("Game");
        logging.basicConfig(filename='main.log', level=DEBUG_LEVEL)
        self.log_handler = CursesHandler(self.graphics.windows["log"])
        self.log_handler.setLevel(DEBUG_LEVEL)
        self.log.addHandler(self.log_handler)
        self.commands = Commands(self)
        self.cursor_pos = [0,0]
        self.game_mode = GameModes.normal
        self.world = World(log_handler=self.log_handler)

        try:
            # Try to load a level from a text file and add it to the world
            # self.world.add_level(self.world.read_level('../data/testworld'))
            # self.world.get_current_level().add_entity(entity.creatures.SpaceOrk(5,5))
            self.world.add_level(
                    self.world.generate_level(
                        self.graphics.max_x, self.graphics.world_height))

            #Place player at spawn
            self.player = entity.creatures.Player(1,1)
            for ent in self.world.get_current_level().entities:
                if ent.__class__ == entity.world.PlayerSpawn:
                    self.player = entity.creatures.Player(ent.position[0],ent.position[1])

            self.world.get_current_level().add_entity(self.player)
        except Exception:
            # use better exception
            self.exit(1)

        self.log.debug("Game started")

    def run(self):
        ''' Draw the world and get input '''
        try:
            self.graphics.draw_world(self.world)
            self.graphics.show_stats(self.player)
            self.graphics.update()
            while True:
                self.parse_command(self.graphics.get_input())
                if self.game_mode == GameModes.cursor or self.game_mode == GameModes.look:
                    self.graphics.clear()
                    self.graphics.draw_world(self.world)
                    self.graphics.draw_cursor(self.cursor_pos)
                if self.game_mode == GameModes.look:
                    for ent in self.world.get_current_tile(self.cursor_pos):
                        self.log.info(ent.name)
                self.graphics.show_stats(self.player)
                self.graphics.update()
        except (Exception, KeyboardInterrupt):
            self.exit(1)

    def turn(self):
        ''' Take a turn; redraw world, run ai... '''
        try:
            for ent in self.world.get_current_level().entities:
                if hasattr(ent, "die"):
                    if ent.die():
                        continue
                if issubclass(ent.__class__, entity.base.Creature):
                    ent.turn(self.player)
            self.graphics.clear()
            self.graphics.draw_world(self.world)
        except (Exception, KeyboardInterrupt):
            self.exit(1)



    def exit(self, status):
        ''' Shutdown curses, close files, and print errors if any'''
        self.log.debug("exiting")
        self.graphics.exit()
        if sys.exc_info()[2] is not None:
            print(traceback.format_exc())
        sys.exit(status)


    def parse_command(self, command):
        ''' Executes the function associated with a command string '''
        self.log.debug(command)
        if hasattr(self.commands, command):
            try:
                self.commands.__class__.__dict__[command](self.commands)
            except (Exception, KeyboardInterrupt):
                self.exit(1)
        else:
            self.log.error("Command not found")
开发者ID:ottopasuuna,项目名称:cyberogue,代码行数:94,代码来源:game.py


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