Пример #1
0
def lista_puntajes(juego, ruta_lista_puntajes):
    lista_puntajes = []
    try:
        with open(ruta_lista_puntajes, "r", newline='') as f:
            lista_puntajes = csv.reader(f)
            lista_puntajes = list(lista_puntajes)
    except:
        with open(ruta_lista_puntajes, "x", newline='') as f:
            pass
    with open(ruta_lista_puntajes, "w", newline='') as f:
        if len(lista_puntajes) < 10:
            nombre = gamelib.input("Ingresa tu nombre:")
            lista_puntajes.append([nombre, juego.puntaje])
        else:
            for nombre, puntaje in lista_puntajes:
                if int(puntaje) < juego.puntaje:
                    nombre = gamelib.input("Ingresa tu nombre:")
                    lista_puntajes.append([nombre, juego.puntaje])
                    break
        lista_puntajes = sorted(lista_puntajes,
                                key=lambda elemento: int(elemento[1]),
                                reverse=True)
        if len(lista_puntajes) > 10:
            lista_puntajes.pop(len(lista_puntajes) - 1)
        dibujar_lista_puntajes(lista_puntajes)
        escribir = csv.writer(f)
        for elem in lista_puntajes:
            escribir.writerow(elem)
Пример #2
0
def pedir_opcion():
    while True:
        opcion = gamelib.input(
            'Ingrese la cantidad de jugadores, puede ser entre 2 o 4: ')
        if ((opcion == None) or (opcion.isdigit() == False)
                or (int(opcion) < 2 or int(opcion) > 4)):
            gamelib.say('Opcion invalida, vuelva a ingresar')
        else:
            break
    return int(opcion)
Пример #3
0
 def validar_apuesta(self, jugador, apuesta):
     while True:
         if apuesta == None or apuesta.isdigit() == False or (
                 int(apuesta) > self.ronda_actual) or (0 > int(apuesta)):
             gamelib.say('Opcion incorrecta, vuelva a ingresar ')
             apuesta = gamelib.input('Cuantas bazas vas a obtener ' +
                                     jugador)
         else:
             break
     return int(apuesta)
Пример #4
0
def es_nivel(caracter, diccionario):
    '''
    Recibe un caracter y un diccionario, entra en el ciclo indefinido y 
    si el caracter ingresado po rel ususario es un numero y esta en el 
    diccionario lo retorna, de lo contrario vuelve a preguntar.
    '''
    while True:
        if caracter.isdigit() and int(caracter) in diccionario:
            return int(caracter)
        caracter = gamelib.input("Elegí otro nivel, por favor:")
Пример #5
0
def top_puntajes(leaderboard, puntaje):
    '''
    Recibe un puntaje y evalua si entra en el TOP10.
    Si entra en el top 10 se pide el nombre al Usuario, se suma el nombre, puntaje al TOP10 y se guarda en el archivo
    '''
    nombre = ""

    if tetris.entra_en_top10(leaderboard, puntaje):
        while nombre == "" or nombre == None:
            nombre = gamelib.input(
                f"Puntaje {puntaje} es TOP10, Ingrese su nombre: ")
        leaderboard = tetris.sumar_leaderboard(leaderboard, nombre, puntaje)
        tetris.guardar_leaderboard(leaderboard)
        return leaderboard, True

    return leaderboard, False
Пример #6
0
    def inicializar_juego(self, cantidad_jugadores):
        palos = ('D', 'H', 'S', 'C')
        valores = ('2', '3', '4', '5', '6', '7', '8', '9', 'J', 'Q', 'K', 'A')
        for palo in palos:
            for valor in valores:
                self.mazo.apilar((str(valor) + str(palo)))

        self.cantidad_jugadores = cantidad_jugadores
        for numero_jugador in range(1, cantidad_jugadores + 1):
            while True:
                nombre_jugador = gamelib.input(
                    "Ingrese nombre del jugador numero " + str(numero_jugador))
                if ((nombre_jugador == None) or (len(nombre_jugador) == 0)):
                    gamelib.say(
                        'Se necesita un nombre para poder continuar,porfavor vuelva a ingresar'
                    )
                else:
                    jugador = Jugador(nombre_jugador, 0)
                    self.lista_jugadores.append(jugador)
                    break
