Skip to content

Commit a921fdc

Browse files
authored
FIX: Grid draws correctly when x and y are large than default (#4)
1 parent b56aa67 commit a921fdc

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

board.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,6 @@ def leftclick(self, pos) -> bool:
199199
self._zero_search(tile, searched)
200200
return True
201201

202-
def show_mines(self):
203-
if not self._revealed:
204-
self._revealed = True
205-
206-
for pos in self.mines:
207-
px, py = pos
208-
tile = self.grid[px][py]
209-
if pos not in self.flags:
210-
tile.toggle_visible()
211-
else:
212-
tile.set_green()
213-
214202
def _zero_search(self, tile, searched):
215203
if tile.n != 0:
216204
return searched
@@ -230,6 +218,18 @@ def _zero_search(self, tile, searched):
230218

231219
return searched
232220

221+
def show_mines(self):
222+
if not self._revealed:
223+
self._revealed = True
224+
225+
for pos in self.mines:
226+
px, py = pos
227+
tile = self.grid[px][py]
228+
if pos not in self.flags:
229+
tile.toggle_visible()
230+
else:
231+
tile.set_green()
232+
233233
def __init__(self, x, y, mines: int):
234234
self.x = x
235235
self.y = y
@@ -242,9 +242,9 @@ def __init__(self, x, y, mines: int):
242242
y_blocks = y * BLOCK_SIZE
243243

244244
self.tl = (GRIDPADDING, GRIDPADDING)
245-
self.tr = (GRIDPADDING, GRIDPADDING + x_blocks)
246-
self.bl = (GRIDPADDING + y_blocks, GRIDPADDING)
247-
self.br = (GRIDPADDING + y_blocks, GRIDPADDING + x_blocks)
245+
self.tr = (GRIDPADDING, GRIDPADDING + y_blocks)
246+
self.bl = (GRIDPADDING + x_blocks, GRIDPADDING)
247+
self.br = (GRIDPADDING + x_blocks, GRIDPADDING + y_blocks)
248248

249249
def _construct_grid(self, x, y, first_pos):
250250
exclude = {pos for pos in _around(first_pos)}
@@ -293,11 +293,13 @@ def render(self, win):
293293

294294
# Outline
295295
for i in range(0, self.x + 1):
296-
left = add(self.tl, (i*16, 0))
297-
right = add(self.tr, (i*16, 0))
296+
diff = (i*16, 0)
297+
left = add(self.tl, diff)
298+
right = add(self.tr, diff)
298299
pygame.draw.line(win, colours.BLACK, left , right, 1)
299300

300301
for i in range(0, self.y + 1):
301-
top = add(self.tl, (0, i*16))
302-
bottom = add(self.bl, (0, i*16))
302+
diff = (0, i*16)
303+
top = add(self.tl, diff)
304+
bottom = add(self.bl, diff)
303305
pygame.draw.line(win, colours.BLACK, top, bottom, 1)

0 commit comments

Comments
 (0)