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


Python Stopwatch.restart方法代码示例

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


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

示例1: Game

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import restart [as 别名]
class Game(PygameGame):
    def __init__(self):
        width = 800
        height = 500
        fps = 40
        fullCh = 255
        bgColor = (fullCh, fullCh, fullCh)
        title = "Bouncy Bouncy Revamped"
        super().__init__(width, height, fps, title, bgColor)

    def initStyles(self):
        assert(pygame.font.get_init())
        assert(pygame.image.get_extended())
        self.font = Struct()
        textSize = 16
        self.font.text = pygame.font.SysFont("Arial", textSize)
        titleSize = 30
        self.font.title = pygame.font.SysFont("Arial", titleSize)
        self.font.titleEmph = pygame.font.SysFont("Arial", titleSize,
            bold=True, italic=True)
        self.margin = 10

    def initMaps(self):
        self.maps = Maps(self.margin + 100, self.margin,
            self.width - 2*self.margin, self.height - 2*self.margin)
        self.progress = Progress(self.maps.levels, self)

    def initMainMenu(self):
        top = 130
        left = 80
        entries = ["Play", "Level select", "Instructions"]
        actions = [self.playLevel, self.doLevelMenu, self.doHelp]
        self.mainMenu = Menu(left, top, entries, actions)

    def initLevelMenu(self):
        top = 60
        left = 130
        entries = []
        actions = []
        for i, level in enumerate(self.maps.levels):
            prevLevel = self.maps.levels[i - 1]
            if i > 0 and self.progress[prevLevel]["score"] == None:
                entries.append("Level %s    Locked" % level)
                actions.append(None)
                continue
            elif self.progress[level]["score"] == None:
                entries.append("Level %s    Unlocked" % level)
            else:
                entries.append("Level %s    Highscore: %d    Best time: %s" %
                    (level, self.progress[level]["score"],
                        Stopwatch.secToMin(self.progress[level]["time"])))
            # Locally scope level
            actions.append(lambda level=level: self.playLevel(level))
        entries += ["Return to main menu", "Clear progress"]
        actions += [self.doMainMenu, self.progress.clear]
        self.levelMenu = Menu(left, top, entries, actions)

    def initPauseMenu(self):
        def play():
            self.mode = "play"
        top = 200
        left = 300
        width = 140
        height = 80
        entries = ["Continue", "Main menu", "Turn sound off"]
        actions = [play,
                   self.doMainMenu,
                   self.toggleSound]
        self.pauseMenu = Menu(left, top, entries, actions)
        background = pygame.Surface((width + self.margin, height + self.margin))
        background.fill(self.bgColor)
        pygame.draw.rect(background, (0, 0, 0), background.get_rect(), 2)
        self.pauseMenu.background = background

    def initMenus(self):
        self.initMainMenu()
        self.initLevelMenu()
        self.initPauseMenu()

    def init(self):
        self.initStyles()
        self.initMaps()
        Terrain.initImages()
        Terrain.initSounds()
        self.initMenus()
        self.stopwatch = Stopwatch()
        self.initHelp()
        self.mode = "menu"
        self.menu = self.mainMenu

    def loadLevel(self):
        terrain, self.startpos = self.maps.load(self.level)
        self.terrain = pygame.sprite.Group(*terrain)
        self.ball = Ball(*self.startpos)
        self.score = 0
        self.stopwatch.restart()
        if self.level != "test":
            highscore = self.progress[self.level]["score"]
            bestTime = self.progress[self.level]["time"]
        else:
#.........这里部分代码省略.........
开发者ID:daniel-wen,项目名称:bouncier,代码行数:103,代码来源:main.py

示例2: add_parser_arguments

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import restart [as 别名]

