/
Inicio :: Foros

 F.A.Q.F.A.Q.                  Conéctese para revisar sus mensajesConéctese para revisar sus mensajes   

Ayuda con conecta 4 en C con allegro.h

 
      Índice del Foro elrincondelc.com -> Gráficos
Ver tema anterior :: Ver siguiente tema  
AutorMensaje
Rejit



Registrado: 17 Jul 2011
Mensajes: 1

MensajePublicado: 17/07/2011 11:25 am
Título: Ayuda con conecta 4 en C con allegro.h

Vereis, he intentado pasar de interfaz de comandos a allegro.h la matriz, pero no se como. Agradeceria algo de ayuda. Aqui os dejo el programa:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define FILAS 8
#define COLUMNAS 10
char tablero[FILAS][COLUMNAS];

void inicializar_tablero() {
int i,j;
for(i=0;i<FILAS;i++)
for(j=0;j<COLUMNAS;j++)
tablero[i][j]=' ';
}
int jugada_correcta(int fila, int col) {

int jugada_correcta; /

jugada_correcta=1;

if (fila>=FILAS || fila<0 || col>=COLUMNAS || col<0) jugada_correcta=0;
if (jugada_correcta==1) {

if (tablero[fila][col]=='0' || tablero[fila][col]=='X') jugada_correcta=0;
}
if (jugada_correcta==1) {

if (fila!=FILAS-1 && tablero[fila+1][col]==' ') jugada_correcta=0;

}
return jugada_correcta;

}

int generar_numero() {

int num;
srand(time(NULL));
num=rand() % COLUMNAS;

return num;
}
int hacer_jugada(int jug) {

int fila,col;
int i; //Para el contador.
char ficha;
int resultado_jugada;
resultado_jugada=1;
if (jug==0) {
ficha='0';
printf("El usuario coloca ficha.\n");
do {
if (resultado_jugada==0) printf("Jugada incorrecta.\n");
printf("Introduce la columna en la que quieres colocar tu ficha: ");
scanf("%d",&col);
i=FILAS-1;

if (tablero[FILAS-1][col]!=' ') {
while(i<FILAS && (tablero[i][col]=='X' || tablero[i][col]=='0'))
i--;
}

fila=i;

resultado_jugada=jugada_correcta(fila,col);

} while(resultado_jugada==0);

} else {

ficha='X';
do {
col=generar_numero();
i=FILAS-1;

if (tablero[FILAS-1][col]!=' ') {
while(i<FILAS && (tablero[i][col]=='X' || tablero[i][col]=='0'))
i--;
}
fila=i;
resultado_jugada=jugada_correcta(fila,col);
} while(resultado_jugada==0);

}



if (resultado_jugada==1) tablero[fila][col]=ficha;

return resultado_jugada;

}

int mostrar_tablero() {

int i,j;

int ficha;


system("clear");

printf("\n");

for(j=0;j<COLUMNAS*5/2;j++) printf(" ");

printf("CONECTA 4");

printf("\n F -");

for(j=0;j<COLUMNAS+1;j++) printf("----");

printf("\n");

for(i=0;i<FILAS;i++) {

printf(" ");

if (i==0)

printf("I");

else if (i==1)

printf("A");

else

printf(" ");

printf(" %d |",i);

for(j=0;j<COLUMNAS;j++) {

printf(" ");

printf("%c",tablero[i][j]);

printf(" |");

}

printf(" ");

if (i==0) printf("\n L");

else if (i==1) printf("\n S");

else printf("\n ");

printf(" -");

for(j=0;j<COLUMNAS+1;j++) printf("----");

printf("\n");
}

printf(" ");

for(j=0;j<COLUMNAS;j++) printf("%d ",j);

printf(" COLUMNAS\n");

printf("\n");

}

int comprobar_fin() {

int i,j;

int ganador;
ganador=-1;

for(i=0;i<FILAS;i++) {

for(j=0;j<COLUMNAS-3;j++) {

if (tablero[i][j]=='X' && tablero[i][j+1]=='X' && tablero[i][j+2]=='X' && tablero[i][j+3]=='X')

ganador=0;

else if (tablero[i][j]=='0' && tablero[i][j+1]=='0' && tablero[i][j+2]=='0' && tablero[i][j+3]=='0')

ganador=1;

}

}

if (ganador==-1) {
for(i=0;i<FILAS-3;i++) {

for(j=0;j<COLUMNAS;j++) {

if (tablero[i][j]=='X' && tablero[i+1][j]=='X' && tablero[i+2][j]=='X' && tablero[i+3][j]=='X')

ganador=0;

else if (tablero[i][j]=='0' && tablero[i+1][j]=='0' && tablero[i+2][j]=='0' && tablero[i+3][j]=='0')

ganador=1;

}

}

}

if (ganador==-1) {

for(i=0;i<FILAS;i++) {

for(j=0;j<COLUMNAS;j++) {

if (i+3<FILAS && j+3<COLUMNAS) {

if (tablero[i][j]=='X' && tablero[i+1][j+1]=='X' && tablero[i+2][j+2]=='X' && tablero[i+3][j+3]=='X')

ganador=0;

else if (tablero[i][j]=='0' && tablero[i+1][j+1]=='0' && tablero[i+2][j+2]=='0' && tablero[i+3][j+3]=='0')

ganador=1;

}

}

}

}

if (ganador==-1) {

for(i=0;i<FILAS;i++) {

for(j=0;j<COLUMNAS;j++) {

if (i+3<FILAS && j-3>=0) {

if (tablero[i][j]=='X' && tablero[i+1][j-1]=='X' && tablero[i+2][j-2]=='X' && tablero[i+3][j-3]=='X')

ganador=0;
else if (tablero[i][j]=='0' && tablero[i+1][j-1]=='0' && tablero[i+2][j-2]=='0' && tablero[i+3][j-3]=='0')

ganador=1;

}
}
}
}
return ganador;
}

int main () {

int jugador;
int total_jugadas;
total_jugadas=0;
inicializar_tablero();
do {

if (total_jugadas % 2 == 0)
jugador=0;

else
jugador=1;

total_jugadas++;
mostrar_tablero();
if (hacer_jugada(jugador)==0) {
printf("Jugada incorrecta.\n\n");

system("pause");
}
} while(comprobar_fin()==-1);
mostrar_tablero();

if (comprobar_fin()==1)

printf("Enhorabuena!! Has ganado!!\n\n");

else
printf("El ordenador ha ganado\n");
}
Volver arriba
      Índice del Foro elrincondelc.com -> Gráficos
Página 1 de 1Todas las horas están en GMT - 8 Horas

 
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas

(c) ElRincondelC.com

Un proyecto de UrlanHeat.com