-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.py
143 lines (120 loc) · 6.04 KB
/
cell.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import constants
import pygame
class Cell:
def __init__(self, value, row, col, screen, sketch):
# Constructor for the Cell class
self.value = str(value)
self.row = row
self.col = col
self.screen = screen
# We need to figure out how to make this true when the user selects the cell
self.selected = False
# tells whether sketch or not
self.sketch = sketch
def set_cell_value(self, value):
# Setter for this cell’s value
self.value = str(value)
# Not too sure about the difference between these two methods
def set_sketched_value(self, value):
# Setter for this cell’s sketched value
self.value = str(value)
def draw(self, screen):
# Draws this cell, along with the value inside it.
# If this cell has a nonzero value, that value is displayed.
# Otherwise, no value is displayed in the cell.
# The cell is outlined red if it is currently selected.
# draw 'x' or 'o' as text in the window/board
# 2. text drawing: define the text
chip_font = pygame.font.Font(None, 50)
if self.sketch == False:
# We need to decide on a font color for the numbers (that is the third parameter in chip_font.render())
one = chip_font.render('1', True, constants.NUMBER_COLOR)
two = chip_font.render('2', True, constants.NUMBER_COLOR)
three = chip_font.render('3', True, constants.NUMBER_COLOR)
four = chip_font.render('4', True, constants.NUMBER_COLOR)
five = chip_font.render('5', True, constants.NUMBER_COLOR)
six = chip_font.render('6', True, constants.NUMBER_COLOR)
seven = chip_font.render('7', True, constants.NUMBER_COLOR)
eight = chip_font.render('8', True, constants.NUMBER_COLOR)
nine = chip_font.render('9', True, constants.NUMBER_COLOR)
# We need to figure out square size
if self.selected:
pygame.draw.rect(screen, (255, 0, 0),
pygame.Rect(self.col * constants.SQ_SIZE, self.row *
constants.SQ_SIZE, constants.SQ_SIZE, constants.SQ_SIZE), 12)
# sets center coords
num_center = (self.col * constants.SQ_SIZE + constants.SQ_SIZE // 2, self.row *
constants.SQ_SIZE + constants.SQ_SIZE // 2)
if self.sketch == True:
# We need to decide on a font color for the numbers (that is the third parameter in chip_font.render())
one = chip_font.render('1', True, constants.SKETCH_NUM_COLOR)
two = chip_font.render('2', True, constants.SKETCH_NUM_COLOR)
three = chip_font.render('3', True, constants.SKETCH_NUM_COLOR)
four = chip_font.render('4', True, constants.SKETCH_NUM_COLOR)
five = chip_font.render('5', True, constants.SKETCH_NUM_COLOR)
six = chip_font.render('6', True, constants.SKETCH_NUM_COLOR)
seven = chip_font.render('7', True, constants.SKETCH_NUM_COLOR)
eight = chip_font.render('8', True, constants.SKETCH_NUM_COLOR)
nine = chip_font.render('9', True, constants.SKETCH_NUM_COLOR)
# We need to figure out square size
if self.selected:
pygame.draw.rect(screen, (255, 0, 0),
pygame.Rect(self.col * constants.SQ_SIZE, self.row *
constants.SQ_SIZE, constants.SQ_SIZE, constants.SQ_SIZE), 12)
# sets center coords
num_center = (self.col * constants.SQ_SIZE + constants.SQ_SIZE // 4, self.row *
constants.SQ_SIZE + constants.SQ_SIZE // 4)
if self.value == '1':
# 3. text drawing: define the location
one_rect = one.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(one, one_rect)
elif self.value == '2':
# 3. text drawing: define the location
two_rect = two.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(two, two_rect)
elif self.value == '3':
# 3. text drawing: define the location
three_rect = three.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(three, three_rect)
elif self.value == '4':
# 3. text drawing: define the location
four_rect = four.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(four, four_rect)
elif self.value == '5':
# 3. text drawing: define the location
five_rect = five.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(five, five_rect)
elif self.value == '6':
# 3. text drawing: define the location
six_rect = six.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(six, six_rect)
elif self.value == '7':
# 3. text drawing: define the location
seven_rect = seven.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(seven, seven_rect)
elif self.value == '8':
# 3. text drawing: define the location
eight_rect = eight.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(eight, eight_rect)
elif self.value == '9':
# 3. text drawing: define the location
nine_rect = nine.get_rect(
center=num_center)
# 4. # text drawing: blit the number onto the screen
screen.blit(nine, nine_rect)