Communauté Informatique NDFR.net : PROBLEME URGENT SVP - Programmation (C/C++, Delphi, VB, etc.)
Reply
PROBLEME URGENT SVP
Thread Tools Display Modes
  #1  
Old 21-03-2004, 10:21
LXir LXir is offline
Membre junior
 
Join Date: 21-03-2004
Posts: 1
Malheureux PROBLEME URGENT SVP

Salut,
J'ai un probleme avec le code suivant qui doit generer un labyrinthe aléatoire (main.c utilise les bibliothèques allegro et mur.bmp est un simple bitmap 20*20 pxls)

main.c :
#include <stdlib.h>
#include "gen_laby.h"
#include <allegro.h>

int laby[40][30],a,b;
BITMAP *mur;

// Fonction main
int main()
{
// Initialisation d'allegro
allegro_init();

// Mise en place du clavier
install_keyboard();

// Mise en place de la souris
if (install_mouse() == -1)
{
allegro_message("Erreur ! %s", allegro_error) ;
return 1 ;
}

// Définition de la profondeur de couleur
set_color_depth(16);

// Mise en place du mode graphique
if (set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Impossible d'initialiser le mode vidéo !\n%s\n", allegro_error);
return 1;
}

mur=load_bitmap("mur.bmp",NULL);

genere_laby(38,28,&laby[0][0],100);
for (b=0;b<28;b++)
for (a=0;a<38;a++)
{
if (laby[a][b]==MUR)
draw_sprite(screen,mur,a*20,b*20);
}

// Boucle principale
while (!key[KEY_ESC])
{
}
return 0;

**********************************
gen_laby.h :
#include <stdlib.h>
#include <mem.h>

#define HAUT 1
#define DROITE 2
#define BAS 3
#define GAUCHE 4

#define VIDE 0
#define MUR 1

// Fonction qui génère le labyrinthe de dimension dim_x, dim_y
// à enregistrer dans le tableau de taille [dim_x][dim_y] vers
// lequel pointe *lab à partir de la clef.
void genere_laby(int dim_x, int dim_y, int *lab, int clef)
{
int init[dim_x][dim_y], laby[dim_x][dim_y], poss[4], nbr_poss, a, b, c;
int x, y, direction;

// Initialisation du generateur de nombres aleatoires
srand(clef);

// Initialisations
memset(poss, 0, 4*sizeof(int) );
memset(init, 0, dim_x*dim_y*sizeof(int) );
memset(laby, MUR, dim_x*dim_y*sizeof(int)) ;

// Premier tunnel
x=1;
y=1;
init[x][y]=1;
laby[x][y]=VIDE;
while (1)
{
nbr_poss=0;
c=0;
if ((y-2>=0)&&(y-2<dim_y))
if (init[x][y-2]==0)
{
nbr_poss++;
poss[c]=HAUT;
c++;
}
if ((y+2>=0)&&(y+2<dim_y))
if (init[x][y+2]==0)
{
nbr_poss++;
poss[c]=BAS;
c++;
}
if ((x-2>=0)&&(x-2<dim_x))
if (init[x-2][y]==0)
{
nbr_poss++;
poss[c]=GAUCHE;
c++;
}
if ((x+2>=0)&&(x+2<dim_x))
if (init[x+2][y]==0)
{
nbr_poss++;
poss[c]=DROITE;
c++;
}
if (nbr_poss==0)
break;
direction=rand()%nbr_poss;
if (poss[direction]==HAUT)
{
init[x][y-2]=1;
laby[x][y-1]=VIDE;
laby[x][y-2]=VIDE;
y=y-2;
}
if (poss[direction]==BAS)
{
init[x][y+2]=1;
laby[x][y+1]=VIDE;
laby[x][y+2]=VIDE;
y=y+2;
}
if (poss[direction]==DROITE)
{
init[x+2][y]=1;
laby[x+1][y]=VIDE;
laby[x+2][y]=VIDE;
x=x+2;
}
if (poss[direction]==GAUCHE)
{
init[x-2][y]=1;
laby[x-1][y]=VIDE;
laby[x-2][y]=VIDE;
x=x-2;
}
}

// On creuse le labyrinthe
for (a=0;a<dim_x;a++)
for (b=0;b<dim_y;b++)
if (init[a][b]==0)
{

// Initialisation du tunnel
x=a;
y=b;
init[x][y]=1;
laby[x][y]=VIDE;
nbr_poss=0;
c=0;

// On relie le tunnel au labyrinthe
if ((y-2>=0)&&(y-2<dim_y))
if ((laby[x][y-1]+laby[x][y-2])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=HAUT;
c++;
}
if ((y+2>=0)&&(y+2<dim_y))
if ((laby[x][y+1]+laby[x][y+2])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=BAS;
c++;
}
if ((x-2>=0)&&(x-2<dim_x))
if ((laby[x-1][y]+laby[x-2][y])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=GAUCHE;
c++;
}
if ((x+2>=0)&&(x+2<dim_x))
if ((laby[x+1][y]+laby[x+2][y])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=DROITE;
c++;
}
direction=rand()%nbr_poss;
if (poss[direction]==HAUT)
{
laby[x][y-1]=VIDE;
laby[x][y-2]=VIDE;
}
if (poss[direction]==BAS)
{
laby[x][y+1]=VIDE;
laby[x][y+2]=VIDE;
}
if (poss[direction]==DROITE)
{
laby[x+1][y]=VIDE;
laby[x+2][y]=VIDE;
}
if (poss[direction]==GAUCHE)
{
laby[x-1][y]=VIDE;
laby[x-2][y]=VIDE;
}

// On creuse le tunnel
while (1)
{
nbr_poss=0;
c=0;
if ((y-2>=0)&&(y-2<dim_y))
if (init[x][y-2]==0)
{
nbr_poss++;
poss[c]=HAUT;
c++;
}
if ((y+2>=0)&&(y+2<dim_y))
if (init[x][y+2]==0)
{
nbr_poss++;
poss[c]=BAS;
c++;
}
if ((x-2>=0)&&(x-2<dim_x))
if (init[x-2][y]==0)
{
nbr_poss++;
poss[c]=GAUCHE;
c++;
}
if ((x+2>=0)&&(x+2<dim_x))
if (init[x+2][y]==0)
{
nbr_poss++;
poss[c]=DROITE;
c++;
}
if (nbr_poss==0)
break;
direction=rand()%nbr_poss;
if (poss[direction]==HAUT)
{
init[x][y-2]=1;
laby[x][y-1]=VIDE;
laby[x][y-2]=VIDE;
y=y-2;
}
if (poss[direction]==BAS)
{
init[x][y+2]=1;
laby[x][y+1]=VIDE;
laby[x][y+2]=VIDE;
y=y+2;
}
if (poss[direction]==DROITE)
{
init[x+2][y]=1;
laby[x+1][y]=VIDE;
laby[x+2][y]=VIDE;
x=x+2;
}
if (poss[direction]==GAUCHE)
{
init[x-2][y]=1;
laby[x-1][y]=VIDE;
laby[x-2][y]=VIDE;
x=x-2;
}
}

// On relie la fin du tunnel au labyrinthe
if ((y-2>=0)&&(y-2<dim_y))
if ((laby[x][y-1]+laby[x][y-2])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=HAUT;
c++;
}
if ((y+2>=0)&&(y+2<dim_y))
if ((laby[x][y+1]+laby[x][y+2])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=BAS;
c++;
}
if ((x-2>=0)&&(x-2<dim_x))
if ((laby[x-1][y]+laby[x-2][y])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=GAUCHE;
c++;
}
if ((x+2>=0)&&(x+2<dim_x))
if ((laby[x+1][y]+laby[x+2][y])==(MUR+VIDE))
{
nbr_poss++;
poss[c]=DROITE;
c++;
}
direction=rand()%nbr_poss;
if (poss[direction]==HAUT)
{
laby[x][y-1]=VIDE;
laby[x][y-2]=VIDE;
}
if (poss[direction]==BAS)
{
laby[x][y+1]=VIDE;
laby[x][y+2]=VIDE;
}
if (poss[direction]==DROITE)
{
laby[x+1][y]=VIDE;
laby[x+2][y]=VIDE;
}
if (poss[direction]==GAUCHE)
{
laby[x-1][y]=VIDE;
laby[x-2][y]=VIDE;
}
}
memmove(lab, laby, dim_x*dim_y*sizeof(int) );
return;
}

lors de l'éxecution, windows renvoie une erreur.
Merci de m'aider.
Reply With Quote
  #2  
Old 21-03-2004, 11:22
Cougar's Avatar
Cougar Cougar is offline
Membre senior
 
Join Date: 16-09-2001
Location: Orléans
Age: 39
Posts: 3,850
Send a message via MSN to Cougar
Re: PROBLEME URGENT SVP

Utilise un compilateur comme Turbo C++ (dispo gratuitement sur borland.com) qui te permettra de savoir exactement où ça coince.
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Petit probléme avec outlook express !!! Alexlesioux Internet, Réseaux et Sécurité 11 31-08-2004 07:16
c urgent probleme de capture d'evenemet rymoez Programmation (C/C++, Delphi, VB, etc.) 2 30-06-2004 22:54
Probléme de lenteurs... chalouf Discussions sur le site et/ou le forum 11 22-01-2003 19:37
Probleme site!! chalouf Discussions sur le site et/ou le forum 4 21-10-2002 21:06
Problème forum claude922 Discussions sur le site et/ou le forum 15 21-10-2002 07:04

All times are GMT +2. The time now is 21:36.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.