Mundo em Python

Jogo de Embaralhar Palavras

from tkinter import *
import random
palavras = [
"python","computador","desenvolver","algoritmo","teclado",
"monitor","internet","software","hardware","codigo",
"variavel","sistema","memoria","processador","rede",
"dados","estrutura","classe","objeto","metodo",
"projeto","servidor","cliente","arquivo","lista",
"dicionario","tupla","numero","texto","entrada",
"saida","comando","terminal","programa","jogo",
"logica","teste","janela","caderno","cadeira",
"mesa","livro"
]
pontuacao = 0
tempo = 30
palavra = ""
after_id = None
def nova_palavra():
global palavra, tempo, after_id if after_id:
root.after_cancel(after_id) tempo = 30
atualizar_tempo() palavra = random.choice(palavras)
print(palavra)
palavra_lista = list(palavra)
random.shuffle(palavra_lista)
palavra_embaralhada = "".join(palavra_lista) palavra_label.config(text=palavra_embaralhada)
resultado_label.config(text="", bg="#cfe2f3")
resposta.set("")
def verificar():
global pontuacao tentativa = resposta.get() if tentativa.lower() == palavra:
pontuacao += 1
resultado_label.config(text=" Correto!", bg="#90ee90")
pontuacao_label.config(text=f"Pontuação: {pontuacao}")
root.after(1500, nova_palavra) # reinicia automaticamente
else:
resultado_label.config(text=f" Errado! Era: {palavra}", bg="#ff7f7f")
root.after(2000, nova_palavra)
def atualizar_tempo():
global tempo, after_id tempo_label.config(text=f"Tempo: {tempo}s") if tempo > 0:
tempo -= 1
after_id = root.after(1000, atualizar_tempo)
else:
resultado_label.config(text=f"Tempo esgotado! Era: {palavra}", bg="#ff7f7f")
root.after(2000, nova_palavra)
root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Jogo de Embaralhar Palavras") titulo = Label(
root,
text="Tenta Adivinhar a Palavra",
font=("Arial", 26, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.pack(pady=15) palavra_label = Label(
root,
text="",
font=("Arial", 24, "bold"),
bg="#103030",
fg="white"
)
palavra_label.pack(pady=10) resposta = StringVar() entrada = Entry(
root,
textvariable=resposta,
font=("Arial", 16, "bold"),
justify="center"
)
entrada.pack(pady=10)
entrada.focus() Button(
root,
text="Verificar",
font=("Arial", 12, "bold"),
bg="#107db2",
fg="white",
command=verificar
).pack(pady=5) Button(
root,
text="Nova Palavra",
font=("Arial", 12, "bold"),
bg="#1f8b4c",
fg="white",
command=nova_palavra
).pack(pady=5) pontuacao_label = Label(
root,
text="Pontuação: 0",
font=("Arial", 14, "bold"),
bg="#103030",
fg="#49e3e3"
)
pontuacao_label.pack(pady=5) tempo_label = Label(
root,
text="Tempo: 30s",
font=("Arial", 14, "bold"),
bg="#103030",
fg="orange"
)
tempo_label.pack(pady=5) resultado_label = Label(
root,
text="",
font=("Arial", 14, "bold"),
bg="#cfe2f3",
width=50
)
resultado_label.pack(pady=15)
nova_palavra()
root.mainloop()
0