import random
from tkinter import *
# Configurações da janela principal
root = Tk()
root.geometry("400x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Jogo dos Copos")
# Título do jogo
titulo = Label(text="Jogo dos Copos", font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05)
# Subtítulos para as cores
sub1_text = Label(text="Vermelho", font=("Arial", 20, "bold"), bg="#103030", fg="#49e3e3")
sub1_text.place(relx=0.15, rely=0.25)
sub2_text = Label(text="Azul", font=("Arial", 20, "bold"), bg="#103030", fg="#49e3e3")
sub2_text.place(relx=0.3, rely=0.4)
sub3_text = Label(text="Verde", font=("Arial", 20, "bold"), bg="#103030", fg="#49e3e3")
sub3_text.place(relx=0.28, rely=0.55)
# Variáveis para armazenar a entrada do usuário
Vermelho = StringVar()
Vermelho_entrada = Entry(textvariable=Vermelho, font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Vermelho_entrada.place(relx=0.55, rely=0.26, relwidth=0.35)
Azul = StringVar()
Azul_entrada = Entry(textvariable=Azul, font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Azul_entrada.place(relx=0.55, rely=0.4, relwidth=0.35)
Verde = StringVar()
Verde_entrada = Entry(textvariable=Verde, font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Verde_entrada.place(relx=0.55, rely=0.55, relwidth=0.35)
# Inicializar a ordem das cores
cores_misturadas = []
# Função para limpar as entradas
def limpar():
Verde_entrada.delete(0, END)
Azul_entrada.delete(0, END)
Vermelho_entrada.delete(0, END)
resultado_texto.config(text="")
# Função para misturar as cores
def misturar_copos():
global cores_misturadas
cores_misturadas = ['Vermelho', 'Azul', 'Verde']
random.shuffle(cores_misturadas)
limpar()
resultado_texto.config(text="Copos misturados!\n Tente adivinhar a nova ordem.")
# Função para verificar a adivinhação do usuário
def app():
try:
red = int(Vermelho.get())
green = int(Verde.get())
blue = int(Azul.get())
# Verifica se as entradas estão entre 1 e 3
if red not in [1, 2, 3] or green not in [1, 2, 3] or blue not in [1, 2, 3]:
resultado_texto.config(text="Por favor, insira números entre 1 e 3.")
return
# Converte as entradas em uma lista de cores
cores_usuario = [None, None, None]
cores_usuario[red-1] = "Vermelho"
cores_usuario[green-1] = "Verde"
cores_usuario[blue-1] = "Azul"
# Verifica se a adivinhação está correta
if cores_usuario == cores_misturadas:
resultado_texto.config(text="Parabéns! Você adivinhou a ordem correta!")
else:
resultado_texto.config(text=f"Que pena! A ordem correta era:\n"
f" {', '.join(cores_misturadas)}.")
except ValueError:
resultado_texto.config(text="Por favor, insira números válidos.")
# Botões do jogo
but1 = Button(text="Verificar", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1)
but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1)
but_novo_jogo = Button(text="Novo Jogo", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=misturar_copos)
but_novo_jogo.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1)
# Label para mostrar o resultado
resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
# Iniciar o jogo misturando os copos
misturar_copos()
# Iniciar o loop principal do Tkinter
root.mainloop()