Blit numbers in cells

This commit is contained in:
Joseph Ferano 2023-10-28 18:21:00 +07:00
parent 7bd04be46f
commit 6b4be6913a

View File

@ -16,6 +16,7 @@ screen = pg.display.set_mode((900, 900))
pg.display.set_caption("Pydoku") pg.display.set_caption("Pydoku")
pg.key.set_repeat(200, 35) pg.key.set_repeat(200, 35)
title_font = pg.font.Font(None, 64) title_font = pg.font.Font(None, 64)
filled_num_font = pg.font.Font(None, 48)
clock = pg.time.Clock() clock = pg.time.Clock()
running = True running = True
@ -63,6 +64,24 @@ def draw_cursor():
CURSOR_SIZE, CURSOR_SIZE) CURSOR_SIZE, CURSOR_SIZE)
screen.blit(cursorSurface, rect) screen.blit(cursorSurface, rect)
def get_num(row, col):
return board[row, col]
filled_num_font = pg.font.Font(None, 60)
def draw_numbers():
for row in range(9):
for col in range(9):
num = board[row * 9 + col]
if num == 0:
continue
digit = filled_num_font.render(str(num), True, "black")
pos = (GRID_X + CELL_SIZE * col + CELL_SIZE // 2 - digit.get_width() // 2,
# Here we divide the height by 2.3 because there seems to be some extra
# padding at the bottom of the surface
GRID_Y + CELL_SIZE * row + CELL_SIZE // 2 - digit.get_height() // 2.3)
screen.blit(digit, pos)
title = title_font.render("Pydoku", True, "black") title = title_font.render("Pydoku", True, "black")
def draw_hud(): def draw_hud():
screen.blit(title, (screen.get_width() // 2 - title.get_width() // 2, 70)) screen.blit(title, (screen.get_width() // 2 - title.get_width() // 2, 70))
@ -97,6 +116,7 @@ while running:
screen.fill('cornflower blue') screen.fill('cornflower blue')
draw_grid() draw_grid()
draw_numbers()
draw_cursor() draw_cursor()
draw_hud() draw_hud()