import streamlit as st import json import time import random import os # ---------------- CONFIG ---------------- st.set_page_config( page_title="DETRAN Pro Simulator", layout="wide" ) # ---------------- CONSTANTES ---------------- PISTA_URL = "https://images.unsplash.com/photo-1505852679233-d9fd70aff56d?auto=format&fit=crop&w=1200&q=60" RANKING_FILE = "ranking.json" # ---------------- BANCO DE QUESTÕES ---------------- QUESTOES_BASE = [ { "pergunta": "Preferência em cruzamento sem sinalização?", "opcoes": ["Vem pela direita", "Vem pela esquerda", "Maior velocidade"], "correta": "Vem pela direita" }, { "pergunta": "Placa R-1 (PARE) exige:", "opcoes": ["Reduzir", "Parar totalmente", "Ceder se vier carro"], "correta": "Parar totalmente" }, { "pergunta": "Distância mínima para ultrapassar ciclista:", "opcoes": ["0,5m", "1,5m", "2,0m"], "correta": "1,5m" }, { "pergunta": "Uso de celular dirigindo gera infração:", "opcoes": ["Média", "Grave", "Gravíssima"], "correta": "Gravíssima" } ] # ---------------- FUNÇÕES ---------------- def load_ranking(): if not os.path.exists(RANKING_FILE): return [] try: with open(RANKING_FILE, "r") as f: return json.load(f) except: return [] def save_ranking(data): with open(RANKING_FILE, "w") as f: json.dump(data, f, indent=4) def reset_game(): st.session_state.pos = 0 st.session_state.vidas = 3 st.session_state.erros = 0 st.session_state.start_time = time.time() st.session_state.questoes = random.sample(QUESTOES_BASE, len(QUESTOES_BASE)) # ---------------- LOGIN ---------------- if "user" not in st.session_state: st.session_state.user = None if st.session_state.user is None: st.title("🔐 Login - DETRAN Pro Simulator") username = st.text_input("Digite seu nome para começar") if st.button("Entrar"): if username.strip(): st.session_state.user = username.strip() reset_game() st.rerun() st.stop() # ---------------- ESTADO INICIAL ---------------- if "pos" not in st.session_state: reset_game() # ---------------- CSS DINÂMICO ---------------- velocidade = max(0.8, 3 - (st.session_state.pos * 0.4)) st.markdown(f""" """, unsafe_allow_html=True) # ---------------- LAYOUT ---------------- st.title(f"🏎️ DETRAN Pro Simulator") st.caption(f"Jogador: {st.session_state.user}") col1, col2 = st.columns([2,1]) # ---------------- AREA VISUAL ---------------- with col1: st.markdown("""