minesweeper_curses.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Minesweeper 作者: M-Mueller 项目源码 文件源码
def draw_game(stdscr, rect, game):
    """Draws the game fields."""
    rect = Rect(rect.x, rect.y, game.column_count()*2+1, game.row_count()+2)
    rect = draw_frame(stdscr, rect)

    for i, (mine, flag, hint) in enumerate(zip(game.mines, game.flags, game.hints)):
        x, y = game.mines.linear_to_subscript(i)
        x = x*2 + rect.x # add padding between characters to get a nicer aspect ratio
        y = y + rect.y
        if flag == minesweeper.Flags.Unknown:
            stdscr.addstr(y, x, "?")
        elif flag == minesweeper.Flags.Marked:
            stdscr.addstr(y, x, "\u26F3") # flag in hole
        else:
            if mine:
                stdscr.addstr(y, x, "\u26ED") # gear without hub
            else:
                if hint == 0:
                    stdscr.addstr(y, x, " ")
                else:
                    stdscr.addstr(y, x, str(hint), curses.A_DIM)
    return rect
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号