Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
#include <stdio.h>
#include <stdlib.h>     // Para usar funcion de limpiar pantalla
#include <windows.h>    // Para usar funcion de hacer pausa
#define TAM_FIL 12
#define TAM_COL 12
typedef struct
{
    int estaEnFinal; //------------------- Para saber si llego al final el objeto
    char simbolo;
    int pos_x; //------------------------- Coordenada del objeto en X
    int pos_y; //------------------------- Coordenada del objeto en Y
}Objeto;
typedef struct
{
    // ----------------------------------- Simplemente para saber las coordenadas de los puntos X e Y de inicio y fin del laberinto ------------------------------------
    int ini_fil;
    int ini_col;
    int fin_fil;
    int fin_col;
}InformacionMapa;
void mostrarEstadoMapa( char laberinto[][TAM_COL] );
int recorrerLaberinto( char laberinto[][TAM_COL], InformacionMapa *punto, Objeto obj );
int main( int argc, char* args[] )
{
    InformacionMapa mapa;
    mapa.ini_fil = 2;
    mapa.ini_col = 0;
    mapa.fin_fil = 4;
    mapa.fin_col = 11;
    Objeto obj;
    obj.simbolo = 'X';
    obj.estaEnFinal = 0;
    obj.pos_x = 2;
    obj.pos_y = 0;
    char laberinto[TAM_FIL][TAM_COL] = { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#',
                                         '#', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', ' ', ' ', '#',
                                         ' ', ' ', '#', ' ', '#', ' ', '#', '#', '#', '#', ' ', '#',
                                         '#', '#', '#', ' ', '#', ' ', ' ', ' ', ' ', '#', ' ', '#',
                                         '#', ' ', ' ', ' ', ' ', '#', '#', '#', ' ', ' ', ' ', ' ',
                                         '#', '#', '#', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#',
                                         '#', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#',
                                         '#', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#',
                                         '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', '#',
                                         '#', '#', '#', '#', '#', '#', ' ', '#', '#', '#', ' ', '#',
                                         '#', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', ' ', ' ', '#',
                                         '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'
                                       };
    if( recorrerLaberinto( laberinto, &mapa, obj ) == 1 )
        printf("\n\n\nFinal del laberinto encontrado");
    else
        printf("\n\n\nNo hay salida en este laberinto.");
    getchar();
	return 0;
}
void mostrarEstadoMapa( char laberinto[][TAM_COL] )
{
    int cont_fil, cont_col;
    system("cls");
    for( cont_fil = 0; cont_fil < TAM_FIL; cont_fil++ )
    {
        for( cont_col = 0; cont_col < TAM_COL; cont_col++ )
        {
            printf("%c", laberinto[cont_fil][cont_col]);
            printf("  ");
        }
        printf("\n\n");
    }
    Sleep(200);
}
int recorrerLaberinto( char laberinto[][TAM_COL], InformacionMapa *mapa, Objeto obj )
{
    if( obj.pos_x == mapa->fin_fil && obj.pos_y == mapa->fin_col )
    {
        obj.estaEnFinal++;
        return 1;
    }
    laberinto[obj.pos_x][obj.pos_y] = obj.simbolo;
    mostrarEstadoMapa( laberinto );
    if( laberinto[obj.pos_x][obj.pos_y + 1] == ' ' && obj.pos_y + 1 < TAM_COL )
    {
        obj.pos_y++;
        if( recorrerLaberinto( laberinto, mapa, obj ) == 1 )
            return 1;
    }
    if( laberinto[obj.pos_x + 1][obj.pos_y] == ' ' && obj.pos_x + 1 < TAM_FIL )
    {
        obj.pos_x++;
        if( recorrerLaberinto( laberinto, mapa, obj ) == 1 )
            return 1;
    }
    if( laberinto[obj.pos_x - 1][obj.pos_y] == ' ' && obj.pos_x - 1 >= 0 )
    {
        obj.pos_x--;
        if( recorrerLaberinto( laberinto, mapa, obj ) == 1 )
            return 1;
    }
    if( laberinto[obj.pos_x][obj.pos_y - 1] == ' ' && obj.pos_y - 1 >= 0 )
    {
        obj.pos_y--;
        if( recorrerLaberinto( laberinto, mapa, obj ) == 1 )
            return 1;
    }
    return 0;
}
				if( laberinto[obj->pos_x][obj->pos_y + 1] != '#' && laberinto[obj->pos_x][obj->pos_y + 1] != obj->simbolo )