Пример #7
0
def puntuaciones(tiempo):
  nombre = gamelib.input('Ingrese su nombre')
  with open('puntuaciones.txt', 'a') as puntuaciones:
    puntuaciones.write(nombre + ' ')
    puntuaciones.write(str(tiempo) + ' ' + 'segundos')
    puntuaciones.write('\n')
def main():
    # Inicializar el estado del juego
    gamelib.resize(RES, RES)
    teclas = tetris.cargar_teclas(RUTA_TECLAS_CONFIG)
    piezas = tetris.cargar_piezas(RUTA_PIEZAS)
    siguiente_pieza = tetris.generar_pieza(piezas)
    juego = tetris.crear_juego(tetris.generar_pieza(piezas))
    tabla_record = tetris.mostrar_tabla_records(RUTA_PUNTUAJES)
    juego_terminado = False
    puntuaje = 0
    salir = False

    timer_bajar = ESPERA_DESCENDER
    while gamelib.loop(fps=30) and not salir:
        gamelib.draw_begin()
        # Dibujar la pantalla
        dibujar_grilla(juego)
        dibujar_pieza(juego)
        dibujar_siguiente(juego, siguiente_pieza)
        dibujar_superficie(juego)
        dibujar_puntuaje(juego, puntuaje)
        if juego_terminado:
            dibujar_game_over(tabla_record)
            anotar = tetris.es_record(puntuaje, tabla_record)
            if anotar:
                nombre = gamelib.input("Ingresar nombre: ")
                tetris.guardar_puntuaje(RUTA_PUNTUAJES, nombre, int(puntuaje))
            dibujar_game_over(tabla_record)
            break
        gamelib.draw_end()

        for event in gamelib.get_events():
            if not event:
                break
            if event.type == gamelib.EventType.KeyPress:
                tecla = event.key
                # Actualizar el juego, según la tecla presionada
                if tecla in teclas:
                    if teclas[tecla] == "IZQUIERDA":
                        juego = tetris.mover(juego, -1)
                    elif teclas[tecla] == "DERECHA":
                        juego = tetris.mover(juego, 1)
                    elif teclas[tecla] == "DESCENDER":
                        timer_bajar = 1
                    elif teclas[tecla] == "SALIR":
                        salir = True
                    elif teclas[tecla] == "ROTAR":
                        juego = tetris.rotar(juego, piezas)
                    elif teclas[tecla] == "GUARDAR":
                        tetris.guardar_partida(
                            RUTA_PARTIDA, juego, puntuaje, siguiente_pieza
                        )
                    elif teclas[tecla] == "CARGAR":
                        partida = tetris.cargar_partida(RUTA_PARTIDA)
                        juego = partida["juego"]
                        siguiente_pieza = partida["siguiente_pieza"]
                        puntuaje = partida["puntuaje"]

        if not tetris.terminado(juego) and not juego_terminado:
            timer_bajar -= 1
            if timer_bajar == 0:
                timer_bajar = ESPERA_DESCENDER
                puntuaje += 0.3
                # Descender la pieza automáticamente
                juego, prox = tetris.avanzar(juego, siguiente_pieza)
                if prox:
                    siguiente_pieza = tetris.generar_pieza(piezas)
        else:
            juego_terminado = True
