Hola, la duda que tengo es cómo generar los dos modos de juego; automático y manual. En el automático se lanzarían todos las bolas finalizaría cuando un cartón de los pedidos cantase bingo. El manual se ejecutaría bola a bola, pidiendo una intervención del usuario. Al finalizar se deben mostrar los cartones con linea cantada, bingo y los números que hayan salido a lo largo del juego.
#include <stdio.h>
#include <stdlib.h>
void generar(int matriz[][9]);
void imprimir(int matriz[][9]);
void huecos(int matriz[][9], int fila);
typedef struct{
int numeros[3][9];
}Carton;
typedef struct{
Carton * juego;
int numeroCartones;
}Bingo;
typedef struct{
int bola;
}Numeros;
void inicializarBingo(Bingo * miJuego)
{
int i,j,k;
int filas;
int columnas;
int fila;
int matriz[3][9];
printf("\nCuantos cartones desea generar: "); scanf ("%d", &(miJuego
->numeroCartones
)); miJuego
->juego
=(Carton
*)malloc(sizeof(Carton
)*miJuego
->numeroCartones
);
for(i=0;i<miJuego->numeroCartones;i++)
{
for(columnas=0;columnas<9;columnas++)
{
do{
for(filas=0;filas<3;filas++)
{
switch (columnas)
{
case 0:
matriz
[filas
][columnas
] = 1 + rand() % (10 + 1 - 1); break;
case 1:
matriz
[filas
][columnas
] = 11 + rand() % (20 + 1 - 11); break;
case 2:
matriz
[filas
][columnas
] = 21 + rand() % (30 + 1 - 21); break;
case 3:
matriz
[filas
][columnas
] = 31 + rand() % (40 + 1 - 31); break;
case 4:
matriz
[filas
][columnas
] = 41 + rand() % (50 + 1 - 41); break;
case 5:
matriz
[filas
][columnas
] = 51 + rand() % (60 + 1 - 51); break;
case 6:
matriz
[filas
][columnas
] = 61 + rand() % (70 + 1 - 61); break;
case 7:
matriz
[filas
][columnas
] = 71 + rand() % (80 + 1 - 71); break;
case 8:
matriz
[filas
][columnas
] = 81 + rand() % (90 + 1 - 81); break;
}
}
}while((matriz[0][columnas]== matriz[1][columnas]) ||
(matriz[0][columnas]==matriz[2][columnas]) ||
(matriz[1][columnas]== matriz[2][columnas])||
(matriz[0][columnas]>matriz[1][columnas])||
(matriz[1][columnas]>matriz[2][columnas]));
}
huecos(matriz, 0);
huecos(matriz, 1);
huecos(matriz, 2);
for(k=0;k<3;k++)
{
for(j=0;j<9;j++)
{
((miJuego->juego)[i]).numeros[k][j] = matriz[k][j];
}
}
}
}
void mostrar(Bingo miJuego)
{
int matriz[3][9];
int i = 0, j = 0, k = 0;
printf("\nTus cartones son los siguientes: "); for(i=0;i<miJuego.numeroCartones;i++)
{
printf("\n\nCarton numero %d:",i
+1); printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n" ,201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,
205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,
205,205,205,205,205,205,205,205,205,205,205,
205,205,205,205,205,205,205,205,205,187);
int filas;
for(filas=0;filas<3;filas++)
{
int columnas;
for(columnas=0;columnas<9;columnas++)
{
if (((miJuego.juego)[i]).numeros[filas][columnas]==-1)
printf("%c_%c%c_%c",186,176,176,186);
else if (columnas == 0 && matriz[filas][0]!=10)
printf("%c__%i_%c", 186,((miJuego.
juego)[i
]).
numeros[filas
][columnas
],186);
else
printf("%c_%i_%c", 186,((miJuego.
juego)[i
]).
numeros[filas
][columnas
],186); }
}
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n" ,200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,
205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,
205,205,205,205,205,205,205,205,205,205,205,
205,205,205,205,205,205,205,205,205,188);
}
}
void automatico(Bingo * miJuego)
{
}
void manual(Bingo * miJuego)
{
}
int main()
{
printf("\nBienvenidos a este maravilloso Bingo\n"); Bingo miBingo;
inicializarBingo(&miBingo);
mostrar(miBingo);
Bingo modoAutomatico;
Bingo modoManual;
int opcion;
printf( "\n Si desea jugar en modo automatico pulse 1: \n"); printf( "\n Si desea jugar en modo Paso a Paso pulse 2: \n"); switch ( opcion )
{
case 1: printf("\n Juego completo: \n"); //system("cls");
automatico(&modoAutomatico);
break;
case 2:printf("\n Juego paso a paso: \n"); manual(&modoManual);
//system("cls");
break;
}
return 0;
}
void huecos(int matriz[][9], int fila) //funcion que genera los cuatro huecos por fila necesarios en el carton
{
int posicion=0,huecos=0;
while(huecos<4)
{
posicion
=rand() % (8 + 1 - 0) + 0; if (matriz[fila][posicion]!=-1)
{
matriz[fila][posicion]=-1;
huecos++;
}
}
}