-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
503 lines (403 loc) · 32 KB
/
game.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
import pygame, random, pygame_menu
from typing import Union
from pygame.locals import *
pygame.init()
FONT = pygame.font.Font(None, 42)
DEVELOPER_GAME = 0
DEVELOPER_GAME_TEXT = [('Não', 0), ('Sim', 1)]
DIFFICULTY_GAME_TEXT = [('Fácil', 0), ('Normal', 1), ('Difícil', 2)]
DIFFICULTY_GAME_WEIGHTS = [[50, 50], [40, 60], [35, 65]]
DIFFICULTY_GAME = DIFFICULTY_GAME_WEIGHTS[0]
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 596
SCREEN_GAME_WIDTH = 596
SCREEN_GAME_HEIGHT = 596
SIZE_DIVISION_BIG_SQUARE = 5
SIZE_DIVISION_SMALL_SQUARE = 2
SIZE_SQUARE = 60
COLOR_BLACK = (0, 0, 0)
COLOR_RED = (255, 0, 0)
COLOR_LITE_GRAY = (100, 100, 100)
COLOR_STRONG_GRAY = (128, 128, 128)
COLOR_INACTIVE = COLOR_STRONG_GRAY
COLOR_ACTIVE = (255, 255, 255)
SMALL_SQUARE_SIZE = SIZE_SQUARE + (SIZE_DIVISION_SMALL_SQUARE * 2)
BIG_SQUARE_SIZE = (SMALL_SQUARE_SIZE * 3) + SIZE_DIVISION_BIG_SQUARE
ERROS = 0
NUM_FALTANTES = 81
NUM_PREENCHIDOS = 0
class Grid:
def __init__(self):
self.grid = []
def initialize(self):
base = 3
side = base*base
# pattern for a baseline valid solution
def pattern(r,c): return (base*(r%base)+r//base+c)%side
# randomize rows, columns and numbers (of valid base pattern)
def shuffle(s): return random.sample(s, len(s))
rBase = range(base)
rows = [ g*base + r for g in shuffle(rBase) for r in shuffle(rBase) ]
cols = [ g*base + c for g in shuffle(rBase) for c in shuffle(rBase) ]
nums = shuffle(range(1, base*base+1))
# produce board using randomized baseline pattern
board = [ [nums[pattern(r,c)] for c in cols] for r in rows ]
for index_row, row in enumerate(board):
for index_col, cell in enumerate(row):
qdr = int((int(index_row / 3) * 3) + (index_col / 3))
self.grid.append({
"text": cell,
"row": index_row,
"column": index_col,
"quadrante": qdr,
"preenchido": False,
"error": False,
})
self.order_grid()
# self.print_grid()
return self.grid
def analyze_grid(self, row:int, col:int) -> dict:
qdr = int((int(row / 3) * 3) + int(col / 3))
result_analyze_grid = {
"index_quadrant": qdr,
"index_row": row,
"index_column": col,
"quadrants": {
"numeros_faltantes": [],
"numeros_preenchidos": [],
},
"columns": {
"numeros_faltantes": [],
"numeros_preenchidos": [],
},
"rows": {
"numeros_faltantes": [],
"numeros_preenchidos": [],
},
}
get_text = lambda x: x['text']
temp = self.get_nums_qdr(qdr)
temp_nums = list(map(get_text, temp))
result_analyze_grid['quadrants']['numeros_preenchidos'] = temp_nums
result_analyze_grid['quadrants']['numeros_faltantes'] = list(set([1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(temp_nums))
temp = self.get_nums_col(col)
temp_nums = list(map(get_text, temp))
result_analyze_grid['columns']['numeros_preenchidos'] = temp_nums
result_analyze_grid['columns']['numeros_faltantes'] = list(set([1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(temp_nums))
temp = self.get_nums_row(row)
temp_nums = list(map(get_text, temp))
result_analyze_grid['rows']['numeros_preenchidos'] = temp_nums
result_analyze_grid['rows']['numeros_faltantes'] = list(set([1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(temp_nums))
return result_analyze_grid
def get_nums_col(self, col:int) -> list:
filter_col = lambda x: x['column'] == col and x['preenchido'] == True
return list(filter(filter_col, self.grid))
def get_nums_row(self, row:int) -> list:
filter_row = lambda x: x['row'] == row and x['preenchido'] == True
return list(filter(filter_row, self.grid))
def get_nums_qdr(self, qdr:int) -> list:
filter_qdr = lambda x: x['quadrante'] == qdr and x['preenchido'] == True
list_nums_in_qdr = list(filter(filter_qdr, self.grid))
return list_nums_in_qdr
def get_num_row_col(self, row:int, col:int) -> dict:
filter_num = lambda x: x['column'] == col and x['row'] == row
return list(filter(filter_num, self.grid))[0]
def order_grid(self):
self.grid = sorted(self.grid, key=lambda x: (x["row"], x["column"]))
def print_grid(self):
self.order_grid()
allGrid = []
find_elem = lambda x: x['row'] == row and x['column'] == col
get_text = lambda x: x["text"]
for row in range(0, 9, 1):
rowGrid = []
if row % 3 == 0:
allGrid.append(" ----------------------")
for col in range(0, 9, 1):
if col == 0:
rowGrid.append("|")
dict_num = list(filter(find_elem, self.grid))
if dict_num:
number = str(list(map(get_text, dict_num))[0])
else:
number = " "
if col % 3 == 0 and col != 0:
rowGrid.append("-|")
rowGrid.append(number)
rowGrid.append("|")
allGrid.append(rowGrid)
allGrid.append(" ----------------------")
for i in allGrid:
print("".join(i))
class InputBox:
def __init__(self, x:float, y:float, w:float, h:float, position:list, text:str=''):
global DIFFICULTY_GAME, NUM_FALTANTES, NUM_PREENCHIDOS, ERROS
self.rect = pygame.Rect(x, y, w, h)
self.position = position
self.color = COLOR_INACTIVE
self.text = text
self.txt_surface = FONT.render(text, True, self.color)
self.active = False
self.error = False
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
# If the user clicked on the input_box rect.
if self.rect.collidepoint(event.pos):
if self.text == "" or self.error:
self.active = not self.active
else:
self.active = False
# Change the current color of the input box.
self.color = COLOR_ACTIVE if self.active else COLOR_INACTIVE
if event.type == pygame.KEYDOWN:
if self.active:
if event.key == pygame.K_ESCAPE:
self.active = False
self.color = COLOR_ACTIVE if self.active else COLOR_INACTIVE
else:
if self.text == "" or self.error == True:
self.text = event.unicode
self.check()
# Re-render the text
self.txt_surface = FONT.render(self.text, True, self.color)
def draw(self, screen):
screen.blit(self.txt_surface, (self.rect.x + 25, self.rect.y + 20))
pygame.draw.rect(screen, self.color, self.rect, SIZE_DIVISION_SMALL_SQUARE)
def check(self):
global NUM_FALTANTES, NUM_PREENCHIDOS, ERROS
cell = GRID.get_num_row_col(self.position[0], self.position[1])
if str(cell['text']) != self.text:
ERROS += 1
self.color = COLOR_RED
self.error = True
else:
NUM_FALTANTES -= 1
NUM_PREENCHIDOS += 1
self.color = COLOR_ACTIVE
self.error = False
GRID.grid[GRID.grid.index(cell)]['preenchido'] = True
def analyze(self, screen):
if self.active:
height = SCREEN_GAME_HEIGHT + 20
result = GRID.analyze_grid(self.position[0], self.position[1])
numeros_faltantes = list(set(result['quadrants']['numeros_faltantes']).intersection(result['columns']['numeros_faltantes']).intersection(result['rows']['numeros_faltantes']))
percentual_quadrants = round((1 / len(result['quadrants']['numeros_faltantes'])) * 100, 2) if len(result['quadrants']['numeros_faltantes']) != 0 else float(0)
percentual_columns = round((1 / len(result['columns']['numeros_faltantes'])) * 100, 2) if len(result['columns']['numeros_faltantes']) != 0 else float(0)
percentual_rows = round((1 / len(result['rows']['numeros_faltantes'])) * 100, 2) if len(result['rows']['numeros_faltantes']) != 0 else float(0)
percentual_all = round((1 / len(numeros_faltantes)) * 100, 2) if len(numeros_faltantes) != 0 else float(0)
percentual_avg = round((percentual_quadrants + percentual_columns + percentual_rows + percentual_all) / 4, 2)
width = 120
for num in range(1, 10, 1):
if num in numeros_faltantes:
if len(numeros_faltantes) == 1:
screen.blit(FONT.render(f'{num}: 100%', True, COLOR_BLACK), (height, width))
else:
screen.blit(FONT.render(f'{num}: {percentual_avg}%', True, COLOR_BLACK), (height, width))
else:
screen.blit(FONT.render(f'{num}: 0%', True, COLOR_BLACK), (height, width))
width += 30
class Button:
def __init__(self, x:float, y:float, w:float, h:float, text:str):
self.text = FONT.render(text, True , COLOR_BLACK)
self.x = x
self.y = y
self.width = w
self.height = h
def is_press(self, mouse):
if self.x <= mouse[0] <= self.x + self.height and self.y <= mouse[1] <= self.y + self.width:
return True
return False
def is_hover(self, mouse):
if self.x <= mouse[0] <= self.x + self.height and self.y <= mouse[1] <= self.y + self.width:
pygame.draw.rect(screen, COLOR_ACTIVE, [self.x, self.y, self.height, self.width])
else:
pygame.draw.rect(screen, COLOR_INACTIVE, [self.x, self.y, self.height, self.width])
# superimposing the text onto our button
screen.blit(self.text, (self.x + (self.height / 5), self.y + (self.width / 5)))
# DIFICULDADE DO JOGO
def set_difficulty(value, difficulty):
global DIFFICULTY_GAME
DIFFICULTY_GAME = DIFFICULTY_GAME_WEIGHTS[difficulty]
print('Dificuldade: ', DIFFICULTY_GAME_TEXT[difficulty][0])
# MODO DESENVOLVEDOR DO JOGO
def set_developer(value, developer):
global DEVELOPER_GAME
DEVELOPER_GAME = developer
print('Modo desenvolvedor: ', DEVELOPER_GAME_TEXT[developer][0])
def draw_scenario():
screen.fill(COLOR_LITE_GRAY)
# DIVISOES QUADRANTES MAIORES
# VERTICAL
pygame.draw.rect(screen, COLOR_BLACK, (BIG_SQUARE_SIZE, 0, SIZE_DIVISION_BIG_SQUARE, SCREEN_GAME_HEIGHT))
pygame.draw.rect(screen, COLOR_BLACK, (BIG_SQUARE_SIZE * 2, 0, SIZE_DIVISION_BIG_SQUARE, SCREEN_GAME_HEIGHT))
# HORIZONTAL
pygame.draw.rect(screen, COLOR_BLACK, (0, BIG_SQUARE_SIZE, SCREEN_GAME_WIDTH, SIZE_DIVISION_BIG_SQUARE))
pygame.draw.rect(screen, COLOR_BLACK, (0, BIG_SQUARE_SIZE * 2, SCREEN_GAME_WIDTH, SIZE_DIVISION_BIG_SQUARE))
# BORDAS
# VERTICAL
pygame.draw.rect(screen, COLOR_BLACK, (0, 0, SCREEN_GAME_WIDTH, SIZE_DIVISION_BIG_SQUARE))
pygame.draw.rect(screen, COLOR_BLACK, (0, 0, SIZE_DIVISION_BIG_SQUARE, SCREEN_GAME_HEIGHT))
# HORIZONTAL
pygame.draw.rect(screen, COLOR_BLACK, (SCREEN_GAME_WIDTH - SIZE_DIVISION_BIG_SQUARE, 0, SIZE_DIVISION_BIG_SQUARE, SCREEN_GAME_HEIGHT))
pygame.draw.rect(screen, COLOR_BLACK, (0, SCREEN_GAME_HEIGHT - SIZE_DIVISION_BIG_SQUARE, SCREEN_GAME_HEIGHT, SIZE_DIVISION_BIG_SQUARE))
def update_info():
global ERROS, NUM_FALTANTES, NUM_PREENCHIDOS
height = SCREEN_GAME_HEIGHT + 20
screen.blit(FONT.render(f'Num faltantes: {NUM_FALTANTES}', True, COLOR_BLACK), (height, 20))
screen.blit(FONT.render(f'Num preenchidos: {NUM_PREENCHIDOS}', True, COLOR_BLACK), (height, 50))
screen.blit(FONT.render(f'Erros: {ERROS}', True, COLOR_BLACK), (height, 80))
# GAME
def start_the_game():
global DEVELOPER_GAME, NUM_FALTANTES, GRID, ERROS
NUM_FALTANTES = 81
ERROS = 0
NUM_PREENCHIDOS = 0
clock = pygame.time.Clock()
draw_scenario()
# DIVISOES QUADRANTES MENORES
inputBoxs = [
# QUADRANTE 01
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 2]},
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 2]},
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 2]},
# QUADRANTE 02
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 5]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 5]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 5]},
# QUADRANTE 03
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [0, 8]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [1, 8]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [2, 8]},
# QUADRANTE 04
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 2]},
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 2]},
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 2]},
# QUADRANTE 05
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 5]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 5]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 5]},
# QUADRANTE 06
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [3, 8]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [4, 8]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [5, 8]},
# QUADRANTE 07
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 2]},
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 2]},
{"x": SIZE_DIVISION_BIG_SQUARE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 0]},
{"x": SIZE_DIVISION_BIG_SQUARE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 1]},
{"x": SIZE_DIVISION_BIG_SQUARE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 2]},
# QUADRANTE 08
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 5]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 5]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 3]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 4]},
{"x": SIZE_DIVISION_BIG_SQUARE + BIG_SQUARE_SIZE + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 5]},
# QUADRANTE 09
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [6, 8]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [7, 8]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 6]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + SMALL_SQUARE_SIZE, "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 7]},
{"x": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "y": SIZE_DIVISION_BIG_SQUARE + (BIG_SQUARE_SIZE * 2) + (SMALL_SQUARE_SIZE * 2), "w": SMALL_SQUARE_SIZE, "h": SMALL_SQUARE_SIZE, "position": [8, 8]},
]
input_boxes = []
for inputBoxSelect in inputBoxs:
if random.choices([0, 1], weights=DIFFICULTY_GAME, k=1)[0] == 1:
text = ""
else:
cell = GRID.get_num_row_col(inputBoxSelect["position"][0], inputBoxSelect["position"][1])
text = str(cell['text'])
GRID.grid[GRID.grid.index(cell)]['preenchido'] = True
NUM_FALTANTES -= 1
inputBoxSelect["text"] = text
input_boxes.append(InputBox(**inputBoxSelect))
btn_sair = Button(x=SCREEN_WIDTH-10-100, y=SCREEN_HEIGHT-10-50, w=50, h=100, text='Sair')
while True:
# FPS
clock.tick(30)
# MOUSE COORDINATES INFO
mouse = pygame.mouse.get_pos()
# VERIFICA EVENTOS
for event in pygame.event.get():
# SAIR
if event.type == QUIT:
pygame.quit()
exit()
# MOUSE
if event.type == pygame.MOUSEBUTTONDOWN:
if btn_sair.is_press(mouse):
return
# VERIFICA SE BOX ESTA SELECIONADA
for box in input_boxes:
box.handle_event(event)
screen.fill((30, 30, 30))
for box in input_boxes:
box.draw(screen)
if DEVELOPER_GAME == 1:
box.analyze(screen)
btn_sair.is_hover(mouse)
pygame.display.flip()
# ATUALIZA INFO
update_info()
# ATUALIZA DA TELA
pygame.display.update()
if NUM_FALTANTES == 0:
break
GRID = Grid()
GRID.initialize()
# PROPIEDADES SCREEN
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
# MENU
menu = pygame_menu.Menu(SCREEN_HEIGHT, SCREEN_WIDTH, 'Bem Vindo(a)!', theme=pygame_menu.themes.THEME_GREEN)
menu.add_selector('Dificuldade :', DIFFICULTY_GAME_TEXT, onchange=set_difficulty)
menu.add_selector('Desenvolvedor :', DEVELOPER_GAME_TEXT, onchange=set_developer)
menu.add_button('Jogar', start_the_game)
menu.add_button('Sair', pygame_menu.events.EXIT)
menu.mainloop(screen)