Código
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define FILAS_CARTON 3 #define NUMEROS_FILA 5 #define MAX_BOLAS 90 void rellenar_carton(int carton [FILAS_CARTON][NUMEROS_FILA]); bool esta_repetido(int numero,int carton[FILAS_CARTON][NUMEROS_FILA]); int elegir_opcion(); void imprimir_menu(); void imprimir_carton(int carton[FILAS_CARTON][NUMEROS_FILA]); int generar_bola(int bolas_bingo[MAX_BOLAS]); bool esta_bola_reptida(int bola, int bolas_bingo[MAX_BOLAS]); void tachar_bola_carton(int carton[FILAS_CARTON][NUMEROS_FILA],int bola); bool comprobar_bingo(int carton[FILAS_CARTON][NUMEROS_FILA]); bool comprobar_linea(int carton[FILAS_CARTON][NUMEROS_FILA]); void guardar_carton(char numero_carton[1], int carton[FILAS_CARTON][NUMEROS_FILA]); void guardar_bolas(int bolas_bingo[MAX_BOLAS]); void cargar_partida(int carton_1[FILAS_CARTON][NUMEROS_FILA], int carton_2[FILAS_CARTON][NUMEROS_FILA],int bolas_bingo[MAX_BOLAS]); int main() { int carton_1[FILAS_CARTON][NUMEROS_FILA]; int carton_2[FILAS_CARTON][NUMEROS_FILA]; int bolas_bingo[MAX_BOLAS]; char* nom1,nom2; int opcion,bola; cargar_partida(carton_1,carton_2,bolas_bingo); opcion=1; while(opcion!=0) { imprimir_menu(); opcion=elegir_opcion(); switch (opcion) { case 1: rellenar_carton(carton_1); guardar_carton("1",carton_1); rellenar_carton(carton_2); guardar_carton("2",carton_2); break; case 2: bola=generar_bola(bolas_bingo); tachar_bola_carton(carton_1,bola); tachar_bola_carton(carton_2,bola); guardar_bolas(bolas_bingo); guardar_carton("1",carton_1); guardar_carton("2",carton_2); comprobar_linea(carton_1); comprobar_linea(carton_2); if(comprobar_bingo(carton_1)){ if (comprobar_bingo(carton_2)){ } } else } break; case 3: imprimir_carton(carton_1); imprimir_carton(carton_2); break; case 4: break; } } return 0; } void imprimir_menu(){ } int elegir_opcion(){ int opcion; return opcion; } void rellenar_carton(int carton [FILAS_CARTON][NUMEROS_FILA]){ int i,j,num; for(i=0;i<FILAS_CARTON;i++){ for(j=0;j<NUMEROS_FILA;j++){ if (!esta_repetido(num,carton)){ carton[i][j]=num; } else { j--; } } } } void imprimir_carton(int carton[FILAS_CARTON][NUMEROS_FILA]){ int i,j; for(i=0;i<FILAS_CARTON;i++){ for(j=0;j<NUMEROS_FILA;j++){ if (carton[i][j]==-1){ } else { } } } } bool esta_repetido(int numero,int carton[FILAS_CARTON][NUMEROS_FILA]){ int i,j; for(i=0;i<FILAS_CARTON;i++){ for(j=0;j<NUMEROS_FILA;j++){ if(carton[i][j]==numero){ return true; } } } return false; } int generar_bola(int bolas_bingo[MAX_BOLAS]){ int bola; while (esta_bola_reptida( bola, bolas_bingo)){ } bolas_bingo[bola-1]=-5; return bola; } bool esta_bola_reptida(int bola, int bolas_bingo[MAX_BOLAS]){ int i; if (bolas_bingo[bola-1]==-5){ return true; } return false; } void tachar_bola_carton(int carton[FILAS_CARTON][NUMEROS_FILA],int bola){ int i,j; for(i=0;i<FILAS_CARTON;i++){ for(j=0;j<NUMEROS_FILA;j++){ if(carton[i][j]==bola){ carton[i][j]=-1; } } } } bool comprobar_bingo(int carton[FILAS_CARTON][NUMEROS_FILA]){ int i,j; for(i=0;i<FILAS_CARTON;i++){ for(j=0;j<NUMEROS_FILA;j++){ if(carton[i][j]!=-1){ return false; } } } return true; } bool comprobar_linea(int carton[FILAS_CARTON][NUMEROS_FILA]){ bool hay_linea=true; int i,j; for(i=0;i<FILAS_CARTON;i++){ hay_linea=true; for(j=0;j<NUMEROS_FILA;j++){ if(carton[i][j]!=-1){ hay_linea=false; } } if(hay_linea==true){ return true; } } return false; } void guardar_carton(char numero_carton[1], int carton[FILAS_CARTON][NUMEROS_FILA]){ int i,j,cont; char nom_fichero[8]="carton"; FILE *fp; for(i=0;i<FILAS_CARTON;i++){ for(j=0;j<NUMEROS_FILA;j++){ } } } void guardar_bolas(int bolas_bingo[MAX_BOLAS]){ int i,j,cont; char nom_fichero[8]="bolas"; FILE *fp; for(i=0;i<MAX_BOLAS;i++){ if (bolas_bingo[i]!=-5) else } } void cargar_partida(int carton_1[FILAS_CARTON][NUMEROS_FILA], int carton_2[FILAS_CARTON][NUMEROS_FILA],int bolas_bingo[MAX_BOLAS] ){ FILE *fp; char numero[6]; int i=0,j=0; if(fp==NULL){ } else { j++; if(j==5){ j=0; i++; } } } i=0; j=0; if(fp==NULL){ } else { j++; if(j==5){ j=0; i++; } } } }
Aqui os dejo el ejercicio de bingo resuelto hecho a mi manera que seguramente haya maneras mejores. pero esta es mi manera, espero que os sea util.
MOD: Etiquetas GeSHi. Texto a minusculas.