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


Python Display.quit方法代码示例

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


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

示例1: Life

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import quit [as 别名]
class Life(object):

    __display = None
    grid_size = [100, 100]

    def __init__(self):
        self.__display = Display(title='PyLife', grid_size=self.grid_size, width=800, height=800)

    def initial_seed(self):
        cells = {}
        for x in range(self.grid_size[0]):
            for y in range(self.grid_size[1]):
                if random.randint(0, 1) == 1:
                    cells[(x, y)] = 1
        return cells


    def get_cell_neighbours(self, item, cells):
        neighbours = 0
        for x in range(-1, 2):
            for y in range(-1, 2):
                cell = (item[0] + x, item[1] + y)
                if cell[0] in range(0, self.grid_size[0]) and cell[1] in range(0, self.grid_size[1]) and cell in cells:
                    if (x == 0 and y == 0) is False:
                        neighbours += 1
        return neighbours

    def get_cells(self, cells):
        new_cells = {}
        for x in range(self.grid_size[0]):
            for y in range(self.grid_size[1]):
                neighbours = self.get_cell_neighbours((x, y), cells)
                if ((x, y) in cells) and (neighbours == 2 or neighbours == 3):
                    new_cells[(x, y)] = 1
                elif ((x, y) in cells) is False and neighbours == 3:
                    new_cells[(x, y)] = 1
        del cells
        return new_cells

    def run(self):
        cells = self.initial_seed()
        while True:
            if self.__display.update() is False:
                self.__display.quit()
                sys.exit(0)
            cells = self.get_cells(cells)
            for cell in cells:
                self.__display.draw(cell[0], cell[1])
开发者ID:mebusila,项目名称:PyLife,代码行数:50,代码来源:life.py

示例2: main

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import quit [as 别名]
def main(myAddr, clAddr):
    myDisplay = Display()
    myDisplay.init()
    
    backSender = BackSender(clAddr)
    
    # start threads
    displayThread = threading.Thread(None, displayMain, 'display', (myDisplay, ))
    displayThread.start()
    
    serverThread = threading.Thread(None, displayServerMain, 'displayserver', (myDisplay, myAddr))
    serverThread.start()
    
    connectTread = threading.Thread(None, connectMain, 'connection', (myAddr, backSender))
    connectTread.start()
    
    inputThread = threading.Thread(None, inputMain, 'input', (myDisplay, backSender))
    inputThread.start()
    
    # wait till threads end
    while displayThread.is_alive() and serverThread.is_alive():
        try:
            littlePause = 0.1
            displayThread.join(littlePause)
        except KeyboardInterrupt:
            logging.info('exit on keyboard interrupt')
            myDisplay.quit = True
        except Exception as err:
            logging.error('unhandled exception in main thread:')
            logging.error(str(err))
            logging.debug(traceback.format_exc())
开发者ID:caryoscelus,项目名称:tam-rogue,代码行数:33,代码来源:main.py


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