-
-
Save parzibyte/7463449db7d686a999b2db2bc3a32242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void jugar(int modo) | |
{ | |
string[,] tablero = new string[FILAS, COLUMNAS]; | |
limpiarTablero(tablero); | |
string jugadorActual = elegirJugadorAlAzar(); | |
System.Console.WriteLine("Comienza el jugador " + jugadorActual); | |
while (true) | |
{ | |
int columna = 0; | |
System.Console.WriteLine("\nTurno del jugador " + jugadorActual); | |
dibujarTablero(tablero); | |
if (modo == MODO_HUMANO_CONTRA_CPU) | |
{ | |
if (jugadorActual == JUGADOR_CPU_2) | |
{ | |
System.Console.Write("CPU 2 pensando..."); | |
columna = elegirColumnaCpu(jugadorActual, tablero); | |
} | |
else | |
{ | |
columna = solicitarColumnaAJugador(); | |
} | |
} | |
else if (modo == MODO_CPU_CONTRA_CPU) | |
{ | |
System.Console.Write($"CPU {(jugadorActual == JUGADOR_CPU_1 ? "1" : "2")} pensando..."); | |
columna = elegirColumnaCpu(jugadorActual, tablero); | |
} | |
else if (modo == MODO_HUMANO_CONTRA_HUMANO) | |
{ | |
columna = solicitarColumnaAJugador(); | |
} | |
int estado = colocarPieza(jugadorActual, columna, tablero); | |
if (estado == ERROR_COLUMNA_LLENA) | |
{ | |
System.Console.Write("Error: columna llena"); | |
} | |
else if (estado == ERROR_FILA_INVALIDA) | |
{ | |
System.Console.Write("Fila no correcta"); | |
} | |
else if (estado == ERROR_NINGUNO) | |
{ | |
int g = ganador(jugadorActual, tablero); | |
if (g != NO_CONECTA) | |
{ | |
dibujarTablero(tablero); | |
System.Console.WriteLine("Gana el jugador " + jugadorActual); | |
break; | |
} | |
else if (esEmpate(tablero)) | |
{ | |
dibujarTablero(tablero); | |
System.Console.Write("Empate"); | |
break; | |
} | |
} | |
jugadorActual = obtenerOponente(jugadorActual); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment