Por favor, implementa un temporizador que represente el tiempo que tiene el usuario para…
- User
Por favor, implementa un temporizador que represente el tiempo que tiene el usuario para responder la pregunta en cuestión. Una vez se termine el tiempo establecido, debe aparecer un mensaje en pantalla que haga evidencia que el tiempo se ha terminado, junto con el puntaje que tuviese el usuario en ese momento: import json import random import os import googletrans from googletrans import Translator from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.textinput import TextInput from kivy.uix.screenmanager import ScreenManager, Screen from kivy.clock import Clock from kivy.metrics import dp
... (mantén las funciones cargar_preguntas, mostrar_menu, mostrar_mensaje_porcentaje, jugar, jugar_de_nuevo, seleccionar_idioma, guardar_puntuacion y ver_mejores_puntuaciones) ...
def cargar_preguntas(): with open("preguntas_es.json", "r", encoding="utf-8") as f: preguntas = json.load(f) return preguntas
def guardar_puntuacion(puntuacion): archivo_puntuaciones = "mejores_puntuaciones.txt"
codeif not os.path.exists(archivo_puntuaciones): with open(archivo_puntuaciones, "w") as f: f.write(f"{puntuacion}\n") else: with open(archivo_puntuaciones, "r") as f: puntuaciones = [int(linea.strip()) for linea in f.readlines()] puntuaciones.append(puntuacion) puntuaciones.sort(reverse=True) puntajes = puntuaciones[:5] with open(archivo_puntuaciones, "w") as f: for puntuacion in puntajes: f.write(f"{puntuacion}\n")def cargar_puntuaciones(): archivo_puntuaciones = "mejores_puntuaciones.txt"
codeif os.path.exists(archivo_puntuaciones): with open(archivo_puntuaciones, "r") as f: puntuaciones = [int(linea.strip()) for linea in f.readlines()] else: puntuaciones = [] return puntuacionesdef traducir(texto, idioma): translator = Translator() traduccion = translator.translate(texto, dest=idioma) return traduccion.text
class LanguageScreen(Screen): def seleccionar_idioma(self, idioma): self.manager.idioma = idioma self.manager.current = "menu"
class MainMenu(Screen): def init(self, **kwargs): super(MainMenu, self).(**kwargs) self.layout = BoxLayout(orientation='vertical') self.add_widget(Label(text='Menú principal')) self.play_button = Button(text='Jugar') self.play_button.bind(on_press=self.start_game) self.layout.add_widget(self.play_button) self.high_scores_button = Button(text='Ver mejores puntuaciones') self.high_scores_button.bind(on_press=self.show_high_scores) self.layout.add_widget(self.high_scores_button) self.exit_button = Button(text='Salir') self.exit_button.bind(on_press=self.exit_app) self.layout.add_widget(self.exit_button) self.add_widget(self.layout)
- Assistant
Hice algunas modificaciones en tu código para agregar un temporizador y mostrar un mensaje cuando el tiempo se agote: