示例#1
0
void marcar(char tablero[9][9],char tablero_de_pasos[9][9],int x_actual, int y_actual,int pasos)
{
    //Casos base
    if(pasos<0)
        return;

    if(x_actual>=9
       || y_actual>=9
       || x_actual<0
       || y_actual<0)
       return;

    if(tablero[y_actual][x_actual]=='#')
       return;

    tablero_de_pasos[y_actual][x_actual]='P';


    if(tablero[y_actual][x_actual]=='O')
        pasos--;

    pasos--;



//    if(tablero[y_actual][x_actual]=='V'
//       && pasos<=0)
//        pasos=1;

    marcar(tablero,tablero_de_pasos,x_actual+1,y_actual,pasos);
    marcar(tablero,tablero_de_pasos,x_actual-1,y_actual,pasos);
    marcar(tablero,tablero_de_pasos,x_actual,y_actual+1,pasos);
    marcar(tablero,tablero_de_pasos,x_actual,y_actual-1,pasos);
}
示例#2
0
void Nodo :: buscar(list<Nodo*> grupo)
{
    for(Nodo* actual : grupo)
        if(actual->grupo==0){
            bool esActual = true;
            for(Nodo* actual : actual->adj)
                if(actual->grupo == grupoActual)
                    esActual = false;
            if(esActual)
                marcar(actual);
        }
}
示例#3
0
//pete(carr,ciu[0].nombre_ciudad,ciu);
int pete(st_carreteras ciud1[], char *potix,st_ciudades  ciud2[] ,int *y){
        int j;
for (j=0;j<350;j++){
if (strcmp(ciud2[j].nombre_ciudad,potix)==0&&ciud2[j].visitado==1)
    return 0;
}
        marcar( ciud2,potix);
        (*y)++;
        for (j=0;j<500;j++){
        if (strcmp(potix,ciud1[j].ciudad_destino)==0){
            pete(ciud1,ciud1[j].ciudad_origen,ciud2,y);

            }
        }

return 1;
}
示例#4
0
bool recorrer2(st_carreteras carre[],st_ciudades cius[], ciunke cius2[],st_ciudades pepe,st_ciudades lino,float recorrido, char * khe){
int j,e;
//getchar();

c_heuristic(cius,lino);


if (pepe.nombre_ciudad!=lino.nombre_ciudad)

    marcar(cius,pepe.nombre_ciudad);
//pepe.visitado=1;
if (pepe.nombre_ciudad==lino.nombre_ciudad){
    //printf("Exito %s : %f  desde: %s\n", pepe.nombre_ciudad, pepe.recorrido, khe);
    distanciax= pepe.recorrido+distanciax;
   // return pepe.recorrido;
return true;
}
// printf("Actual %s : %f desde: %s\n\n", pepe.nombre_ciudad, pepe.recorrido, khe);

float aux=0, min=INF;
  for (j=0;j<500;j++){
        if (carre[j].ciudad_origen==pepe.nombre_ciudad){
              for(e=0;e<350;e++){
              if(cius[e].nombre_ciudad==carre[j].ciudad_destino){
              //  printf("la suma entre la heuristica y la distancia es: %s   %f\n", carre[j].ciudad_destino, cius[e].heuristica+carre[j].distancia);

                //cius[e].recorrido
                float nene=recorrido+carre[j].distancia;

                //cius[e].recorrido=nene;
                if(cius[e].recorrido>0&&cius[e].recorrido<nene)nene=cius[e].recorrido;
                cius[e].recorrido=nene;



                aux=cius[e].heuristica+cius[e].recorrido;


                cius2[into].nombre=cius[e].nombre_ciudad;
                cius2[into].funcion=  cius[e].heuristica+carre[j].distancia+cius[e].recorrido;// //+cius[e].recorrido;//  //
                into++;


                if(aux<min) min=aux;
                }

              }
              }
            }


            bubbleSort(cius2,into);
int a;
/*
printf("%i\n",into);
for (a=0;a<into;a++)
printf("%s : funcion :%f\n",ciutre[a].nombre,ciutre[a].funcion);
for (a=0;a<350;a++)
    if (strlen(cius[a].nombre_ciudad)>0)
printf("%s : recorrido :%f\n",cius[a].nombre_ciudad,cius[a].recorrido);

*/
int ki=0;

            for (e=0;e<=into;e++){
              //  for (j=0;j<500;j++){
              int k;

            for(k=0;k<350;k++){
                if(strlen(cius[k].nombre_ciudad)>0)
                if(cius[k].nombre_ciudad==cius2[e].nombre){
            //    printf("El minimo es: %s   : %f  \n",carr[j].ciudad_destino, min);
                if(cius[k].visitado!=1)
            if( recorrer2(carre,cius,cius2,cius[k],lino,cius[k].recorrido,pepe.nombre_ciudad))ki++;
           //    recorrer2(carre,cius,cius2,cius[k],lino,cius[k].recorrido,pepe.nombre_ciudad);
                //cius[k].visitado=1;
                //pepe.visitado=1;

               // return true;
                }
               //


            }


            //}

cius2[e].nombre="";
cius2[e].funcion= INF;

            }

           // for(a=0;a<350;a++)
             //   ciu[a].visitado=0;



 if (ki>0)return true;
          else  return false;

}
示例#5
0
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;
}