elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / problema con juego en: 28 Noviembre 2013, 00:04 am
hola tengo un problema con un juego llamado othello al ejecutar inicia pero despues de un rato me deja de fucionar


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define F 8
#define C 8

char otelo [F][C];
int pintaOtelo (){
   system("color 35");
   int i,j;
   
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("--------------------------------\n");
   for (i=0;i<=F-1;i++){
         for (j=0;j<=C-1;j++){
                printf("%c  ",otelo [j] );
            if (j<=(C-1)){
                printf("|");
             }
         }
         printf("\n");
         if (i<=(F-1)){
               printf("--------------------------------\n");
         }
         
   }
   printf("\n");
}
int inicializaOtelo (){
   int i,j;
   for (i=0;i <=F-1; i++ ){
         for (j=0;j <=C-1; j++ ){
            otelo [j] =' ';
         }
   }
}

int valoresIniciales(){
     otelo[3][3]='o';
     otelo[4][3]='o';
     otelo[4][4]='x';
     otelo[3][4]='x';
     }

int casillaVacia(int fila,int columna){
   system("color 89");
    if(otelo[fila][columna]==' '){
      return 0;                
     }
    else{
        if(otelo[fila][columna]=='x'){
            return 1;
      }
     
    else {
          return 2;    
     }
    }
    system("pause");
}


int juega(){
   int f,c,k,e,encontre,turno,veces;
   valoresIniciales();
    pintaOtelo();
   do{
      if (turno==0){
            system("color 2");
         printf("jugador 1\n");
      }
      else{
            system("color 4");
         printf("jugador 2\n");
      }
      printf("Dime renglon: ");scanf("%i",&f);fflush(stdin);
       printf("Dime columna: ");scanf("%i",&c);fflush(stdin);   
      if  (casillaVacia(f,c)==0){
          if (validaDerecha(f,c,turno)!=0){ encontre= cambia(f,c,turno,2); }
           if (validaIzquierda(f,c,turno)!=0){ }
         if (validaAbajo(f,c,turno)!=0){      }
         if (validaArriba(f,c,turno)!=0){    }
         if (validaDSD(f,c,turno)!=0){       }            
          if (validaDSD(f,c,turno)!=0){       }               
          if (validaDSI(f,c,turno)!=0){       }   
         if (validaDID(f,c,turno)!=0){       }   
         if (validaDII(f,c,turno)!=0){       }   
         }
         if(encontre==1){turno=asignaYCambiaTurno(f,c,turno); }               
        else{
             printf("la casilla la ocupa el jugador %i \n",casillaVacia(f,c));
        }
          system("cls");
          veces++;pintaOtelo();
          cambia();
          cuenta();
       system("pause");
         system("cls");
       pintaOtelo();
        
        
   }while (veces!=64);

}
int asignaYCambiaTurno(int ren, int col, int tur){
   if (tur==0){   otelo[ren][col]='x';tur=1;}
            else{   otelo[ren][col]='o';tur=0;}   
            printf("%i****************\n",tur);
   return tur;
}

int cambia(int fila,int col,int turno,int direccion){
int columna_original=col,i;
int enc=0;
   switch(direccion){
      case 2:{
               if(turno==0){
                   while(col<=7&&enc==0){
                       col++;
                      if(otelo[fila][col]=='x'){
                        for(i=col;i>=columna_original;i--){
                            otelo[fila]='x';
                        }
                        enc=1;
                    }
            
                   }
                }
                if(turno==1){
                   while(col<=7&&enc==1){
                       col++;
                      if(otelo[fila][col]=='o'){
                        for(i=col;i>=columna_original;i--){
                            otelo[fila]='o';
                            }
                          enc=0;
                    }
            
                   }
                }
        }   
   }
   return enc;
}
int cuenta(){
   int i,j;
   int cox=0,coo=0;
   for (i=0;i <=F-1; i++ ){
         for (j=0;j <=C-1; j++ ){
            if(otelo [j] =='x'){
               cox++;
            }
            else{
            
                 if(otelo [j] =='o'){
                         coo++;
                  }
              }
         }
   }
   printf("Puntos del jug 1 -> %i   puntos del jugador 2 ->%i\n",cox,coo);
   if(cox+coo==64){
          if(cox<coo){
               printf("El ganador es jugador 2");
          }
          else{
               printf("El ganador es jugador 1");
          }
    }
         
}



int validaDerecha(int f,int c, int turno){
   if(turno==0){
        if(otelo[f][c+1]=='o'){
          return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f][c+1]=='x'){
         return 1;
        }
        else{
           return 0;
        }
   }
}
int validaIzquierda(int f,int c, int turno){
   if(turno==0){
        if(otelo[f][c-1]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f][c-1]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int validaAbajo(int f,int c, int turno){
   if(turno==0){
        if(otelo[f+1][c]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f+1][c]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int validaArriba(int f,int c, int turno){
   if(turno==0){
        if(otelo[f-1][c]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f-1][c]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int validaDSD(int f,int c, int turno){/*Derecha arriba*/
   if(turno==0){
        if(otelo[f-1][c+1]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f-1][c+1]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int validaDSI(int f,int c, int turno){/*Izquierda arriba*/
   if(turno==0){
        if(otelo[f-1][c-1]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f-1][c-1]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int validaDID(int f,int c, int turno){/*Derecha abajo*/
   if(turno==0){
        if(otelo[f+1][c+1]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f+1][c+1]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int validaDII(int f,int c, int turno){/*Izquierda abajo*/
   if(turno==0){
        if(otelo[f+1][c-1]=='o'){
           return 2;
         }
         else {
            return 0;
         }
    }
    else{
        if(otelo[f+1][c-1]=='x'){
          return 1;
        }
        else{
           return 0;
        }
   }
}
int main(int argc, char *argv[]){
 
    system("cls");
    inicializaOtelo ();
    juega();
 
  system("PAUSE");   
  return 0;
}

Tambien tengo otro problema la 'x' no se cambia por la 'o'
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines