Afficher une position dans un tableau
Salut,
Voilà j'ai un projet dérivé du démineur, je dois aller d'un point A à un point B, mais je bloque vraiment sur la méthode, mon programme est de cette manière :
Faire
InitialiserPlateau(plateau)
InitialiserMines1(plateau
Affnom(nom)
AffPlateau(plateau)
JeuPasTerminé = vrai
Tant que (JeuPasTerminé)
Tant que (position !=MINE ou position!=arrivée)
AffPlateau(position)
Déplacement
En gras je n'arrive pas à les mettre en relation, j'ai donc alors tenté de faire une unique fonction, mais j'ai des erreurs dans le switch
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
void AffPosition (int t[NBLigne][NBColonne]) {
int position[NBLigne][NBColonne];
int i=0,j=0,k=0, deplacement = 0;
t[0][0] = DEPART; // Détermination point de départ
t[NBLigne-1][NBColonne-1] = ARRIVEE; // Détermination point d'arrivée
position = t[0][0];
while (position != MINE || position != ARRIVEE) {
printf("\n\nDeplacement :");
printf("\nDroite - Saisir 1");
printf("\nGauche - Saisir 2");
printf("\nHaut - Saisir 3");
printf("\nBas - Saisir 4");
scanf("%d",&deplacement); //Déplacement
switch (deplacement) {
case 1 : position = t[j][k+1];
break;
case 2 : position = t[j][k-1];
break;
case 3 : position = t[j-1][k];
break;
case 4 : position = t[j+1][k];
break;
for (j=0;j<NBLigne;j++) {
printf("\n");
for (k=0;k<NBColonne;k++) {
printf("| ");
if (t[j][k] == INIT)
printf(" ");
else if (t[j][k] == DEPART)
printf("D ");
else if (t[j][k] == ARRIVEE)
printf("A ");
else if (t[j][k] == position)
printf("O");
/*else if (t[j-1][k] == MINE || t[j+1][k] == MINE || t[j][k-1] == MINE || t[j][k+1] == MINE )
printf("X ");*/
else if (t[j][k] == MINE)
printf(" ");
/* else if (t[j][k] == Gagne)
printf("G ");*/
}
printf("|");
printf("\n");
for(k=0;k<NBColonne;k++)
printf("----");
}
}
}
} |
Merci