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


Python Gui.refresh方法代码示例

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


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

示例1: runGame

# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import refresh [as 别名]
def runGame(players, logger, slowMode=False, gui=False):
    passes = 0
    state = GameState()

    if gui:
        gui = Gui(state)
        # Upgrade console players to GUI players in GUI mode
        for idx, player in enumerate(players):
            if player.__name__ == 'player_console.player':
                players[idx] = GuiPlayer(gui)

    player1 = players[0]
    player2 = players[1]
    player3 = players[2]
    player4 = players[3]

    t0 = time.clock()

    while passes < 4:
        player = state.getPlayer()

        if gui:
            gui.refresh(True)

        logger.log('Player ' + str(player) + '\'s turn!')
        if player == 1:
            move = player1.getMove(state.clone(), player)
        elif player == 2:
            move = player2.getMove(state.clone(), player)
        elif player == 3:
            move = player3.getMove(state.clone(), player)
        elif player == 4:
            move = player4.getMove(state.clone(), player)

        if move == None:
            passes += 1
        else:
            passes = 0

        if state.applyMove(move, player):
            logger.log('  > Move made: ' + str(move))
        else:
            logger.log('  > Invalid move!')

        if slowMode:
            time.sleep(.5)

    logger.log(state)
    totalCells = getTotalCells()
    winners = []
    minCells = ROWS*COLS
    for player in [1,2,3,4]:
        remaining = totalCells - state.getCellsOnBoard(player)
        if remaining < minCells:
            winners = [player]
            minCells = remaining
        elif remaining == minCells:
            winners.append(player)
        logger.log('Player ' + str(player) + ' has ' + str(remaining) + ' cells remaining.')

    logger.log('')
    if len(winners) == 1:
        logger.log('Player ' + str(winners[0]) + ' wins!')
    elif len(winners) > 1:
        logger.log('Tie between ' + str(winners) + '!')

    logger.log("Game took " + str(time.clock() - t0) + " seconds")

    if gui:
        gui.waitForQuit()
    elif slowMode:
        time.sleep(5)

    return winners
开发者ID:djynth,项目名称:blokus-game,代码行数:76,代码来源:game_runner.py


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