Frédéric.
Bonjour, je dois faire un programme sous Linux en C avec la bibliothèque Ncurses. Ca c'est pas trop le problème.
Le code est à priori correct, mais je n'arrive pas lors de l'exécution de programme à afficher le labyrinthe. La fenêtre qui s'affiche est vide. Dans le programme, il y a un lien qui pointe sur un fichier texte, avec un style de labyrinthe, mais à priori ca ne fonctionne pas. Je code avec Scite sous Linux!!! Pouriez vous m'aider, ou m'expliquer d'où vient le problème. Pouvez vous également m'aider pour le commenter. Merci beaucoup. Je suis assez pressé, dont si quelqu'un de compétant peut m'aider. Ne poster pas des messages bidons, cela n'aide personne, si vous savez pas, chut !!! Merci.
Le code est présenté ci-dessous:
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
void ncurses();
void mat();
void deplacer();
void ncurses(){
initscr();
noecho(); /*A commenter*/
start_color();
init_pair(1, COLOR_RED, COLOR_RED);/*A commenter */
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);/*A commenter*/
wattrset (stdscr, COLOR_PAIR(2));/*A commenter*/
addch('>');/*A commenter*/
}
int main (int argc, char **argv)/*A commenter. Pourquoi arg c et **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" );
/****************init lab******************/
mat();
/****************initlab******************/
/***********ncureses*************/
ncurses(); /************ncursess*******/
while (!feof(fichier)) /*Qu'est ce que veut dire "feof"?*/
{
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));/*A commenter*/
mvprintw(nb_ligne,nb_col," " );/*A commenter*/
attroff(COLOR_PAIR(1));/*A commenter*/
}
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);/*A commenter*/
curs_set(0);/*A commenter*/
nb_ligne= 1 ;
nb_col= 5 ;
move(nb_ligne,nb_col);
while (key != KEY_F(12))
{
wattrset (stdscr, COLOR_PAIR(3));/*A commenter*/
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();/*A commenter*/
move(nb_ligne,nb_col);
refresh();
}
echo();
endwin();
exit(0);
return 0;
}