-
Notifications
You must be signed in to change notification settings - Fork 0
/
CUBERSE.py
577 lines (459 loc) · 20.6 KB
/
CUBERSE.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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# Import Libraries
import re
import nltk
import pandas as pd
import pygame
from pygame import mixer
import os
import string
import random
from PIL import Image
import cv2
import numpy as np
from tensorflow.keras.models import load_model
from collections import Counter
import subprocess
import threading
import time
import traceback
from collections import Counter
#### BACKEND ####
# Parametros modelo IA
MODEL_PATH = 'digits.h5'
CONFIDENCE_THRESHOLD = 0.95
CAPTURE_WIDTH = 640
CAPTURE_HEIGHT = 480
RESIZE_WIDTH = 200
RESIZE_HEIGHT = 200
PREDICTION_FRAMES = 15 #10
lock = threading.Lock()
predicted_number = None
# Cargar el modelo
model = load_model(MODEL_PATH)
# Función para realizar la predicción
def prediction(image, model):
img = cv2.resize(image, (28, 28))
img = img / 255
img = img.reshape(1, 28, 28, 1)
predict = model.predict(img)
prob = np.amax(predict)
class_index = np.argmax(predict)
result = class_index
if prob < CONFIDENCE_THRESHOLD:
result = None
prob = 0
return result, prob
# Lista para almacenar las últimas predicciones
last_predictions = []
root = None
video_label = None
# Función para actualizar la imagen en la interfaz gráfica
def update_image():
global last_predictions
global cap
global predicted_number
_, frame = cap.read()
frame_copy = frame.copy()
bbox_size = (70, 70)
bbox = [(int(CAPTURE_WIDTH // 2 - bbox_size[0] // 2), int(CAPTURE_HEIGHT // 2 - bbox_size[1] // 2)),
(int(CAPTURE_WIDTH // 2 + bbox_size[0] // 2), int(CAPTURE_HEIGHT // 2 + bbox_size[1] // 2))]
img_cropped = frame[bbox[0][1]:bbox[1][1], bbox[0][0]:bbox[1][0]]
img_gray = cv2.cvtColor(img_cropped, cv2.COLOR_BGR2GRAY)
img_gray = cv2.resize(img_gray, (RESIZE_WIDTH, RESIZE_HEIGHT))
result, probability = prediction(img_gray, model)
last_predictions.append(result)
if len(last_predictions) > PREDICTION_FRAMES:
last_predictions.pop(0)
most_common_prediction = Counter(last_predictions).most_common(1)[0][0]
predicted_number = most_common_prediction
print(predicted_number)
cv2.putText(frame_copy, f"Prediction: {most_common_prediction}", (40, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 255), 2, cv2.LINE_AA)
cv2.putText(frame_copy, "Probabilty: {:.2f}".format(probability), (40, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 255), 2, cv2.LINE_AA)
color = (0, 255, 0) if probability > CONFIDENCE_THRESHOLD else (0, 0, 255)
cv2.rectangle(frame_copy, bbox[0], bbox[1], color, 3)
# Mostrar la imagen con OpenCV
cv2.imshow("Handwritten Digit Recognition", frame_copy)
cv2.waitKey(1)
def run_digit_recognition_gui():
global cap
try:
# Inicializar la captura de video
cap = cv2.VideoCapture(2 + cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, CAPTURE_WIDTH)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, CAPTURE_HEIGHT)
while predicted_number is None:
update_image()
except Exception as e:
print("Error en run_digit_recognition_gui:")
print(traceback.format_exc())
finally:
cap.release()
cv2.destroyAllWindows()
#### FRONTEND ####
pygame.init()
# MUSIC
mixer.init()
mixer.music.load('zelda.mp3')
mixer.music.play(-1) # El -1 hará que la música se repita indefinidamente.
#mixer.music.set_volume(0.5) # Establece el volumen al 50%. Puedes cambiar 0.5 a cualquier valor entre 0 y 1.
win = pygame.display.set_mode((640, 480))
pygame.display.set_caption("CUBERSE ")
mixer.init()
# FONTS
pygame.font.init()
font_1 = pygame.font.SysFont('impact', 55)
font_2 = pygame.font.SysFont('Arial', 25)
font_3 = pygame.font.SysFont('roboto', 30)
font_4 = pygame.font.SysFont('Arial', 20)
font_5 = pygame.font.SysFont('impact', 25)
font_6 = pygame.font.SysFont('impact', 120)
font_7 = pygame.font.SysFont('impact', 90)
# time
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 1000)
#############
# Main Page #
#############
page = 0
# Background
win.fill((59, 89, 152)) # title
pygame.draw.rect(win, (117, 138, 182), (0, 200, 640, 110)) # word length
pygame.draw.rect(win, (176, 188, 213), (0, 310, 640, 110)) # time limit
pygame.draw.rect(win, (235, 238, 244), (0, 420, 640, 60)) # game start
# Title
win.blit(font_1.render('CUBERSE', False,(242, 242, 242)),(215, 45))
win.blit(font_2.render('HCI 2023A', False, (212, 216, 232)), (350, 135))
# Word Length
word_length = 3
win.blit(font_3.render('CHOOSE DIFFICULTY', False, (212, 216, 232)), (150, 210))
pygame.draw.rect(win, (59, 89, 152), (170, 250, 85, 40))
word_length_button_three = pygame.Rect(170, 250, 85, 40)
win.blit(font_4.render('Easy', False, (255, 255, 255)), (185, 257))
pygame.draw.rect(win, (255, 255, 255), (270, 250, 85, 40))
word_length_button_four = pygame.Rect(270, 250, 85, 40)
win.blit(font_4.render('Medium', False, (59, 89, 152)), (292, 257))
pygame.draw.rect(win, (255, 255, 255), (370, 250, 85, 40))
word_length_button_random = pygame.Rect(370, 250, 85, 40)
win.blit(font_4.render('Hard', False, (59, 89, 152)), (375, 257))
# Time Limit
time_limit = 3
win.blit(font_3.render('CHOOSE TIME LIMIT', False, (212, 216, 232)), (180, 320))
pygame.draw.rect(win, (59, 89, 152), (170, 360, 85, 40))
time_limit_button_three = pygame.Rect(170, 360, 85, 40)
win.blit(font_4.render('Three', False, (255, 255, 255)), (185, 367))
pygame.draw.rect(win, (255, 255, 255), (270, 360, 85, 40))
time_limit_button_five = pygame.Rect(270, 360, 85, 40)
win.blit(font_4.render('Five', False, (59, 89, 152)), (292, 367))
pygame.draw.rect(win, (255, 255, 255), (370, 360, 85, 40))
time_limit_button_ten = pygame.Rect(370, 360, 85, 40)
win.blit(font_4.render('Eight', False, (59, 89, 152)), (390, 367))
# Game Start
win.blit(font_5.render('GAME Start !!!', False, (59, 89, 152)), (247, 433))
game_start_button = pygame.Rect(0, 420, 640, 60)
# Action
def word_length_button_three_pressed():
pygame.draw.rect(win, (117, 138, 182), (0, 200, 640, 110))
win.blit(font_3.render('CHOOSE DIFFICULTY', False, (212, 216, 232)), (150, 210))
pygame.draw.rect(win, (59, 89, 152), (170, 250, 85, 40))
win.blit(font_4.render('Easy', False, (255, 255, 255)), (185, 257))
pygame.draw.rect(win, (255, 255, 255), (270, 250, 85, 40))
win.blit(font_4.render('Medium', False, (59, 89, 152)), (292, 257))
pygame.draw.rect(win, (255, 255, 255), (370, 250, 85, 40))
win.blit(font_4.render('Hard', False, (59, 89, 152)), (375, 257))
def word_length_button_four_pressed():
pygame.draw.rect(win, (117, 138, 182), (0, 200, 640, 110))
win.blit(font_3.render('CHOOSE DIFFICULTY', False, (212, 216, 232)), (150, 210))
pygame.draw.rect(win, (255, 255, 255), (170, 250, 85, 40))
win.blit(font_4.render('Easy', False, (59, 89, 152)), (185, 257))
pygame.draw.rect(win, (59, 89, 152), (270, 250, 85, 40))
win.blit(font_4.render('Medium', False, (255, 255, 255)), (292, 257))
pygame.draw.rect(win, (255, 255, 255), (370, 250, 85, 40))
win.blit(font_4.render('Hard', False, (59, 89, 152)), (375, 257))
def word_length_button_random_pressed():
pygame.draw.rect(win, (117, 138, 182), (0, 200, 640, 110))
win.blit(font_3.render('CHOOSE DIFFICULTY', False, (212, 216, 232)), (150, 210))
pygame.draw.rect(win, (255, 255, 255), (170, 250, 85, 40))
win.blit(font_4.render('Easy', False, (59, 89, 152)), (185, 257))
pygame.draw.rect(win, (255, 255, 255), (270, 250, 85, 40))
win.blit(font_4.render('Medium', False, (59, 89, 152)), (292, 257))
pygame.draw.rect(win, (59, 89, 152), (370, 250, 85, 40))
win.blit(font_4.render('Hard', False, (255, 255, 255)), (375, 257))
def time_limit_button_three_pressed():
pygame.draw.rect(win, (176, 188, 213), (0, 310, 640, 110))
win.blit(font_3.render('CHOOSE TIME LIMIT', False, (212, 216, 232)), (180, 320))
pygame.draw.rect(win, (59, 89, 152), (170, 360, 85, 40))
win.blit(font_4.render('Three', False, (255, 255, 255)), (185, 367))
pygame.draw.rect(win, (255, 255, 255), (270, 360, 85, 40))
win.blit(font_4.render('Five', False, (59, 89, 152)), (292, 367))
pygame.draw.rect(win, (255, 255, 255), (370, 360, 85, 40))
win.blit(font_4.render('Eight', False, (59, 89, 152)), (390, 367))
def time_limit_button_five_pressed():
pygame.draw.rect(win, (176, 188, 213), (0, 310, 640, 110))
win.blit(font_3.render('CHOOSE TIME LIMIT', False, (212, 216, 232)), (180, 320))
pygame.draw.rect(win, (255, 255, 255), (170, 360, 85, 40))
win.blit(font_4.render('Three', False, (59, 89, 152)), (185, 367))
pygame.draw.rect(win, (59, 89, 152), (270, 360, 85, 40))
win.blit(font_4.render('Five', False, (255, 255, 255)), (292, 367))
pygame.draw.rect(win, (255, 255, 255), (370, 360, 85, 40))
win.blit(font_4.render('Eight', False, (59, 89, 152)), (390, 367))
def time_limit_button_eight_pressed():
pygame.draw.rect(win, (176, 188, 213), (0, 310, 640, 110))
win.blit(font_3.render('CHOOSE TIME LIMIT', False, (212, 216, 232)), (180, 320))
pygame.draw.rect(win, (255, 255, 255), (170, 360, 85, 40))
win.blit(font_4.render('Three', False, (59, 89, 152)), (185, 367))
pygame.draw.rect(win, (255, 255, 255), (270, 360, 85, 40))
win.blit(font_4.render('Five', False, (59, 89, 152)), (292, 367))
pygame.draw.rect(win, (59, 89, 152), (370, 360, 85, 40))
win.blit(font_4.render('Eight', False, (255, 255, 255)), (390, 367))
##############
# Game Start #
##############
# Game Set Up
life = 3
numero_aleatorio = None
def adj_en_char(en_char, en_char_x):
return en_char_x
def adj_en_char2(en_char, en_char_x):
return en_char_x
#############
# PAGE CORRECT #
#############
def correct():
win.fill((59, 89, 152))
win.blit(font_1.render('CORRECTO', False, (242, 242, 242)), (200, 55))
win.blit(font_1.render('Ganaste 10 puntos', False, (242, 242, 242)), (115, 120))
# Cargar la imagen
image_path = 'face_correct.png' # Cambia esto a la ruta de tu imagen
image = pygame.image.load(image_path)
# Obtener las dimensiones de la ventana y la imagen
win_width, win_height = win.get_size()
img_width, img_height = image.get_size()
# Calcular la posición para centrar la imagen en la ventana
x = (win_width - img_width) // 2
y = (win_height - img_height) // 2 + 120 # 120 es aproximadamente la posición y del último texto
# Dibujar la imagen en la ventana
win.blit(image, (x, y))
#############
# PAGE INCORRECT #
#############
def incorrect():
win.fill((59, 89, 152))
win.blit(font_1.render('INCORRECTO', False, (242, 242, 242)), (200, 55))
win.blit(font_1.render('Perdiste una vida ', False, (242, 242, 242)), (115, 120))
# Cargar la imagen
image_path = 'face_incorrect.png' # Cambia esto a la ruta de tu imagen
image = pygame.image.load(image_path)
# Obtener las dimensiones de la ventana y la imagen
win_width, win_height = win.get_size()
img_width, img_height = image.get_size()
# Calcular la posición para centrar la imagen en la ventana
x = (win_width - img_width) // 2
y = (win_height - img_height) // 2 + 120 # 120 es aproximadamente la posición y del último texto
# Dibujar la imagen en la ventana
win.blit(image, (x, y))
### random number ###
def show_card_three():
global numero_aleatorio
win.fill((59, 89, 152))
win.blit(font_1.render('Time', False, (242, 242, 242)), (215, 55))
win.blit(font_1.render('Countdown', False, (242, 242, 242)), (145, 120))
win.blit(font_2.render('Find the number on the cube and focus it on the camera:', False, (212, 216, 232)), (65, 235))
pygame.draw.rect(win, (242, 242, 242), (280, 280, 100, 160))
pygame.draw.rect(win, (176, 188, 213), (270, 270, 100, 160))
# Genera un número aleatorio
if numero_aleatorio is None:
numero_aleatorio = str(random.randint(1, 9))
en_char_1_x = 290
en_char_1_x = adj_en_char(numero_aleatorio, en_char_1_x)
win.blit(font_6.render(numero_aleatorio, False, (255, 255, 255)), (en_char_1_x, 270))
return numero_aleatorio
###
###
confirm_button = pygame.Rect(200, 415, 110, 40)
reset_button = pygame.Rect(330, 415, 110, 40)
###
# INTERFAZ NUMEROS
###
def three_choose_from_six():
global numero_aleatorio
global predicted_number
win.fill((59, 89, 152))
win.blit(font_2.render('Please choose the number below -interfaz :', False, (212, 216, 232)), (140, 50))
threading.Thread(target=run_digit_recognition_gui).start()
#subprocess.Popen(["python", "C:/Users/Ronny Amores/Desktop/Sexto Semestre EPN/HCI/PROYECTOI/Proyeto_Final_HCI/Infinite-Cube-with-AI-for-kids-/PRUEBAS_NUCLEO_FINAL.py"])
#pygame.draw.rect(win, (148, 148, 148), (270, 85, 100, 160))
pygame.draw.rect(win, (242, 242, 242), (235, 275, 80, 120))
pygame.draw.rect(win, (176, 188, 213), (230, 270, 80, 120))
while predicted_number is None:
time.sleep(0.1)
en_char_2_x = 247
if predicted_number is not None:
en_char_2_x = adj_en_char2(str(predicted_number), en_char_2_x)
win.blit(font_7.render(str(predicted_number), False, (255, 255, 255)), (en_char_2_x, 270))
else:
win.blit(font_7.render("Waiting...", False, (255, 255, 255)), (en_char_2_x, 270))
pygame.draw.rect(win, (255, 255, 255), (200, 415, 110, 40))
win.blit(font_4.render('Confirm', False, (59, 89, 152)), (220, 422))
pygame.draw.rect(win, (255, 255, 255), (330, 415, 110, 40))
win.blit(font_4.render('Reset', False, (59, 89, 152)), (360, 422))
win.blit(font_2.render('Mark : '+str(mark), False, (212, 216, 232)), (510, 10))
win.blit(font_2.render('Life : '+str(life), False, (212, 216, 232)), (20, 10))
#### RESET
def reset_detection():
try:
global predicted_number
global cap
global last_predictions
# Libera la cámara
cap.release()
# Pequeño retraso para asegurarnos de que la cámara se libere correctamente
time.sleep(2)
# Reinicia la predicción
with lock:
predicted_number = None
last_predictions = []
# Vuelve a inicializar la cámara
cap = cv2.VideoCapture(2 + cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, CAPTURE_WIDTH)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, CAPTURE_HEIGHT)
# Muestra nuevamente la ventana con el número a predecir
numero_aleatorio = show_card_three()
three_choose_from_six()
pygame.display.update() # Actualiza la pantalla
except Exception as e:
print("Error en reset_detection:")
print(traceback.format_exc())
def word_one_button_pressed():
pygame.draw.rect(win, (100, 100, 100), (30, 270, 80, 120))
def word_two_button_pressed():
pygame.draw.rect(win, (100, 100, 100), (130, 270, 80, 120))
def word_three_button_pressed():
pygame.draw.rect(win, (100, 100, 100), (230, 270, 80, 120))
def word_four_button_pressed():
pygame.draw.rect(win, (100, 100, 100), (330, 270, 80, 120))
def word_five_button_pressed():
pygame.draw.rect(win, (100, 100, 100), (430, 270, 80, 120))
def word_six_button_pressed():
pygame.draw.rect(win, (100, 100, 100), (530, 270, 80, 120))
next_button = pygame.Rect(0, 420, 640, 60)
music_three_button = pygame.Rect(60, 314, 80, 80)
music_four_button = pygame.Rect(30, 314, 80, 80)
restart_button = pygame.Rect(200, 265, 110, 40)
quit_button = pygame.Rect(330, 265, 110, 40)
# GAME OVER
def game_over():
win.fill((59, 89, 152))
win.blit(font_6.render('Game Over', False, (212, 216, 232)), (50, 10))
win.blit(font_1.render('Total Mark', False, (212, 216, 232)), (130, 160))
win.blit(font_1.render(str(mark), False, (212, 216, 232)), (430, 160))
pygame.draw.rect(win, (255, 255, 255), (200, 265, 110, 40))
win.blit(font_4.render('Restart', False, (59, 89, 152)), (220, 272))
pygame.draw.rect(win, (255, 255, 255), (330, 265, 110, 40))
win.blit(font_4.render('Quit', False, (59, 89, 152)), (365, 272))
# RESTART
def restart():
# Background
win.fill((59, 89, 152)) # title
pygame.draw.rect(win, (117, 138, 182), (0, 200, 640, 110)) # word length
pygame.draw.rect(win, (176, 188, 213), (0, 310, 640, 110)) # time limit
pygame.draw.rect(win, (235, 238, 244), (0, 420, 640, 60)) # game start
# Title
win.blit(font_1.render('CUBERSE', False, (242, 242, 242)), (215, 45))
win.blit(font_2.render('HCI 2023A', False, (212, 216, 232)), (350, 135))
# Word Length
win.blit(font_3.render('CHOOSE DIFFICULTY', False, (212, 216, 232)), (150, 210))
pygame.draw.rect(win, (59, 89, 152), (170, 250, 85, 40))
win.blit(font_4.render('Easy', False, (255, 255, 255)), (185, 257))
pygame.draw.rect(win, (255, 255, 255), (270, 250, 85, 40))
win.blit(font_4.render('Medium', False, (59, 89, 152)), (292, 257))
pygame.draw.rect(win, (255, 255, 255), (370, 250, 85, 40))
win.blit(font_4.render('Hard', False, (59, 89, 152)), (375, 257))
# Time Limit
win.blit(font_3.render('CHOOSE TIME LIMIT', False, (212, 216, 232)), (180, 320))
pygame.draw.rect(win, (59, 89, 152), (170, 360, 85, 40))
win.blit(font_4.render('Three', False, (255, 255, 255)), (185, 367))
pygame.draw.rect(win, (255, 255, 255), (270, 360, 85, 40))
win.blit(font_4.render('Five', False, (59, 89, 152)), (292, 367))
pygame.draw.rect(win, (255, 255, 255), (370, 360, 85, 40))
win.blit(font_4.render('Eight', False, (59, 89, 152)), (390, 367))
# Game Start
win.blit(font_5.render('Game Start !!!', False, (59, 89, 152)), (247, 433))
#---------------------------------
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if life == 0:
page = 4
game_over()
if page == 1:
show_card_three() # Mueve esta línea aquí
if event.type == pygame.USEREVENT:
time_count -= 1
time_text = int(time_count)
if time_text > time_limit:
time_text = time_limit
pygame.draw.rect(win, (59, 89, 152), (420, 50, 100, 160))
win.blit(font_6.render(str(time_text), True, (242, 242, 242)), (440, 50))
pygame.display.flip()
clock.tick(60)
if time_count <= 0:
page = 2
three_choose_from_six()
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = event.pos
if (word_length_button_three.collidepoint(mouse_pos)) & (page == 0):
life = 5
word_length_button_three_pressed()
if (word_length_button_four.collidepoint(mouse_pos)) & (page == 0):
life = 3
word_length_button_four_pressed()
if (word_length_button_random.collidepoint(mouse_pos)) & (page == 0):
life = 1
word_length_button_random_pressed()
if (time_limit_button_three.collidepoint(mouse_pos)) & (page == 0):
time_limit = 3
time_limit_button_three_pressed()
if (time_limit_button_five.collidepoint(mouse_pos)) & (page == 0):
time_limit = 5
time_limit_button_five_pressed()
if (time_limit_button_ten.collidepoint(mouse_pos)) & (page == 0):
time_limit = 8
time_limit_button_eight_pressed()
if (game_start_button.collidepoint(mouse_pos)) & (page == 0):
page = 1
time_count = time_limit + 1
show_card_three()
idx = 0
mark = 0
if (confirm_button.collidepoint(mouse_pos)) & (page == 2):
if str(predicted_number) == numero_aleatorio:
mark += 10
correct()
pygame.display.update()
pygame.time.wait(3000)
else:
life -= 1
incorrect()
pygame.display.update()
pygame.time.wait(3000) # Mostrar la pantalla "incorrect" durante 3 segundos
page = 1
time_count = time_limit + 3
numero_aleatorio = None
predicted_number = None
last_predictions = []
pygame.display.update()
if (reset_button.collidepoint(mouse_pos)) & (page == 2):
reset_detection()
if (restart_button.collidepoint(mouse_pos)) & (page == 4):
page = 0
life = 3
word_length = 3
time_limit = 3
restart()
if (quit_button.collidepoint(mouse_pos)) & (page == 4):
run = False
pygame.display.update()
pygame.quit()