agrego ultimas modificaciones del equipo
This commit is contained in:
parent
6c16092804
commit
fb56a3a4c3
6 changed files with 175 additions and 1 deletions
BIN
Sara/__pycache__/funciones.cpython-314.pyc
Normal file
BIN
Sara/__pycache__/funciones.cpython-314.pyc
Normal file
Binary file not shown.
BIN
Sara/__pycache__/motor.cpython-314.pyc
Normal file
BIN
Sara/__pycache__/motor.cpython-314.pyc
Normal file
Binary file not shown.
75
Sara/funciones.py
Normal file
75
Sara/funciones.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
# Archivo Funciones.py
|
||||
|
||||
import random
|
||||
|
||||
|
||||
def tatetivsPC(tablero):
|
||||
|
||||
casillas = []
|
||||
|
||||
for casilla in range(9):
|
||||
if not (tablero[casilla] == "X" or tablero[casilla] == "O"):
|
||||
casillas.append(tablero[casilla])
|
||||
|
||||
print(casillas)
|
||||
return random.choice(casillas)
|
||||
|
||||
|
||||
def comprueba_ganador(tablero):
|
||||
""" Comprueba si hay un ganador """
|
||||
return (tablero[0] == tablero[1] == tablero[2] or
|
||||
tablero[3] == tablero[4] == tablero[5] or
|
||||
tablero[6] == tablero[7] == tablero[8] or
|
||||
tablero[0] == tablero[3] == tablero[6] or
|
||||
tablero[1] == tablero[4] == tablero[7] or
|
||||
tablero[2] == tablero[5] == tablero[8] or
|
||||
tablero[0] == tablero[4] == tablero[8] or
|
||||
tablero[2] == tablero[4] == tablero[6])
|
||||
|
||||
def imprime_tablero(tablero):
|
||||
|
||||
tablero_colores = []
|
||||
|
||||
for casilla in tablero:
|
||||
if casilla == "X":
|
||||
tablero_colores.append("\033[91mX\033[0m")
|
||||
elif casilla == "O":
|
||||
tablero_colores.append("\033[94mO\033[0m")
|
||||
else:
|
||||
tablero_colores.append(casilla)
|
||||
|
||||
|
||||
print(f"\n {tablero_colores[0]} | {tablero_colores[1]} | {tablero_colores[2]} \n---+---+---\n {tablero_colores[3]} | {tablero_colores[4]} | {tablero_colores[5]} \n---+---+---\n {tablero_colores[6]} | {tablero_colores[7]} | {tablero_colores[8]} ")
|
||||
|
||||
def datos_jugadores(modalidad):
|
||||
"""Esta función permite cargar los datos de los jugadores"""
|
||||
|
||||
#Grabo los datos de los jugadores en un archivo TXT
|
||||
archivo = open('./juego_tateti/jugadores.txt', 'w')
|
||||
|
||||
#El jugadorX puede jugar solo o contra otro humano por eso se define afuera
|
||||
nombre_jugadorX = input('\nIngrese el nombre del jugador X: ')
|
||||
archivo.write('JugadorX = ' + nombre_jugadorX + '\n')
|
||||
|
||||
if modalidad == str(1):
|
||||
nombre_jugadorO = input('\nIngrese el nombre del jugador O: ')
|
||||
print("\n¡Buenisimo! " + nombre_jugadorX + " vs " + nombre_jugadorO + "\nArranca el juego.")
|
||||
archivo.write('JugadorO = ' + nombre_jugadorO + '\n')
|
||||
else:
|
||||
nombre_jugadorO = "a la PC"
|
||||
print("\n¡Buenisimo! " + nombre_jugadorX + " vs PC " + "\nArranca el juego.")
|
||||
archivo.close()
|
||||
return nombre_jugadorX, nombre_jugadorO
|
||||
|
||||
def pedir_numero():
|
||||
while True:
|
||||
pos = input("Elegir un número del 1 al 9: ")
|
||||
if pos in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
|
||||
return int(pos)
|
||||
print("Opción no válida. Ingresá un número del 1 al 9.")
|
||||
|
||||
def informa_ganador(jugadorX, nombre_jugadorO, nombre_jugadorX):
|
||||
if jugadorX:
|
||||
print("¡Ganó \033[94mO\033[0m! Felicitaciones " + nombre_jugadorO)
|
||||
else:
|
||||
print("¡Ganó \033[91mX\033[0m! Felicitaciones " + nombre_jugadorX)
|
||||
63
Sara/motor.py
Normal file
63
Sara/motor.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# archivo motor.py
|
||||
|
||||
from funciones import comprueba_ganador, datos_jugadores, imprime_tablero, tatetivsPC, pedir_numero, informa_ganador
|
||||
|
||||
# Creo una función que inicializa el tablero del juego con las casillas numeradas.
|
||||
|
||||
def crear_tablero():
|
||||
return ["1", "2", "3",
|
||||
"4", "5", "6",
|
||||
"7", "8", "9"]
|
||||
|
||||
# Defino una función para crear y devolver el tablero inicial con las posiciones disponibles,
|
||||
# permitiendo luego almacenar las X y O según los movimientos de los jugadores.
|
||||
|
||||
tablero = crear_tablero()
|
||||
|
||||
def jugar_tateti(opcion):
|
||||
nombre_jugadorX, nombre_jugadorO = datos_jugadores(opcion)
|
||||
imprime_tablero(tablero)
|
||||
jugadas = 0
|
||||
jugadorX = True
|
||||
jugadorO = False
|
||||
|
||||
while jugadas < 9:
|
||||
if jugadorX:
|
||||
print("\nTurno del jugador X")
|
||||
numeroElegido = pedir_numero()
|
||||
else:
|
||||
if opcion == str(1):
|
||||
print("\nTurno del jugador O")
|
||||
numeroElegido = pedir_numero()
|
||||
else:
|
||||
print("\nTurno PC")
|
||||
numeroElegido = int(tatetivsPC(tablero))
|
||||
|
||||
if 1 <= numeroElegido <= 9:
|
||||
|
||||
if tablero[numeroElegido - 1] not in ['X', 'O']:
|
||||
|
||||
if jugadorX:
|
||||
tablero[numeroElegido - 1] = 'X'
|
||||
jugadorX = False
|
||||
jugadorO = True
|
||||
else:
|
||||
tablero[numeroElegido - 1] = 'O'
|
||||
jugadorX = True
|
||||
jugadorO = False
|
||||
|
||||
jugadas += 1
|
||||
|
||||
imprime_tablero(tablero)
|
||||
|
||||
else:
|
||||
print("Ubicación no disponible.")
|
||||
|
||||
else:
|
||||
print("Ingrese un número válido del 1 al 9.")
|
||||
|
||||
if comprueba_ganador(tablero):
|
||||
informa_ganador(jugadorX, nombre_jugadorO, nombre_jugadorX)
|
||||
break
|
||||
elif jugadas==9:
|
||||
print("La partida terminó empatada")
|
||||
36
Sara/tateti.py
Normal file
36
Sara/tateti.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
'''
|
||||
Juego TA-TE-TI
|
||||
Profesora = ANA LAURA ALMADA
|
||||
Alumnos de UNL Virtual - Grupo Venus
|
||||
Federico Alejandro Mazzei:
|
||||
Estructura inicial del programa (tablero inicial del juego, ingreso de posiciones validas y contador de jugadas)
|
||||
datos_jugadores() Solicito nombre de los jugadores y lo guardo en un archivo .TXT (jugadores.txt)
|
||||
Agrego la función jugar_tateti(opcion) que según la opcion elegida juega vs humano o PC.
|
||||
Fernando Zaldívar Posse:
|
||||
Validación de ganador de la partida. Empate si se completan las 9 posiciones sin un ganador.
|
||||
Matías Mauricio Machado Pérez:
|
||||
Menú principal con opciones antes de que muestre el tablero de juego.
|
||||
Sara Somaré:
|
||||
Incorporación del segundo jugador y turnos de juego integrándolo al código de Ingrid.
|
||||
Ingrid Celia Spessotti:
|
||||
Representación del tablero con una lista, actualización del tablero y control de casillas ocupadas
|
||||
'''
|
||||
|
||||
# Archivo TaTeTi.py
|
||||
|
||||
from motor import jugar_tateti
|
||||
|
||||
print("=== BIENVENIDO AL TA-TE-TI ===")
|
||||
print("1. Humano vs Humano (2 jugadores)")
|
||||
print("2. Humano vs PC")
|
||||
|
||||
opcion = ""
|
||||
opcion = input("Elegí una opción (1 para jugar): ")
|
||||
|
||||
if opcion == "1":
|
||||
jugar_tateti(opcion)
|
||||
|
||||
elif opcion == "2":
|
||||
jugar_tateti(opcion)
|
||||
else:
|
||||
print("Opción no válida. Poné 1 o 2.")
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
JugadorX = Fede
|
||||
JugadorO = Lore
|
||||
JugadorO = Sara
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue