def letraPulsada(self, let, btn): victoria = False self.errores = 0 btn.config(state=tk.DISABLED) if let not in self.ahorcado.palabra: self.errores = self.ahorcado.sumaError() threading.Thread(target=lambda: self.canvasHorca.itemconfig( self.imgHorca, image=self.imgFile[self.errores])).start() if self.errores < 6: self.sonido_efecto(files.get("error", "")) elif self.errores == 6: self.sonido_efecto(files.get("gameover", "")) self.datos.guardar_marcador(d=1) otra = tk.messagebox.askokcancel("AHORCADO", ( "Has perdido. La palabra era {}\n\n¿Otra partida?").format( self.ahorcado.palabra)) else: check = self.ahorcado.checkLetra(let) self.var.set(" ".join(check)) victoria = self.ahorcado.checkVictoria(check) if not victoria: self.sonido_efecto(files.get("acierto", "")) else: self.sonido_efecto(files.get("victoria", "")) self.datos.guardar_marcador(v=1) otra = tk.messagebox.askokcancel( "VICTORIA", "Felicidades, has ganado\n\n¿Otra partida?") if self.errores == 6 or victoria == True: if otra: self.cambiar_clase(self.game) # super().cambiar_clase(Game) else: self.cambiar_clase(self.startpage)
def __init__(self, master): super().__init__(master) self.master = master imgTitulo = tk.PhotoImage(file=files.get("titulo", "")) # try? canvas = tk.Canvas(self.master, width=530, height=48, background="#121", bd=0, highlightthickness=0) canvas.create_image(0, 0, anchor="nw", image=imgTitulo) canvas.pack(side=tk.TOP, expand=False, padx=30, pady=30) imgIcon = tk.PhotoImage(file=files.get("icono", "")) canvasIcon = tk.Canvas(self.master, width=128, height=128, background="#121", bd=0, highlightthickness=0) canvasIcon.create_image(0, 0, anchor="nw", image=imgIcon) canvasIcon.pack(side=tk.TOP, expand=False, padx=30, pady=10) btnGame = ttk.Button(self.master, text="Nuevo Juego", style="gran.TButton", width=25, command=lambda: self.cambiar_clase(self.game)) btnPunt = ttk.Button(self.master, text="Marcador", style="gran.TButton", width=25, command=lambda: self.cambiar_clase(self.marcador)) btnGame.pack(side=tk.TOP, fill=tk.BOTH, padx=30, pady=10, ipady=10) btnPunt.pack(side=tk.TOP, fill=tk.BOTH, padx=30, pady=0, ipady=10) imgPaypal = tk.PhotoImage(file=files.get("paypal", "")) tk.Button(self.master, image=imgPaypal, cursor="hand1", bd=0, highlightthickness=0, background="#121", activebackground="#121", command=self.paypal).pack(side=tk.BOTTOM, pady=10) self.master.mainloop()
def __init__(self, pop): self.popup = pop # self.popup = tk.Tk() self.popup.configure(background="#121") self.popup.overrideredirect(True) self.popup.attributes("-topmost", True) self.popup.focus_set() msg = ( "\nEL AHORCADO - {}\n\nEl juego arrancará enseguida,\n" "estamos recuperando datos y...").format(VERSION) label = tk.Label(self.popup, text=msg, fg="white", background="#121", font=("Helvetica", 14)) label.pack(side="top", padx=30, pady=5) self.progressbar = ttk.Progressbar(self.popup, length=150, mode="indeterminate") self.progressbar.pack(padx=30, pady=10) self.progressbar.start(10) self.popup.after(2000, self.popup.destroy) msg = "...preparando la horca" label = tk.Label( self.popup, text=msg, fg="white", background="#121", font=("Helvetica", 18)) label.pack(side="top", padx=30, pady=0) soga = tk.PhotoImage(file=files.get("derrotas", "")) canvasSoga = tk.Canvas( self.popup, width=64, height=64, bd=0, background="#121", highlightthickness=0) canvasSoga.create_image(0, 0, anchor="nw", image=soga) canvasSoga.pack(side=tk.TOP, expand=False, padx=30, pady=20) self.popup.mainloop()
def update_label(self, lbl, var): if self.count < 10: letras = ("________________________________" "AAAABCDEEEEFGHIIIIJKLMNÑOOOOPQRSTUUUUVWXYZ") palabra = "" self.sonido_efecto(files.get("tecla", "")) for x in range(7): letra = choice(letras) palabra = palabra + " " + letra var.set(palabra) lbl.after(100, lambda: self.update_label(lbl, var)) self.count += 1 else: self.var.set(" ".join(self.ahorcado.secreta)) if self.datos.nivel == "Temas": self.muestra_pista() self.teclado()
def vocabulario(self): filePalabras = files.get("vocabulario", "ERROR") try: with open(filePalabras, "r") as archivoPalabras: dataPalabras = json.load(archivoPalabras) except: print("ERROR: ARCHIVO DE PALABRAS CORRUPTO O NO ENCONTRADO.") self.palabra = "AHORCADO" # sys.exit(1) self.pista = ( "La aplicación está utilizando una palabra comodín porque " "posiblemente el archivo de palabras está corrupto o no ha " "sido encontrado.\n\nPrueba a jugar en otro nivel o descarga " "nuevamente la aplicación desde la web del proyecto.") else: self.todosTemas = dataPalabras["VOCABULARIO"] self.categoria = choice(self.todosTemas) self.pista = self.categoria["PISTA"] self.palabra = choice(self.categoria["PALABRAS"])
def __init__(self, master): super().__init__(master) self.master = master imgM = tk.PhotoImage(file=files.get("marcador", "")) canvasM = tk.Canvas(self.master, width=435, height=48, background="#121", bd=0, highlightthickness=0) canvasM.create_image(0, 0, anchor="nw", image=imgM) canvasM.pack(side=tk.TOP, expand=False, padx=30, pady=60) frameTrofeos = tk.Frame(self.master, bg="#121") frameV = tk.Frame(frameTrofeos, bg="#121") trofeo = tk.PhotoImage(file=files.get("triunfos", "")) canvasTrofeo = tk.Canvas(frameV, width=64, height=64, background="#121", bd=0, highlightthickness=0) canvasTrofeo.create_image(0, 0, anchor="nw", image=trofeo) canvasTrofeo.pack(side=tk.TOP, expand=False, padx=30) self.tanV = tk.StringVar() puntVictorias = tk.Label(frameV, textvariable=self.tanV, fg="white", bg="#121", font=("Courier", 32, "bold")) self.tanV.set(self.datos.victorias) puntVictorias.pack(side=tk.TOP, expand=False, padx=30, pady=20) frameV.pack(side=tk.LEFT) frameD = tk.Frame(frameTrofeos, bg="#121") soga = tk.PhotoImage(file=files.get("derrotas", "")) canvasSoga = tk.Canvas(frameD, width=64, height=64, background="#121", bd=0, highlightthickness=0) canvasSoga.create_image(0, 0, anchor="nw", image=soga) canvasSoga.pack(side=tk.TOP, expand=False, padx=30) self.tanD = tk.StringVar() puntDerrotas = tk.Label(frameD, textvariable=self.tanD, fg="white", bg="#121", font=("Courier", 32, "bold")) self.tanD.set(self.datos.derrotas) puntDerrotas.pack(side=tk.TOP, expand=False, padx=30, pady=20) frameD.pack(side=tk.LEFT) frameTrofeos.pack(side=tk.TOP, expand=False, pady=2) frameBtn = tk.Frame(self.master, bg="#121") ttk.Button(frameBtn, text="Reset", width=10, style="gran.TButton", command=self.resetear).pack(side=tk.LEFT, ipady=8) ttk.Button(frameBtn, text="Inicio", width=10, style="gran.TButton", command=lambda: self.cambiar_clase(self.startpage)).pack( side=tk.LEFT, ipady=8) ttk.Button(frameBtn, text="Jugar", width=10, style="gran.TButton", command=lambda: self.cambiar_clase(self.game)).pack( side=tk.LEFT, ipady=8) frameBtn.pack(side=tk.BOTTOM, expand=False, padx=30, pady=20) self.master.mainloop()
def __init__(self, master): self.datos = Datos() try: self.startpage, self.game, self.marcador = [ cls for cls in Base.__subclasses__() ] except ValueError as e: Dialogo(master, error=e) except Exception as e: Dialogo(master, error=e) # Fuentes y estilos fuentes = ["TkDefaultFont", "TkMenuFont", "TkCaptionFont"] for f in fuentes: font.nametofont(f).configure(family="Helvetica", size=12, weight="normal") ttk.Style().configure('gran.TButton', font=("Helvetica", 18)) ttk.Style().configure('key.TButton', font=("Helvetica", 16)) # Ventana self.master = master self.master.protocol("WM_DELETE_WINDOW", lambda: sys.exit()) self.master.title("El Ahorcado") self.master.configure(background="#121") # Menu self.menuApp = tk.Menu(self.master, relief=tk.FLAT) self.master.config(menu=self.menuApp) self.menuGame = tk.Menu(self.menuApp, tearoff=0, bd=2, activeborderwidth=2, relief=tk.GROOVE) self.menuEdit = tk.Menu(self.menuApp, tearoff=0, bd=2, activeborderwidth=2, relief=tk.GROOVE) self.menuInfo = tk.Menu(self.menuApp, tearoff=0, bd=2, activeborderwidth=2, relief=tk.GROOVE) self.menuApp.add_cascade(menu=self.menuGame, label="Juego") self.menuApp.add_cascade(menu=self.menuEdit, label="Editar") self.menuApp.add_cascade(menu=self.menuInfo, label="Info") self.menuGame.add_command( label="Nuevo Juego", underline=0, command=lambda: self.cambiar_clase(self.game), accelerator="Alt+N") self.menuGame.add_command( label="Marcador", command=lambda: self.cambiar_clase(self.marcador)) self.menuGame.add_separator() self.menuGame.add_command(label="Salir", command=sys.exit, accelerator="Alt+Q") self.master.bind_all("<Alt-n>", lambda event: self.cambiar_clase(self.game)) self.master.bind_all("<Alt-q>", lambda event: sys.exit()) self.niveles = tk.Menu(self.menuEdit, tearoff=0, bd=2, activeborderwidth=2, relief=tk.GROOVE) self.menuEdit.add_cascade(menu=self.niveles, label="Nivel ") for clave in self.modos: self.niveles.add_command(label=clave, command=lambda arg=clave: self. cambiar_nivel(self.niveles, arg)) self.niveles.entryconfigure(self.modos[self.datos.nivel], state="disabled") self.sonido = tk.Menu(self.menuEdit, tearoff=0, bd=2, activeborderwidth=2, relief=tk.GROOVE) self.menuEdit.add_cascade(menu=self.sonido, label="Sonido ") self.sonido.add_command( label="OK", command=lambda: self.cambiar_sonido(self.sonido, True)) self.sonido.add_command( label="Mute", command=lambda: self.cambiar_sonido(self.sonido, False)) if audio: entry = 0 if self.datos.sonido else 1 else: self.cambiar_sonido(self.sonido, False) entry = 0 self.sonido.entryconfigure(entry, state="disabled") self.menuInfo.add_command( label="Ayuda", command=lambda: self.info(files.get("help", "ERROR"))) self.menuInfo.add_command( label="Acerca de", command=lambda: self.info(files.get("about", "ERROR")))
def muestra_pista(self): self.filePista = tk.PhotoImage(file=files.get("pista", "")) self.canvasPista.create_image(0, 0, anchor="nw", image=self.filePista) self.canvasPista.bind( "<Button-1>", lambda e: tk.messagebox.showinfo("Pista", self.ahorcado.pista))