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


Python GameOfLife.randomize_board方法代码示例

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


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

示例1: board

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import randomize_board [as 别名]
# Get a board size from the user.
default_size = 30
str_prompt = "Specify a number of {0} for the board (default " \
             + str(default_size) +  "): "
fcn_parse = lambda string: (True, default_size) if string == '' else parse_positive_int(string)

num_rows = my_prompt(str_prompt.format('rows'), fcn_parse)
num_cols = my_prompt(str_prompt.format('columns'), fcn_parse)

# Should we play on a torus?
fcn_parse_torus = lambda string: (True, False) if string == '' else parse_yes_no(string)
on_torus = my_prompt("Make the board a torus (a la Pac-Man)? y/[n]: ", parse_yes_no)

# Initialize a random game.
game = GameOfLife(num_rows, num_cols, on_torus = on_torus)
game.randomize_board()

# ========================================================================
# A simple GUI demo
# ========================================================================
#
# Draw the board we created above, and update it every 250 milliseconds as long
# as there is life on the board.  No additional interaction is supported.

# Create a canvas for drawing to.
master = tk.Tk()
master.title("Conway's Game of Life")
w = tk.Canvas(master, width = 10 * num_cols, height = 10 * num_rows)
w.pack()

# Create the rectangles with which we'll draw the game.
开发者ID:zjroth,项目名称:game-of-life,代码行数:33,代码来源:demo.py


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