#include <stdlib.h>
#include <stdio.h>
#define DIM 16 /*Constante utilizada para definir la maxima dimension del tablero*/
//#define tam_string 40 /*Constante para la cantidad de digitos de los Nombres*/
//#define ced_string 8
struct partidas1{
char nom_jug[40];
char ced_jug[8];
}partidas1[500];
struct partidas2{
char nom_jug[40];
char ced_jug[8];
}partidas2[500];
int partida, aux2;
struct partidas
{
char nom_jug[40];
char ced_jug[8];
};
struct partidas partidas[10];
char nom_jug[40];
char ced_jug[8];
/*PROCEDIMIENTOS Y FUNCIONES*/
void inicializar_tablero(char tablero[][DIM],int);
int juegan_O_(char tabla[][DIM],int,int);
int juegan_X_(char tablero[][DIM],int,int);
int cuatro_en_linea(char tablero[][DIM],int);
int limpiar(char nom_jug[]);
int inicia1 = 0;
int inicia2 = 0, jugar=1;
int main()
{
char tablero[DIM][DIM];
int x,opcion,victoria=1,nombre1,nombre2,contador=1,correcta=1,aux=1,sumador = 0;
do
{
system("cls");
printf("\n\n\n JUEGO CUATRO EN LINEA\n\n\n\n\n");
printf(" 1) Ingresar datos del primer jugador\n\n");
printf(" 2) Ingresar datos del segundo jugador\n\n");
printf(" 3) Jugar\n\n");
printf(" 4) Listar todos los juegos realizados\n\n");
printf(" 5) Salir\n\n\n");
if (contador%2==0)
{
printf(" Error: Antes de jugar debe ingresar los datos de los dos jugadores. \n\n\n");
printf(" REINGRESE SU OPCION: ");
contador--;
}
if (correcta%2==0)
{
printf(" Opcion incorrecta \n\n\n");
printf(" REINGRESE SU OPCION: ");
correcta--;
}
if (aux%2==0)
{
printf(" No se han realizado juegos. \n\n\n");
aux--;
}
scanf("%d",&opcion);
system("cls");
switch (opcion)
{
case 1: /*OPCION 1 DEL MENU.*/
{
limpiar(nom_jug);
limpiar(ced_jug);
while(getchar() != '\n');
printf("\n Ingrese su Nombre: ");
do
{
scanf("%39[^\n]",partidas1[inicia1].nom_jug);
if (partidas1[inicia1].nom_jug[0]=='\0')
{
printf(" ERROR\n");
printf(" Ingrese nuevamente Nombre: ");
}
else
{
for (nombre1=0;nombre1<40;nombre1++)
{
nom_jug[nombre1];
}
}while(getchar() != '\n');
system("cls");
}while(partidas1[inicia1].nom_jug[0]=='\0');
printf("\n Ingrese su cedula: ");
do
{
scanf("%8[^\n]",partidas1[inicia1].ced_jug);
if (partidas1[inicia1].ced_jug[0]=='\0')
{
printf(" ERROR\n");
printf(" Ingrese nuevamente su cedula: ");
}
else
{
for (nombre1=0;nombre1<8;nombre1++)
{
ced_jug[nombre1];
}
system("cls");
printf("\n");
}while(getchar() != '\n');
}while(partidas1[inicia1].ced_jug[0]=='\0');
printf("\n DATOS INGRESADOS\n");
printf("\n\n Nombre ingresado: %s",partidas1[inicia1].nom_jug);
printf("\n\n Cedula ingresada: %s",partidas1[inicia1].ced_jug);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n presione ENTER para volver al menu");
partidas1[inicia1+1]=partidas1[inicia1];
jugar++;
break;
}
case 2: /*OPCION 2 DEL MENU*/
{
limpiar(nom_jug);
limpiar(ced_jug);
while(getchar() != '\n');
printf("\n Ingrese su Nombre: ");
do
{
scanf("%39[^\n]",partidas2[inicia2].nom_jug);
if (partidas2[inicia2].nom_jug[0]=='\0')
{
printf(" ERROR\n");
printf(" Ingrese nuevamente Nombre: ");
}
else
{
for (nombre2=0;nombre2<40;nombre2++)
{
nom_jug[nombre2];
}
}while(getchar() != '\n');
system("cls");
}while(partidas2[inicia2].nom_jug[0]=='\0');
printf("\n Ingrese su cedula: ");
do
{
scanf("%8[^\n]",partidas2[inicia2].ced_jug);
do
if (partidas2[inicia2].ced_jug[0]=='\0')
{
printf(" ERROR\n");
printf(" Ingrese nuevamente su cedula: ");
}
else
{
for (nombre2=0;nombre2<8;nombre2++)
{
ced_jug[nombre2];
}
system("cls");
printf("\n");
}while(getchar() != '\n');
}while(partidas2[inicia2].ced_jug[0]=='\0');
printf("\n DATOS INGRESADOS\n");
printf("\n\n Nombre ingresado: %s",partidas2[inicia2].nom_jug);
printf("\n\n Cedula ingresada: %s",partidas2[inicia2].ced_jug);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n presione ENTER para volver al menu");
partidas2[inicia2+1]=partidas2[inicia2];
jugar++;
break;
}
case 3: /*OPCION 3 DEL MENU*/
{
if (jugar<3)
{
contador++;
}
else
{
cuatro_en_linea(tablero,opcion);
sumador++;
}
break;
}
case 4: /*OPCION 4 DEL MENU*/
{
if (sumador<1)
{
aux++;
}
else
{
partida=1;
aux2=0;
for(partida;partida<sumador+1;partida++){
printf("Partida %d\n",partida);
printf("\n");
printf("Jugador 1: %s\n",partidas1[aux2].nom_jug);
printf("Cedula: %s\n",partidas1[aux2].ced_jug);
printf("Jugador 2: %s\n",partidas2[aux2].nom_jug);
printf("Cedula: %s\n",partidas2[aux2].ced_jug);
aux2++;
printf("\n");
}
}
system("PAUSE");
break;
}
case 5: /*OPCION 5 DEL MENU*/
{
return printf("\n\n SALIENDO\n\n");
break;
default:
correcta++;
break;
}
}while (getchar()!='\n');
}while (victoria==1);
}