Пример #9
0
def main():

    # Inicializar el estado del juego
    gamelib.resize(400, 450)
    pieza = tetris.generar_pieza()
    juego = tetris.crear_juego(pieza)
    pieza_i = tetris.generar_pieza()
    timer_bajar = ESPERA_DESCENDER
    while gamelib.loop(fps=10):

        gamelib.draw_begin()
        gamelib.draw_text("SIGUIENTE PIEZA: ", 300, 20)
        gamelib.draw_text("PUNTAJE:", 275, 300)
        #lineas verticales
        for i in range(1, 10):
            gamelib.draw_line(TAMANOCELDA * i, 0, TAMANOCELDA * i, ALTOTABLERO)
        #lineas horizontales
        for i in range(1, tetris.ALTO_JUEGO):
            gamelib.draw_line(0, TAMANOCELDA * i, ANCHOTABLERO,
                              TAMANOCELDA * i)
        # Dibujar la pantalla
        gamelib.draw_end()

        for event in gamelib.get_events():
            if not event:
                break

            if event.type == gamelib.EventType.KeyPress:
                tecla = event.key
                dicteclas = tetris.pasar_a_diccionario("teclas.txt")
                a = dicteclas.get(tecla, None)

                if a == "ROTAR":
                    juego = tetris.rotar(juego)

                if a == "DESCENDER":
                    juego, _ = tetris.avanzar(juego, pieza_i)
                    if _:
                        pieza_i = tetris.generar_pieza()
                if a == "IZQUIERDA":
                    juego = tetris.mover(juego, tetris.IZQUIERDA)

                if a == "DERECHA":
                    juego = tetris.mover(juego, tetris.DERECHA)
                if a == "GUARDAR":
                    juego = tetris.guardar_partida(juego, "partida.txt")
                if a == "CARGAR":
                    juego = tetris.cargar_partida("partida.txt")
                if a == "SALIR":
                    return

                # Actualizar el juego, según la tecla presionada

        timer_bajar -= 1
        if timer_bajar == 0:

            juego, _ = tetris.avanzar(juego, pieza_i)
            if _:
                pieza_i = tetris.generar_pieza()
            timer_bajar = ESPERA_DESCENDER

            # Descender la pieza automáticamente

        if tetris.terminado(juego):
            pieza, superficie, puntuacion = juego
            gamelib.draw_text("PERDISTE", 175, 80, size=40)
            nombre = gamelib.input("ingrese su nombre")
            listapuntuaciones = procesarpuntuaciones("puntuaciones.txt")
            listapuntuaciones.append((nombre, int(puntuacion)))
            lista = ordenarseleccionpuntuaciones(listapuntuaciones)
            lista.reverse(
            )  #la damos vuelta porque esta ordenada de menor a mayor y queremos que el archivo empieze leyendo de mayor a menor

            if len(lista) > 10:
                lista = lista[:10]

            subirpuntuaciones("puntuaciones.txt", lista)

            break

        mostrar_juego(juego)
        dibujar_siguiente(pieza_i)
Пример #10
0
def main():
    # Inicializar el estado del juego
    deshacer = Pila()
    pistas = []

    teclas = archivo_teclas(RUTA_TECLAS)
    niveles = archivo_niveles(RUTA_NIVELES)

    contador = es_nivel(gamelib.input("Eliga un nivel:"), niveles)
    juego = emparejar(niveles[contador])  #lista de cadenas

    c, f = soko.dimensiones(juego)
    gamelib.resize(c * DIM_CELDA, f * DIM_CELDA)

    juego = soko.crear_grilla(juego)  #lista de listas
    dibujar_juego(contador, juego, 1)

    while gamelib.is_alive():
        ev = gamelib.wait(gamelib.EventType.KeyPress)
        if not ev:
            break
        # Actualizar el estado del juego, según la `tecla` presionada
        tecla = ev.key

        if es_tecla(tecla, teclas) == None:
            continue

        if tecla == 'Escape':
            gamelib.say("Gracias por jugar Sokoban :)")
            break

        if tecla == 'h':
            if len(pistas) == 0:
                pistas = backtraking(contador, juego)
                if pistas == None:
                    pistas = []
            else:
                pista = pistas.pop()
                juego = soko.mover(juego, pista)
                deshacer.apilar(juego)
                dibujar_juego(contador, juego, 2)  #pista disponible

        if soko.juego_ganado(juego):
            contador += 1
            while not deshacer.esta_vacia():
                deshacer.desapilar()
            gamelib.say("Pasaste al siguiente nivel :)")

            juego = emparejar(niveles[contador])
            c, f = soko.dimensiones(juego)
            gamelib.resize(c * DIM_CELDA, f * DIM_CELDA)
            juego = soko.crear_grilla(juego)
            dibujar_juego(contador, juego, 1)

        if tecla == 'r':
            if len(pistas) != 0:
                pistas = []
            juego = emparejar(niveles[contador])
            c, f = soko.dimensiones(juego)
            gamelib.resize(c * DIM_CELDA, f * DIM_CELDA)
            juego = soko.crear_grilla(juego)
            dibujar_juego(contador, juego, 1)

        if tecla == 'Control_L':
            if not deshacer.esta_vacia():
                juego = deshacer.desapilar()
            dibujar_juego(contador, juego, 1)

        if teclas[tecla] in DIRECCIONES:
            deshacer.apilar(juego)
            juego = soko.mover(juego, DIRECCIONES[teclas[tecla]])
            dibujar_juego(contador, juego, 1)

        if tecla != 'h':  #vaciar la lista
            if len(pistas) != 0:
                pistas = []