Juego atrapar el boton y arreglo de la barra de carga del pomodoro
This commit is contained in:
parent
d6d750ae33
commit
5b8f4f45b7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
52
app/game.py
52
app/game.py
|
@ -0,0 +1,52 @@
|
|||
import threading
|
||||
import tkinter as tk
|
||||
import random
|
||||
import time
|
||||
|
||||
class HiloJuego:
|
||||
def __init__(self, frame):
|
||||
self.frame = frame
|
||||
|
||||
self.score = 0
|
||||
self.running = False
|
||||
|
||||
self.label_score = tk.Label(frame, text=f"Puntaje: {self.score}", font=("Arial", 16), bg="lightgray")
|
||||
self.label_score.pack(pady=10)
|
||||
|
||||
self.start_button = tk.Button(frame, text="Iniciar Juego", command=self.iniciar_juego)
|
||||
self.start_button.pack(pady=5)
|
||||
|
||||
self.target_button = tk.Button(frame, text="¡Click me!", state="disabled", command=self.incrementar_puntaje)
|
||||
self.target_button.pack(pady=20)
|
||||
|
||||
def iniciar_juego(self):
|
||||
self.running = True
|
||||
self.score = 0
|
||||
self.label_score.config(text=f"Puntaje: {self.score}")
|
||||
self.start_button.config(state="disabled")
|
||||
self.target_button.config(state="normal")
|
||||
|
||||
# Hilo para mover el botón
|
||||
self.hilo_movimiento = threading.Thread(target=self.mover_boton)
|
||||
self.hilo_movimiento.daemon = True
|
||||
self.hilo_movimiento.start()
|
||||
|
||||
def mover_boton(self):
|
||||
while self.running:
|
||||
x = random.randint(50, self.frame.winfo_width() - 100)
|
||||
y = random.randint(50, self.frame.winfo_height() - 100)
|
||||
|
||||
self.target_button.place(x=x, y=y)
|
||||
time.sleep(1)
|
||||
|
||||
def incrementar_puntaje(self):
|
||||
self.score += 1
|
||||
self.label_score.config(text=f"Puntaje: {self.score}")
|
||||
|
||||
#Fin del juego
|
||||
if self.score >= 10:
|
||||
self.running = False
|
||||
self.start_button.config(state="normal")
|
||||
self.target_button.config(state="disabled")
|
||||
self.target_button.place_forget()
|
||||
self.label_score.config(text=f"¡Juego Terminado! Puntaje final: {self.score}")
|
|
@ -91,6 +91,7 @@ class PomodoroTimer:
|
|||
self.remaining_time = self.work_time if not self.is_break else self.break_time
|
||||
self.update_timer_label()
|
||||
self.progress["value"] = 0
|
||||
self.progress["maximum"] = 100
|
||||
|
||||
def apply_settings(self):
|
||||
try:
|
||||
|
@ -103,20 +104,23 @@ class PomodoroTimer:
|
|||
messagebox.showerror("Error", "Por favor, ingresa valores numéricos válidos.")
|
||||
|
||||
def run_timer(self):
|
||||
total_time = self.remaining_time # Guarda el tiempo total inicial
|
||||
while self.remaining_time > 0 and self.is_running:
|
||||
time.sleep(1)
|
||||
self.remaining_time -= 1
|
||||
self.update_timer_label()
|
||||
self.progress["value"] = (self.work_time if not self.is_break else self.break_time) - self.remaining_time
|
||||
# Calcula el progreso como porcentaje
|
||||
elapsed_time = total_time - self.remaining_time
|
||||
progress_value = (elapsed_time / total_time) * 100
|
||||
self.progress["value"] = progress_value
|
||||
|
||||
if self.remaining_time == 0 and self.is_running:
|
||||
self.is_running = False
|
||||
self.is_break = not self.is_break
|
||||
# Actualizar el tiempo restante según la nueva fase
|
||||
self.remaining_time = self.break_time if self.is_break else self.work_time
|
||||
self.progress["maximum"] = self.break_time if self.is_break else self.work_time # Actualiza el máximo
|
||||
self.progress["maximum"] = 100
|
||||
self.update_timer_label()
|
||||
self.progress["value"] = 0 # Reinicia la barra
|
||||
self.progress["value"] = 0
|
||||
messagebox.showinfo(
|
||||
"Pomodoro Finalizado",
|
||||
"¡Tiempo de descanso!" if self.is_break else "¡Tiempo de trabajar!",
|
||||
|
@ -125,6 +129,7 @@ class PomodoroTimer:
|
|||
self.start_timer()
|
||||
|
||||
|
||||
|
||||
def update_timer_label(self):
|
||||
self.timer_label.config(text=self.format_time(self.remaining_time))
|
||||
|
||||
|
|
4
main.py
4
main.py
|
@ -11,6 +11,7 @@ import time
|
|||
import datetime
|
||||
import psutil
|
||||
from app import scraping
|
||||
from app import game
|
||||
|
||||
|
||||
def update_time(status_bar):
|
||||
|
@ -115,6 +116,9 @@ for i in range(1, 6):
|
|||
pomodoro.PomodoroTimer(tab)
|
||||
elif i == 3:
|
||||
notebook.add(tab, text="Gestor de tareas", padding=4)
|
||||
elif i == 4:
|
||||
notebook.add(tab,text='Juego', padding=4)
|
||||
hilo_juego = game.HiloJuego(tab)
|
||||
else:
|
||||
notebook.add(tab, text=f"Solapa {i}", padding=4)
|
||||
# Añadir un Label en cada solapa para diferenciarla
|
||||
|
|
Loading…
Reference in New Issue