Created
June 8, 2020 18:48
-
-
Save parzibyte/14e7c21edc58cc406b3b4759b19f51f5 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
void imprimirSeparadorEncabezado() { | |
int m; | |
for (m = 0; m <= COLUMNAS; m++) { | |
printf("----"); | |
if (m + 2 == COLUMNAS) { | |
printf("-"); | |
} | |
} | |
printf("\n"); | |
} | |
void imprimirSeparadorFilas() { | |
int m; | |
for (m = 0; m <= COLUMNAS; m++) { | |
printf("+---"); | |
if (m == COLUMNAS) { | |
printf("+"); | |
} | |
} | |
printf("\n"); | |
} | |
void imprimirEncabezado() { | |
imprimirSeparadorEncabezado(); | |
printf("| "); | |
int l; | |
for (l = 0; l < COLUMNAS; l++) { | |
printf("| %d ", l + 1); | |
if (l + 1 == COLUMNAS) { | |
printf("|"); | |
} | |
} | |
printf("\n"); | |
} | |
// Convierte un int a un char. Por ejemplo 0 a '0' | |
char enteroACaracter(int numero) { | |
return numero + '0'; | |
} | |
void imprimirTablero(char tablero[FILAS][COLUMNAS], int deberiaMostrarMinas) { | |
imprimirEncabezado(); | |
imprimirSeparadorEncabezado(); | |
char letra = 'A'; | |
int l; | |
for (l = 0; l < FILAS; l++) { | |
int m; | |
// Imprimir la letra de la fila | |
printf("| %c ", letra); | |
letra++; | |
for (m = 0; m < COLUMNAS; m++) { | |
// No le vamos a mostrar al usuario si hay una mina... | |
char verdaderaLetra = ESPACIO_SIN_DESCUBRIR; | |
char letraActual = tablero[l][m]; | |
if (letraActual == MINA) { | |
verdaderaLetra = ESPACIO_SIN_DESCUBRIR; | |
} else if (letraActual == ESPACIO_DESCUBIERTO) { | |
// Si ya lo abrió, entonces mostramos las minas cercanas | |
int minasCercanas = obtenerMinasCercanas(l, m, tablero); | |
verdaderaLetra = enteroACaracter(minasCercanas); | |
} | |
// Si DEBUG está en 1, o debería mostrar las minas (porque perdió o ganó) | |
// mostramos la mina original | |
if (letraActual == MINA && (DEBUG || deberiaMostrarMinas)) { | |
verdaderaLetra = MINA; | |
} | |
printf("| %c ", verdaderaLetra); | |
if (m + 1 == COLUMNAS) { | |
printf("|"); | |
} | |
} | |
printf("\n"); | |
imprimirSeparadorFilas(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment