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
评论列表
文章目录