Frédéric.
J'utilise le logiciel Scite (je suis sous Linux). C'est un programme en C.
Voici le code:
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
void ncurses();
void mat();
void deplacer();
void ncurses(){
initscr();
noecho();
start_color();
init_pair(1, COLOR_RED, COLOR_RED);
init_pair(2, COLOR_RED, COLOR_BLUE);
init_pair(3, COLOR_RED, COLOR_WHITE);
init_pair(4, COLOR_RED, COLOR_GREEN);
}
void mat(){
int largeur=30,hauteur=30;
char lab[largeur][hauteur];
int nb_ligne,nb_col;
for(nb_ligne=0;nb_ligne<=hauteur;nb_ligne++)
{
for(nb_col=0;nb_col<=largeur;nb_col++)
{
lab[nb_ligne][nb_col]='0';
}
}
}
void deplacer(int nb_ligne, int nb_col){
move(nb_ligne,nb_col);
wattrset (stdscr, COLOR_PAIR(2));
addch('>');
}
int main (int argc, char **argv)
{
int largeur=30,hauteur=30;
char lab[largeur][hauteur];
int nb_ligne,nb_col;
FILE *fichier;
char chaine;
int key=0;
fichier=fopen("stylelabyrinthe.txt","r" ); /*Ca c'est un fichier en txt que j'ai crée pour générer un style de labyrinthe, et c'est ca mon pb!!!*/
/****************init lab******************/
mat();
/****************initlab******************/
/***********ncureses*************/
ncurses(); /************ncursess*******/
while (!feof(fichier))
{
for(nb_ligne=0;nb_ligne<=hauteur;nb_ligne++)
{
for(nb_col=1;nb_col<=largeur;nb_col++)
{
fscanf(fichier,"%c",&lab[nb_ligne][nb_col]);
if(lab[nb_ligne][nb_col]=='0')
{
attron(COLOR_PAIR(1));
mvprintw(nb_ligne,nb_col," " );
attroff(COLOR_PAIR(1));
}
else if(lab[nb_ligne][nb_col]=='1')
{
attron(COLOR_PAIR(3));
mvprintw(nb_ligne,nb_col," " );
attroff(COLOR_PAIR(3));
}
else if(lab[nb_ligne][nb_col]=='M')
{
attron(COLOR_PAIR(2));
mvprintw(nb_ligne,nb_col," " );
attroff(COLOR_PAIR(2));
}
else if(lab[nb_ligne][nb_col]=='K')
{
attron(COLOR_PAIR(4));
mvprintw(nb_ligne,nb_col,"&" );
attroff(COLOR_PAIR(4));
}
refresh();
}
fscanf(fichier,"%c",&chaine);
}
}
keypad(stdscr,TRUE);
curs_set(0);
nb_ligne= 1 ;
nb_col= 5 ;
move(nb_ligne,nb_col);
while (key != KEY_F(12))
{
wattrset (stdscr, COLOR_PAIR(3));
switch (key)
{
case KEY_RIGHT:
if (largeur-1 > nb_col)
{
if (lab[nb_ligne][nb_col+1] != '0' && lab[nb_ligne+1][nb_col] != 'V')
{
addch (' ');
nb_col++;
deplacer(nb_ligne,nb_col);
}
}
break;
case KEY_LEFT:
if (0 < nb_col)
{
if (lab[nb_ligne][nb_col-1] != '0' && lab[nb_ligne+1][nb_col] != 'V')
{
addch (' ');
nb_col--;
deplacer(nb_ligne,nb_col);
}
}
break;
case KEY_DOWN:
if (hauteur-1 > nb_ligne)
{
if (lab[nb_ligne+1][nb_col] != '0' && lab[nb_ligne+1][nb_col] != 'V')
{
addch (' ');
nb_ligne++;
/******deplacer*********/
deplacer(nb_ligne,nb_col);
/*********deplacer***********/
}
}
break;
case KEY_UP:
if (0< nb_ligne)
{
if (lab[nb_ligne-1][nb_col] != '0' && lab[nb_ligne+1][nb_col] != 'm')
{
addch (' ');
nb_ligne--;
deplacer(nb_ligne,nb_col);
}
}
break;
}
key=getch();
move(nb_ligne,nb_col);
refresh();
}
echo();
endwin();
exit(0);
return 0;
}
Voila le programme en C avec la bibliothèque ncurses qu'il me faut, donc ce programme est bon, il marche a l'exécution, mais fenêtre vide!!!