#.........这里部分代码省略.........
        except KeyError:
            peer_player = self.get_player_for_peer(segment["peeraddr"])
            segment["player"] = peer_player
            return peer_player

    def get_player_for_peer(self, peeraddr):
        peer_player = None
        try:
            peer_player = self._player_for_peer[peeraddr]
        except KeyError:
            peer_player = self._create_player(peeraddr)
            self.players.append(peer_player)
            self._player_for_peer[peeraddr] = peer_player
        return peer_player

    def _create_player(self, addr):
        count = len(self.players)
        logger.debug("creating player number %d" % count)
        player = self._player_class(self, count)
        if self.options.locate_peers and self._peer_location[addr] is not None:
            x, y = self._peer_location[addr]
            location_str = "%s,%s" % (x, y)
        else:
            location_str = ""
        self._tell_visualizers(
            "/peer", player.id, addr, player.spatial_position.bearing, location_str)
        return player

    def set_time_cursor(self, log_time):
        assert not self.realtime
        logger.debug("setting time cursor at %f" % log_time)
        self.log_time_played_from = log_time
        if self._playing:
            self.stopwatch.restart()
        self.current_chunk_index = self._get_current_chunk_index()
        self.current_segment_index = self._get_current_segment_index()

    def _get_current_chunk_index(self):
        index = 0
        next_to_last_index = len(self.chunks) - 2
        while index < next_to_last_index:
            if self.chunks[index+1]["t"] >= self.log_time_played_from:
                return index
            index += 1
        return len(self.chunks) - 1

    def _get_current_segment_index(self):
        index = 0
        next_to_last_index = len(self.score) - 2
        while index < next_to_last_index:
            if self.score[index+1]["onset"] >= self.log_time_played_from:
                return index
            index += 1
        return len(self.score) - 1

    def _handle_set_listener_position(self, path, args, types, src, data):
        if self.ssr:
            x, y = args
            self.ssr.set_listener_position(x, y)

    def _handle_set_listener_orientation(self, path, args, types, src, data):
        if self.ssr:
            orientation = args[0]
            self.ssr.set_listener_orientation(orientation)

    def _handle_place_segment(self, path, args, types, src, data):
开发者ID:gaborpapp,项目名称:torrential-forms,代码行数:70,代码来源:orchestra.py

示例3: add_parser_arguments

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import restart [as 别名]

#.........这里部分代码省略.........
            peer_player = self._player_for_peer[peeraddr]
        except KeyError:
            peer_player = self._create_player(peeraddr)
            self.players.append(peer_player)
            self._player_for_peer[peeraddr] = peer_player
        return peer_player

    def _create_player(self, addr):
        count = len(self.players)
        logger.debug("creating player number %d" % count)
        player = self._player_class(self, count)
        player.addr = addr
        if self.server.options.locate_peers and self._peer_location[addr] is not None:
            x, y, place_name = self._peer_location[addr]
            if place_name:
                place_name = place_name.encode("unicode_escape")
            else:
                place_name = ""
            player.location_str = "%s,%s,%s" % (x, y, place_name)

            if x < self._peers_center_location_x:
                player.spatial_position.pan = -1.0
            else:
                player.spatial_position.pan = 1.0
        else:
            player.location_str = ""
        return player

    def set_time_cursor(self, log_time):
        assert not self.realtime
        logger.debug("setting time cursor at %f" % log_time)
        self.log_time_played_from = log_time
        if self._playing:
            self.stopwatch.restart()
        self.current_chunk_index = self._get_current_chunk_index()
        self.current_segment_index = self._get_current_segment_index()

    def _get_current_chunk_index(self):
        index = 0
        next_to_last_index = len(self.chunks) - 2
        while index < next_to_last_index:
            if self.chunks[index+1]["t"] >= self.log_time_played_from:
                return index
            index += 1
        return len(self.chunks) - 1

    def _get_current_segment_index(self):
        index = 0
        next_to_last_index = len(self.score) - 2
        while index < next_to_last_index:
            if self.score[index+1]["onset"] >= self.log_time_played_from:
                return index
            index += 1
        return len(self.score) - 1

    def _handle_set_listener_position(self, path, args, types, src, data):
        if self.output == self.SSR:
            x, y = args
            self.ssr.set_listener_position(x, y)

    def _handle_set_listener_orientation(self, path, args, types, src, data):
        if self.output == self.SSR:
            orientation = args[0]
            self.ssr.set_listener_orientation(orientation)

    def _handle_place_segment(self, path, args, types, src, data):
开发者ID:alex-berman,项目名称:tforms,代码行数:70,代码来源:orchestra.py


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