Example #1
0
            tiempo_final = time.time()
            tiempo_total = tiempo_final - tiempo_inicial

            # Genera horas, minutos y segundos
            tiempo = "Tiempo total " + convertir_segundos(tiempo_total)

            render.final((x, y), tiempo)

            ev = gl.wait(gl.EventType.KeyPress)

            return


def convertir_segundos(segundos):
    '''Recibe una cantidad de segundos (float), y devuelve la cantidad de horas, minutos, y segundos que representan en formato hh:mm:ss'''
    h = str(int(segundos // 3600))
    segundos %= 3600

    m = str(int(segundos // 60))
    segundos %= 60

    s = str(int(segundos))

    h, m, s = map(lambda num: num if len(num) > 1 else "0" + num, [h, m, s])

    return f"{h}:{m}:{s}"


gl.init(main)
Example #2
0
                juego = tetris.mover(juego, 2)
              if tecla == lista_teclas[0]:
                return
              if tecla == lista_teclas[6]:
                juego = tetris.rotar(juego)    
              if tecla == lista_teclas[4]:
                guardar_partida(juego)
              if tecla == lista_teclas[2]:
                juego = recuperar_partida()                           
              # Actualizar el juego, según la tecla presionada
        timer_bajar -= 1
        if timer_bajar == 0:  
            timer_bajar = ESPERA_DESCENDER 
            juego, siguiente_pieza = tetris.avanzar(juego, siguiente)
            if siguiente_pieza:
              siguiente = tetris.generar_pieza()
            if tetris.terminado(juego):
              gamelib.draw_image('img/perdiste.gif', 50, 200)
              t2 = time.time()
              tiempo_final = t2- t1
              gamelib.draw_rectangle(0, 0, 595, 60, outline='white', fill='salmon')
              gamelib.draw_text('Tu tiempo fue de {} segundos'.format(tiempo_final), 10, 17, fill='#000', size=18, anchor='nw')
              puntuaciones(tiempo_final)
              break

    while gamelib.is_alive():
      ordenar_puntuaciones()
      event = gamelib.wait(gamelib.EventType.KeyPress)
          # Descender la pieza automáticamente
gamelib.init(main)