def test_exceptionsintentar_letra_(self, dificultad, letras, result): servicePartida = ServicesPartidas() partida = servicePartida.iniciar_partida('claudio', dificultad, 'python', 'lenguaje de programacion') with self.assertRaises(ValueError): for letra in letras: servicePartida.intentar_letra(partida, letra)
def dos_jugadores(self): dicJugadores = {} servis = ServicesPartidas() for j in range(0, 2): nombreJugador = str(input("Ingrese su nombre: ")) intentosJugador = int(input("Ingrese la dificultad: ")) palabra = str( input("Ingrese una palabra para %s: " % nombreJugador)) tipoPalabra = str(input("Ingrese el tipo de palabra: ")) p = servis.iniciar_partida(nombreJugador, intentosJugador, palabra, tipoPalabra) for i in range(0, p.intentos): letra = str(input("\nIngrese una letra para adivinar: ")) if letra == 'salir': return True respuesta = servis.intentar_letra(p, letra.upper()) print(respuesta) if respuesta == 'Gano' or respuesta == 'Perdio': if j == 0: dicJugadores[nombreJugador] = p.__dict__ break else: dicJugadores[nombreJugador] = p.__dict__ with open('jugadores.json', 'w') as f: json.dump(dicJugadores, f, indent=2) return True
def dos_jugadores(self): services = ServicesPartidas() for i in range(0, 2): _nombre = input( '\n----> \tIngrese el nombre del jugador {}: '.format(i + 1)) _dificultad = int( input('\n----> \tIngrese la dificultad para {} ' '(1-10): '.format(_nombre.upper()))) _palabra = input('\n----> \t¿Qué palabra deberá adivinar ' '{}?: '.format(_nombre.upper())) _tipo_palabra = input('\n----> \t¿Qué tipo de palabra es?: ') p2 = services.iniciar_partida(_nombre, _dificultad, _palabra, _tipo_palabra) res = 'Continua' while res == 'Continua': letra = input('\n----> \tIngrese una letra: ') if letra == 'salir': return True res = services.intentar_letra(p2, letra.upper()) print('\t', p2._palabra_aciertos) if res == 'Gano': print('\n----> \tFelicitaciones {}, adivinaste!\n'.format( _nombre.upper())) elif res == 'Perdio': print( '\n----> \tPerdiste {}, mejor suerte la próxima.\n'.format( _nombre.upper())) print(RepoPartidas.partidas_list, "\n") return True
def un_jugador(self): servicePartida = ServicesPartidas() pal = random.choice(Repositorios.palabrasList) nombre = input('Ingrese un nombre: ') dificultad = int( input("Ingrese una dificultad del 1 al 10" "(1 --> dificil, 10 --> facil): ")) partida = Partida(pal['palabra'], dificultad * len(pal['palabra']), pal['tipo_palabra'], nombre) while partida._intentos > 0: print('Palabra a adivinar: ', partida._palabra_aciertos) print('Pista: ', partida._tipo_palabra) print('Cantidad de intentos: ', partida._intentos) letra = input("Ingrese una letra: ").upper() if letra == 'SALIR': return True result = servicePartida.intentar_letra(partida, letra) if result == 'Gano': print(result, '! Felicitaciones, la palabra era: ', partida._palabra) partida._intentos = 0 return True else: # os.system('clear') print(result) if result == 'Perdio': print(result, '! Lo lamento, la palabra era: ', partida._palabra) return True
def test_intentar_letra(self, dificultad, letras, result): servicePartida = ServicesPartidas() partida = servicePartida.iniciar_partida('claudio', dificultad, 'python', 'lenguaje de programacion') for letra in letras: result_aux = servicePartida.intentar_letra(partida, letra) self.assertEqual(result_aux, result)
def un_jugador(self): servis = ServicesPartidas() nombreJugador = str(input("Ingrese su nombre: ")) intentosJugador = int(input("Ingrese la dificultad: ")) p = servis.iniciar_partida(nombreJugador, intentosJugador, '', '') for i in range(0, p.intentos): letra = input("\nIngrese una letra para adivinar: ") if letra == 'salir': return True respuesta = servis.intentar_letra(p, letra.upper()) print(respuesta) if respuesta == 'Gano' or respuesta == 'Perdio': return True
def pedir_letras(self, partida): servicios = ServicesPartidas() seguir = True while seguir is True: try: let = str(input("Letra: ")) except StopIteration: return if let == "salir": break result = servicios.intentar_letra(partida, let) print("\n", partida._palabra_aciertos) if result == "Gano": print("\nGANASTE! La palabra era: ", partida.palabra) return "Gano" seguir = False if result == "Perdio": print("\nPERDISTE! La palabra era: ", partida.palabra) return "Perdio" seguir = False
def un_jugador(self): services = ServicesPartidas() _nombre = input('\n----> \tIngrese su nombre: ') _dificultad = int(input('\n----> \tIngrese la dificultad (1-10): ')) p1 = services.iniciar_partida(_nombre, _dificultad) res = 'Continua' while res == 'Continua': letra = input('\n----> \tIngrese una letra: ') if letra == 'salir': return True res = services.intentar_letra(p1, letra.upper()) print('\t', p1._palabra_aciertos) if res == 'Gano': print('\n----> \tFelicitaciones {}, adivinaste!\n'.format( _nombre.upper())) return True elif res == 'Perdio': print('\n----> \tPerdiste {}, mejor suerte la próxima.\n'.format( _nombre.upper())) return False
def un_jugador(self): gano = 'Gano' salida = 'salir' try: estado = True servPart = ServicesPartidas() nombre_jugador = input('Ingresa Tu Nombre: ') while True: try: dificultad = int(input('Elije dificultad 1 a 10 ')) partida0 = servPart.iniciar_partida( nombre_jugador, dificultad, '', '') break except Exception: print('Error, dificultad no valida') print('Okey empecemos, tu palabra a adivinar es de tipo', partida0.tipo_palabra) print('Primer y ultima letra', partida0.palabra[0], '-', partida0.palabra[-1]) for _ in range(0, partida0.intentos): letra = input('Ingrese letra: ') resultado = servPart.intentar_letra(partida0, letra) print(partida0.palabra_aciertos) print('Te quedan', partida0.intentos, 'intentos') print(partida0.nombre_jugador, resultado) if letra == salida: break if resultado == gano: break while estado: condicion = input('Quieres volver a jugar?(s/n): ') if condicion == 's': self.un_jugador() if condicion == 'n': estado = False else: print('Error, entrada erronea :/') except Exception: StopIteration return True
def dos_jugadores(self): gano = 'Gano' salida = 'salir' try: estado1 = True estado2 = True estado3 = True while estado1: servPart = ServicesPartidas() while True: try: jugadador1 = input('Turno del Jugador 1,tu nombre?: ') dificultad1 = int( input('Que dificultad' ' eliges? (1-10): ')) palabra1 = input('Ingresa la palabra a adivinar: ') tipoPalabra1 = input('Ingresa el tipo de palabra: ') partida1 = servPart.iniciar_partida( jugadador1, dificultad1, palabra1, tipoPalabra1) break except Exception: print('Dificultad erronea :/') print('Llego la hora de adivinar!') for _ in range(0, partida1.intentos): letra1 = input('Ingrese letra: ') resultado = servPart.intentar_letra(partida1, letra1) print(partida1.palabra_aciertos) print('Te quedan', partida1.intentos, 'intentos') print(partida1.nombre_jugador, resultado) Repositorios.partida1 = partida1.__dict__ if resultado == gano: break if letra1 == salida: break print('Resultado Jugador 1', Repositorios.partida1) estado1 = False while estado2: while True: try: jugadador2 = input('Turno del jugador 2, tu nombre?: ') dificultad = int( input('Que dificultad' ' eliges? (1-10): ')) palabra = input('Ingresa la palabra a adivinar: ') tipoPalabra = input('Ingresa el tipo de palabra: ') partida2 = servPart.iniciar_partida( jugadador2, dificultad, palabra, tipoPalabra) break except Exception: print('Dificultad erronea :/') print('Llego la hora de adivinar!') for _ in range(0, partida2.intentos): letra2 = input('Ingrese letra: ') resultado2 = servPart.intentar_letra(partida2, letra2) print(partida2.palabra_aciertos) print('Te quedan', partida2.intentos, 'intentos') print(partida2.nombre_jugador, resultado2) Repositorios.partida2 = partida2.__dict__ if resultado2 == gano: break if letra2 == salida: break estado2 = False print('Resultado Jugador 2', Repositorios.partida2) while estado3: condicion = input('Quieres volver a jugar?(s/n): ') if condicion == 's': self.dos_jugadores() elif condicion == 'n': estado3 = False else: print('Error, entrada incorrecta :/') except Exception: StopIteration return True
def dos_jugadores(self): servicePartida = ServicesPartidas() print('------------------') print('Juega el jugador 1') print('------------------') nombre1 = input('Jugador 1: Ingrese un nombre: ') dificultad1 = int( input('Jugador 1: Ingrese una dificultad del 1 al 10' ' (1 --> dificil, 10 --> facil): ')) palabra_adivinar1 = input( 'Jugador 2: Ingrese una palabra' ' (esta se utilizara para que juegue el jugador 1): ') tipo_palabra_adivinar1 = input( 'Jugador 2: Ingrese la pista o tipo de palabra: ') partida1 = Partida(palabra_adivinar1, dificultad1 * len(palabra_adivinar1), tipo_palabra_adivinar1, nombre1) os.system('clear') while partida1._intentos > 0: print('Palabra a adivinar: ', partida1._palabra_aciertos) print('Pista: ', partida1._tipo_palabra) print('Cantidad de intentos: ', partida1._intentos) print(nombre1.upper(), end=': ') letra = input("Ingrese una letra: ").upper() if letra == 'SALIR': return True result = servicePartida.intentar_letra(partida1, letra) if result == 'Gano': print(result, '! Felicitaciones, la palabra era: ', partida1._palabra) servicePartida.add_partida(partida1) partida1._intentos = 0 break else: print(result) if result == 'Perdio': print(result, '! Lo lamento, la palabra era: ', partida1._palabra) servicePartida.add_partida(partida1) break print('------------------') print('Juega el jugador 2') print('------------------') nombre2 = input('Jugador 2: Ingrese un nombre: ') dificultad2 = int( input('Jugador 2: Ingrese una dificultad del 1 al 10' ' (1 --> dificil, 10 --> facil): ')) palabra_adivinar2 = input( 'Jugador 1: Ingrese una palabra' ' (esta se utilizara para que juegue el jugador 2): ') tipo_palabra_adivinar2 = input( 'Jugador 1: Ingrese la pista o tipo de palabra: ') partida2 = Partida(palabra_adivinar2, dificultad2 * len(palabra_adivinar2), tipo_palabra_adivinar2, nombre2) os.system('clear') while partida2._intentos > 0: print('Palabra a adivinar: ', partida2._palabra_aciertos) print('Pista: ', partida2._tipo_palabra) print('Cantidad de intentos: ', partida2._intentos) print(nombre2.upper(), end=': ') letra = input("Ingrese una letra: ").upper() if letra == 'SALIR': return True result = servicePartida.intentar_letra(partida2, letra) if result == 'Gano': print(result, '! Felicitaciones, la palabra era: ', partida2._palabra) servicePartida.add_partida(partida2) partida2._intentos = 0 return True else: print(result) if result == 'Perdio': print(result, '! Lo lamento, la palabra era: ', partida2._palabra) servicePartida.add_partida(partida2) return True