-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.py
More file actions
112 lines (112 loc) · 4.1 KB
/
board.py
File metadata and controls
112 lines (112 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import pygame
import pygame.draw
from cell import Cell
pygame.init()
x = 0
y = 0
WIDTH = 500
HEIGHT = 500
dif = WIDTH / 9
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
smallfont = pygame.font.SysFont('Times New Roman', 25)
class Board:
def __init__(self, width, height, screen, difficulty):
#Difficulty is equal to the removed cells from the board.
self.width = width
self.height = height
self.screen = screen
self.difficulty = difficulty
self.cells = []
self.original_board = []
self.solved_board = []
#Store original board in self.original_board and do NOT modify.
#Call fill_values method from SG to construct the board initially.
for i in range(0, 9):
self.column_list = []
for j in range(0, 9):
cell = Cell(None, i, j, self.screen)
self.column_list.append(cell)
self.cells.append(self.column_list)
def get_board_values(self):
values = []
for i in range(0, 9):
row = self.cells[i]
col = []
for j in range(0, 9):
cell = row[j]
col.append(cell.get_cell_value())
values.append(col)
return values
def draw(self):
for i in range(9):
for j in range(9):
if self.screen[i][j] != 0:
pygame.draw.rect(WINDOW, (0, 153, 153), (i * dif, j * dif, dif + 1, dif + 1))
text1 = smallfont.render(str(self.screen[i][j]), True, (0, 0, 0))
WINDOW.blit(text1, (i * dif + 15, j * dif + 15))
for i in range(10):
if i % 3 ==0:
thickness = 7
else:
thickness = 1
pygame.draw.line(WINDOW, (0, 0, 0), (0, i * dif), (500, i * dif), thickness)
pygame.draw.line(self.screen, (0, 0, 0), (i * dif, 0), (i * dif, 500), thickness)
def select(self, row, col):
self.row = row
self.col = col
self.current_cell = self.cells[self.row][self.col]
def click(self, x, y):
#Calculates the row and column based off the dimensions of the window
#Call the select method and return a tuple
pass
def clear(self):
for i in range(0, 9):
current_row = self.cells[i]
for j in range(0, 9):
cell = current_row[j]
cell.set_cell_value(None)
cell.set_sketched_value(None)
def sketch(self, value):
self.current_cell.set_sketched_value(value)
def place_number(self, value):
#place numbers will be sent to check board
self.current_cell.set_cell_value(value)
#Call this method in SudokuGenerator (press Enter)
def reset_to_original(self):
# check_board is called to reset board
self.cells = self.original_board.copy()
def is_full(self):
# returns a value to the check_board
# checks the board square is full which gets called to check_board
for i in range(0, 9):
row = self.cells[i]
for j in range(0, 9):
cell = row[j]
if cell.value == 0:
return False
return True
def update_board(self):
#updates values from player input
#Retreive all the numbers from board and update self.cells.
pass
def find_empty(self):
# I think this calls for
for i in range(0, 9):
row = self.cells[i]
for j in range(0, 9):
cell = row[j]
if cell.value == None:
return (i, j)
def check_board(self):
# this checks for that varibles
# if player wins = game_continue False
# if player loses = game_continue False but player is able to restart
for i in range(0, 9):
row = self.cells[i]
solved_row = self.solved_board[i]
for j in range(0, 9):
cell = row[j]
solved_cell = solved_row[j]
if cell.value != solved_cell.value:
return False
return True