bool puedoLLegar(char tablero[9][9],int x_actual, int y_actual,int pasos, int x_final, int y_final) { //Casos base if(pasos<0) return false; if(x_actual>=9 || y_actual>=9 || x_actual<0 || y_actual<0) return false; if(tablero[y_actual][x_actual]=='#') return false; if(x_actual==x_final && y_actual==y_final) return true; if(tablero[y_actual][x_actual]=='O') pasos--; pasos--; // if(tablero[y_actual][x_actual]=='V' // && pasos<=0) // pasos=1; return puedoLLegar(tablero,x_actual+1,y_actual,pasos,x_final,y_final) || puedoLLegar(tablero,x_actual-1,y_actual,pasos,x_final,y_final) || puedoLLegar(tablero,x_actual,y_actual+1,pasos,x_final,y_final) || puedoLLegar(tablero,x_actual,y_actual-1,pasos,x_final,y_final); }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Generate the message surfaces // upMessage = TTF_RenderText_Solid( font, "Up was pressed.", textColor ); // downMessage = TTF_RenderText_Solid( font, "Down was pressed.", textColor ); // leftMessage = TTF_RenderText_Solid( font, "Left was pressed", textColor ); // rightMessage = TTF_RenderText_Solid( font, "Right was pressed", textColor ); SDL_Surface* pasillo = load_image("tablero/path.png"); SDL_Surface* muro = load_image("tablero/brick.png"); SDL_Surface* obstaculo = load_image("tablero/green.png"); SDL_Surface* ventaja = load_image("tablero/adv.png"); char tablero[9][9]={{' ','#',' ','O','V',' ','#',' ','O'}, {' ','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#','#',' ',' ',' ','O'}, {' ','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#','#',' ','#',' ','O'}, {' ','#',' ','#',' ',' ','#',' ','O'}, {' ','O','O',' ',' ',' ','#',' ','O',}}; char tablero_de_pasos[9][9]={{' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}}; SDL_Surface* pasos_surface = load_image("pasos.png"); SDL_Surface* atq_surface = load_image("ataque.png"); SDL_Surface* win_surface = load_image("win.png"); SDL_Surface* go_surface = load_image("go.png"); SDL_Surface* personaje_surface = load_image("player1/image1.png"); SDL_Surface* enemigo_surface = load_image("enem.png"); Personaje* personaje= new Personaje(2,3,personaje_surface); Personaje* enemigo=new Personaje(5,5,enemigo_surface); Personaje* actual=personaje; // enemigo.turn=false; SDL_Surface* cursor_surface = load_image("cursor.png"); int cursor_x=0; int cursor_y=0; //While the user hasn't quit while( quit == false ) { //If there's an event to handle if( SDL_PollEvent( &event ) ) { //If a key was pressed if( event.type == SDL_KEYDOWN ) { //Set the proper message surface switch( event.key.keysym.sym ) { case SDLK_UP: cursor_y--; // // limpiar(tablero_de_pasos); // if(cursor_x==personaje->x && cursor_y==personaje->y) // { // // marcar_atq(tablero,tablero_de_pasos,personaje->x,personaje->y,3); // // marcar(tablero,tablero_de_pasos,personaje->x,personaje->y,2); // } break; case SDLK_DOWN: cursor_y++; break; case SDLK_LEFT: cursor_x--; break; case SDLK_RIGHT: cursor_x++; break; case SDLK_F1: // personaje->atacar(enemigo); // enemigo->attacar(personaje); if(actual->x==personaje->x && actual->y==personaje->y){ enemigo->atacar(personaje); } if(actual->x==enemigo->x && actual->y==enemigo->y) personaje->atacar(enemigo); break; case SDLK_RETURN: if(turno){ if(puedoLLegar(tablero,personaje->x,personaje->y,2,cursor_x,cursor_y)) { actual = personaje; personaje->x=cursor_x; personaje->y=cursor_y; limpiar(tablero_de_pasos); marcar_atq(tablero,tablero_de_pasos,personaje->x,personaje->y,3); marcar(tablero,tablero_de_pasos,personaje->x,personaje->y,2); } turno=false; } else if(turno==false){ if(puedoLLegar(tablero,enemigo->x,enemigo->y,2,cursor_x,cursor_y)) { actual=enemigo; enemigo->x=cursor_x; enemigo->y=cursor_y; limpiar(tablero_de_pasos); marcar_atq(tablero,tablero_de_pasos,enemigo->x,enemigo->y,3); marcar(tablero,tablero_de_pasos,enemigo->x,enemigo->y,2); } turno =true; } break; } } //If the user has Xed out the window else if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Apply the background apply_surface( 0, 0, background, screen ); //If a message needs to be displayed if( message != NULL ) { //Apply the background to the screen apply_surface( 0, 0, background, screen ); //Apply the message centered on the screen apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen ); //Null the surface pointer message = NULL; } for(int x=0;x<9;x++) for(int y=0;y<9;y++) { if(tablero[y][x]==' ') apply_surface(x*75,y*75,pasillo,screen); if(tablero[y][x]=='#') apply_surface(x*75,y*75,muro,screen); if(tablero[y][x]=='O') apply_surface(x*75,y*75,obstaculo,screen); if(tablero[y][x]=='V') apply_surface(x*75,y*75,ventaja,screen); } for(int x=0;x<9;x++) for(int y=0;y<9;y++){ if(tablero_de_pasos[y][x]=='P') apply_surface(x*75,y*75,pasos_surface,screen); if(tablero_de_pasos[y][x]=='A') apply_surface(x*75,y*75,atq_surface,screen); } personaje->hp=TTF_RenderText_Solid( personaje->font, personaje->toString(personaje->vida).c_str(), personaje->textColor ); enemigo->hp=TTF_RenderText_Solid( enemigo->font, enemigo->toString(enemigo->vida).c_str(), enemigo->textColor ); personaje->dibujar(screen); // personaje->hp_dibujar(screen); enemigo->dibujar(screen); //enemigo->hp_dibujar(screen); apply_surface(cursor_x*75,cursor_y*75,cursor_surface,screen); if(personaje->vida==0) apply_surface(0,0,go_surface,screen); if(enemigo->vida==0) apply_surface(0,0,win_surface,screen); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } } //Clean up clean_up(); return 0; }
void evaluar() { double nota =0; NodoTrinario* nt1=new NodoTrinario(1); NodoTrinario* nt2=new NodoTrinario(2); NodoTrinario* nt3=new NodoTrinario(3); NodoTrinario* nt4=new NodoTrinario(4); NodoTrinario* nt5=new NodoTrinario(5); NodoTrinario* nt6=new NodoTrinario(6); NodoTrinario* nt7=new NodoTrinario(7); NodoTrinario* nt8=new NodoTrinario(8); NodoTrinario* nt9=new NodoTrinario(9); nt1->izq = nt2; nt1->medio = nt3; nt1->der = nt4; nt2->izq = nt5; nt2->medio = nt6; nt6->izq = nt7; nt3->izq = nt8; nt3->medio = nt9; cout<<"existe() - trinario:\t"; if(!existe(nt1,10) && !existe(nt1,12) && !existe(nt2,1) && existe(nt1,1) && existe(nt1,5) && existe(nt6,7)) { cout<<"Correcto"<<endl; nota+=2.5; }else { cout<<"Incorrecto"<<endl; } NodoNario* n1=new NodoNario(1); NodoNario* n2=new NodoNario(2); NodoNario* n3=new NodoNario(3); NodoNario* n4=new NodoNario(4); NodoNario* n5=new NodoNario(5); NodoNario* n6=new NodoNario(1); NodoNario* n7=new NodoNario(1); NodoNario* n8=new NodoNario(2); n1->hijos.push_back(n2); n1->hijos.push_back(n3); n2->hijos.push_back(n4); n4->hijos.push_back(n5); n5->hijos.push_back(n6); n5->hijos.push_back(n7); n5->hijos.push_back(n8); cout<<"existe() - nario:\t"; if(!existe(n1,10) && !existe(n1,12) && !existe(n8,1) && existe(n1,1) && existe(n1,5) && existe(n5,2)) { cout<<"Correcto"<<endl; nota+=2.5; }else { cout<<"Incorrecto"<<endl; } NodoBinario* nb1=new NodoBinario(1); NodoBinario* nb2=new NodoBinario(2); NodoBinario* nb3=new NodoBinario(3); NodoBinario* nb4=new NodoBinario(4); NodoBinario* nb5=new NodoBinario(5); NodoBinario* nb6=new NodoBinario(1); NodoBinario* nb7=new NodoBinario(2); NodoBinario* nb8=new NodoBinario(1); nb1->izq=nb2; nb1->der=nb3; nb3->der=nb4; nb4->izq=nb5; nb5->izq=nb6; nb2->izq=nb7; nb2->der=nb8; cout<<"contar():\t\t"; if(contar(nb1,1)==3 && contar(nb1,2)==2 && contar(nb1,3)==1 && contar(nb1,50)==0 && contar(nb7,1)==0) { cout<<"Correcto"<<endl; nota+=5; }else { cout<<"Incorrecto"<<endl; } int arr[5][5]= {{0,1,1,0,0}, {0,1,0,0,0}, {0,1,1,0,1}, {0,1,2,0,1}, {0,0,0,1,1}}; cout<<"puedoLLegar():\t\t"; if(!puedoLLegar(arr,0,0,2,1,11) && puedoLLegar(arr,0,0,2,1,12)) { cout<<"Correcto"<<endl; nota+=5; }else { cout<<"Incorrecto"<<endl; } cout<<endl<<"Nota: "<<nota<<"/15"<<endl; }