Título: Ayuda con juego en c++ Publicado por: Abbaidd en 15 Diciembre 2010, 00:55 am Hola amigos soy nuevo en el foro y me gustaria que me ayudaran con un juego del gato y el raton donde el gato se mueve 2 espacios y el raton un espacio y el juego termina cuando el gato "atrapa" al raton la verdad me he esta quebrando la cabeza con este codigo pero yo se que aqui hay expertos y talvez es sencillo para ellos
aqui esta el codigo pero cuando lo compilo con el dev c++ me sale [linker error] undifined reference to movimientoraton().. #include <iostream> #include <cstdlib> using std::cout; using std::cin; enum Direction { DOWN, RIGHT, UP, LEFT }; const int X_START = 2, Y_START = 0; const int Z_START = 11,T_START =11; void laberintotransversal( char [][ 12 ], int, int, int,int,int ); void imprimirlaberinto( const char[][ 12 ] ); void movimientoraton(const char[][12],int,int,int*,int*,int); bool validarRaton(const char[][12],int,int,int,int,int); bool movimientogato( const char [][ 12 ], int, int ,int,int); int main() { char laberinto [ 12 ][ 12 ] = { {'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'}, {'#', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#'}, {'#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#'}, {'#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#'}, {'#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '#'}, {'#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#'}, {'#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#'}, {'#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#'}, {'#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#'}, {'#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#'}, {'#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '-', '#'}, {'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'} }; laberintotransversal( laberinto , X_START, Y_START,Z_START, T_START, RIGHT ); return 0; } void laberintotransversal( char laberinto [][ 12 ], int xCoord, int yCoord,int zCoord,int tCoord, int direccion ) { static bool flag = false; laberinto [ xCoord ][ yCoord ] = 'X'; laberinto [zCoord][tCoord]='0'; imprimirlaberinto( laberinto ); int *z=&zCoord; int *t=&tCoord; for ( int mover = direccion, conta = 0; conta < 4; ++conta, ++mover, mover %= 4 ) switch( mover ) { case DOWN: if ( movimientogato( laberinto , xCoord + 1, yCoord,zCoord,tCoord ) ) { laberintotransversal( laberinto , xCoord + 1, yCoord,zCoord,tCoord , LEFT ); movimientoraton(laberinto,xCoord,yCoord,z,t,direccion); return; } break; case RIGHT: if ( movimientogato( laberinto , xCoord, yCoord + 1,zCoord,yCoord ) ) { laberintotransversal( laberinto , xCoord, yCoord + 1,zCoord,tCoord , DOWN ); movimientoraton (laberinto,xCoord,yCoord,z,t,direccion); return; } break; case UP: if ( movimientogato( laberinto , xCoord - 1, yCoord,zCoord,yCoord ) ) { laberintotransversal( laberinto , xCoord - 1, yCoord,zCoord,tCoord , RIGHT ); movimientoraton (laberinto,xCoord,yCoord,z,t,direccion); return; } break; case LEFT: if ( movimientogato( laberinto , xCoord, yCoord - 1 ,zCoord,yCoord) ) { laberintotransversal( laberinto , xCoord, yCoord - 1,zCoord,tCoord , UP ); movimientoraton (laberinto,xCoord,yCoord,z,t,direccion); return; } break; } } bool movimientogato( const char laberinto [][ 12 ], int r, int c,int p, int q ) { return ( r >= 0 && r <= 11 && c >= 0 && c <= 11 && laberinto [ r ][ c ] != '#' ); } void movimientoraton(char laberinto[][12],int x,int y,int *z,int *t,int direccion){ int n=*z; int m=*t; for ( int mover2 = direccion, conta = 0; conta < 4; ++conta, ++mover2, mover2 %= 4 ) switch( mover2 ) { case DOWN: if ( validarRaton( laberinto , x, y,n+1,m,direccion) ) { laberintotransversal( laberinto , x, y,n+1,m,direccion); return; } break; case RIGHT: if ( validarRaton( laberinto , x, y,n,m+1,direccion) ) { laberintotransversal( laberinto , x, y,n,m+1,direccion); return; } break; case UP: if ( validarRaton( laberinto , x, y,n-1,m,direccion) ) { laberintotransversal( laberinto , x, y,n-1,m,direccion ); return; } break; case LEFT: if ( validarRaton( laberinto , x, y,n,-1,direccion ) ) { laberintotransversal( laberinto , x, y,n,m-1 ,direccion); return; } break;} } bool validarRaton(const char laberinto[][12],int x,int y,int n,int m) {return ( m >= 0 && n<= 11 && m >= 0 && m<= 11 && laberinto [ n][m] != '#' ); } void imprimirlaberinto( const char laberinto [][ 12 ] ) { for ( int w = 0; w < 12; ++w) { for ( int o = 0; 0 < 12; ++o ) cout << laberinto [ w][ 0] << ' '; cout << '\n'; } cout << "\nPresione Enter para ver la siguiente jugada\n"; cin.get(); } |