Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 6, 2020 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/1cbbf64a83c83463063175472e711d72 to your computer and use it in GitHub Desktop.
Save parzibyte/1cbbf64a83c83463063175472e711d72 to your computer and use it in GitHub Desktop.
# Ocultar todos los cuadros
def ocultar_todos_los_cuadros():
for fila in cuadros:
for cuadro in fila:
cuadro.mostrar = False
cuadro.descubierto = False
def aleatorizar_cuadros():
# Elegir X e Y aleatorios, intercambiar
cantidad_filas = len(cuadros)
cantidad_columnas = len(cuadros[0])
for y in range(cantidad_filas):
for x in range(cantidad_columnas):
x_aleatorio = random.randint(0, cantidad_columnas - 1)
y_aleatorio = random.randint(0, cantidad_filas - 1)
cuadro_temporal = cuadros[y][x]
cuadros[y][x] = cuadros[y_aleatorio][x_aleatorio]
cuadros[y_aleatorio][x_aleatorio] = cuadro_temporal
def comprobar_si_gana():
if gana():
pygame.mixer.Sound.play(sonido_exito)
reiniciar_juego()
# Regresa False si al menos un cuadro NO está descubierto. True en caso de que absolutamente todos estén descubiertos
def gana():
for fila in cuadros:
for cuadro in fila:
if not cuadro.descubierto:
return False
return True
def reiniciar_juego():
global juego_iniciado
juego_iniciado = False
def iniciar_juego():
pygame.mixer.Sound.play(sonido_clic)
global juego_iniciado
# Aleatorizar 3 veces
for i in range(3):
aleatorizar_cuadros()
ocultar_todos_los_cuadros()
juego_iniciado = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment