import pygame
import random
import sys

# Inicialización de Pygame
pygame.init()

# Configuración de la ventana
ANCHO, ALTO = 800, 600
ventana = pygame.display.set_mode((ANCHO, ALTO))
pygame.display.set_caption("Tragaperras")

# Carga de recursos
fondo = pygame.image.load("fondo_tragaperras.jpg")
simbolos_img = pygame.image.load("simbolos.jpg")

# Colores
BLANCO = (255, 255, 255)

# Clase para representar una ruleta
class Ruleta:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.simbolos = ["🍒", "🍊", "🍇", "🔔", "💎"]  # Puedes personalizar los símbolos
        self.resultado = random.choice(self.simbolos)

    def girar(self):
        # Simula el giro de la ruleta
        self.resultado = random.choice(self.simbolos)

    def dibujar(self):
        ventana.blit(simbolos_img, (self.x, self.y), area=self.simbolos.index(self.resultado) * 100)

# Crear tres ruletas
ruleta1 = Ruleta(100, 200)
ruleta2 = Ruleta(300, 200)
ruleta3 = Ruleta(500, 200)

# Función para girar las ruletas
def girar_ruletas():
    ruleta1.girar()
    ruleta2.girar()
    ruleta3.girar()

# Bucle principal
while True:
    for evento in pygame.event.get():
        if evento.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        elif evento.type == pygame.MOUSEBUTTONDOWN:
            # Si se hace clic en el botón "Jugar"
            if 400 <= evento.pos[0] <= 500 and 450 <= evento.pos[1] <= 500:
                girar_ruletas()

    # Dibuja el fondo
    ventana.blit(fondo, (0, 0))

    # Dibuja las ruletas y el botón "Jugar"
    ruleta1.dibujar()
    ruleta2.dibujar()
    ruleta3.dibujar()
    pygame.draw.rect(ventana, (100, 100, 100), (400, 450, 100, 50))
    fuente_botón = pygame.font.Font(None, 24)
    texto_botón = fuente_botón.render("¡Jugar!", True, BLANCO)
    ventana.blit(texto_botón, (410, 460))

    pygame.display.flip()