#include <stdio.h>
#include <stdlib.h>     // Para usar funcion de limpiar pantalla
#include <windows.h>    // Para usar funcion de hacer pausa
#define TAM_FIL 12
#define TAM_COL 12
using namespace std;
typedef struct
{
    int estaEnInicio, estaEnFinal; //----- Para saber cuantas veces nuestro objeto ha estado en el inicio y si esta en el final
    char simbolo;
    int pos_x; //------------------------- Coordenada del objeto en X
    int pos_y; //------------------------- Coordenada del objeto en Y
}Objeto;
typedef struct
{
    // ----------------------------------- Simplemente para saber las coordenadas de los puntos X e Y de inicio y fin del laberinto ------------------------------------
    int ini_fil;
    int ini_col;
    int fin_fil;
    int fin_col;
}InformacionMapa;
void mostrarEstadoMapa( char laberinto[][TAM_COL] );
void recorrerLaberinto( char laberinto[][TAM_COL], InformacionMapa *punto, Objeto *obj );
int main( int argc, char* args[] )
{
    int cont_fil, cont_col;
    InformacionMapa mapa;
    mapa.ini_fil = 2;
    mapa.ini_col = 0;
    mapa.fin_fil = 4;
    mapa.fin_col = 11;
    Objeto obj;
    obj.simbolo = 'X';
    obj.estaEnInicio = 0;
    obj.estaEnFinal = 0;
    obj.pos_x = 2;
    obj.pos_y = 0;
    char laberinto[TAM_FIL][TAM_COL] = { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#',
                                         '#', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', ' ', ' ', '#',
                                         ' ', ' ', '#', ' ', '#', ' ', '#', '#', '#', '#', ' ', '#',
                                         '#', '#', '#', ' ', '#', ' ', ' ', ' ', ' ', '#', ' ', '#',
                                         '#', ' ', ' ', ' ', ' ', '#', '#', '#', ' ', ' ', ' ', ' ',
                                         '#', '#', '#', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#',
                                         '#', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#',
                                         '#', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#',
                                         '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', '#',
                                         '#', '#', '#', '#', '#', '#', ' ', '#', '#', '#', ' ', '#',
                                         '#', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', ' ', ' ', '#',
                                         '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'
                                       };
    recorrerLaberinto( laberinto, &mapa, &obj );
    getchar();
	return 0;
}
void mostrarEstadoMapa( char laberinto[][TAM_COL] )
{
    int cont_fil, cont_col;
    system("cls");
    for( cont_fil = 0; cont_fil < TAM_FIL; cont_fil++ )
    {
        for( cont_col = 0; cont_col < TAM_COL; cont_col++ )
        {
            printf("%c", laberinto[cont_fil][cont_col]);
            printf("  ");
        }
        printf("\n\n");
    }
    Sleep(500);
}
void recorrerLaberinto( char laberinto[][TAM_COL], InformacionMapa *mapa, Objeto *obj )
{
    if( obj->pos_x == mapa->ini_fil && obj->pos_y == mapa->ini_col )
        obj->estaEnInicio++;
    else if( obj->pos_x == mapa->fin_fil && obj->pos_y == mapa->fin_col )
        obj->estaEnFinal++;
    while( laberinto[4][11] != obj->simbolo && obj->estaEnInicio == 1 && !obj->estaEnFinal )
    {
        laberinto[obj->pos_x][obj->pos_y] = obj->simbolo;
        mostrarEstadoMapa( laberinto );
        if( laberinto[obj->pos_x][obj->pos_y + 1] != '#' && laberinto[obj->pos_x][obj->pos_y + 1] != obj->simbolo )
        {
            obj->pos_y++;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x + 1][obj->pos_y] != '#' && laberinto[obj->pos_x + 1][obj->pos_y] != obj->simbolo )
        {
            obj->pos_x++;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x - 1][obj->pos_y] != '#' && laberinto[obj->pos_x - 1][obj->pos_y] != obj->simbolo )
        {
            obj->pos_x--;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x][obj->pos_y - 1] != '#' && laberinto[obj->pos_x][obj->pos_y - 1] != obj->simbolo )
        {
            obj->pos_y--;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x][obj->pos_y - 1] != '#' )
        {
            obj->pos_y--;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x - 1][obj->pos_y] != '#' )
        {
            obj->pos_x--;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x + 1][obj->pos_y] != '#' )
        {
            obj->pos_x++;
            recorrerLaberinto( laberinto, mapa, obj );
        }
        else if( laberinto[obj->pos_x][obj->pos_y + 1] != '#' )
        {
            obj->pos_y++;
            recorrerLaberinto( laberinto, mapa, obj );
        }
    }
    if( obj->estaEnInicio > 1 )
        printf("\n\n\nNo hay salida en este laberinto.");
    if( obj->estaEnFinal )
        printf("\n\n\nFinal del laberinto encontrado");
}