Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void init_carte(int tab[20][20]);
- int deplace_personnage(int tab[20][20], int perso[2], int compteurPieces, int PV);
- void affiche_carte(int tab[20][20], int perso[2], int compteurPieces, int PV); //MODIFIE PAR MOI
- int main()
- {
- int tab[20][20];
- int perso[2];
- int compteurPieces,PV;
- init_carte(tab);
- deplace_personnage(tab,perso,compteurPieces, PV);
- return 0;
- }
- void init_carte(int tab[20][20])
- {
- for (int i=0; i<20; i++)
- {
- for (int j=0; j<20; j++)
- {
- tab[i][j]=0;
- }
- }
- tab[15][13]=5;
- tab[11][1]=5;
- tab[18][8]=5;
- tab[1][15]=5;
- tab[11][19]=5;
- tab[18][18]=5;
- tab[4][7]=5;
- tab[1][16]=2;
- tab[1][17]=2;
- tab[1][18]=2;
- tab[2][16]=2;
- tab[2][17]=2;
- tab[2][18]=2;
- tab[14][13]=2;
- tab[14][14]=2;
- tab[14][15]=2;
- tab[15][14]=2;
- tab[15][15]=2;
- tab[16][15]=2;
- tab[10][19]=7;
- tab[12][19]=7;
- tab[1][0]=7;
- tab[0][3]=7;
- tab[0][4]=7;
- tab[0][5]=7;
- tab[0][6]=7;
- tab[1][4]=7;
- tab[1][5]=7;
- tab[3][3]=8;
- tab[8][1]=8;
- tab[8][2]=8;
- tab[9][2]=8;
- tab[5][11]=1;
- tab[17][6]=1;
- tab[14][11]=1;
- tab[6][9]=1;
- tab[2][18]=1;
- //tab[0][0]=9;
- }
- void affiche_carte(int tab[20][20], int perso[2], int compteurPieces, int PV) //MODIFIE PAR MOI
- {
- printf("Pièce(s) : %d PV : %d\n",compteurPieces,PV);
- for (int i=0; i<20; i++)
- {
- for (int j=0; j<20; j++)
- {
- if (perso[0] == j && perso[1] == i){ //MODIFIE PAR MOI
- printf("X "); //MODIFIE PAR MOI
- } //MODIFIE PAR MOI
- else //MODIFIE PAR MOI
- { //MODIFIE PAR MOI
- switch (tab[i][j])
- {
- case 0:
- printf(", ");
- break;
- case 1:
- printf("f ");
- break;
- case 2:
- printf("Y ");
- break;
- case 3:
- printf("B ");
- break;
- case 4:
- printf("! ");
- break;
- case 5:
- printf("C ");
- break;
- case 6:
- printf("? ");
- break;
- case 7:
- printf("P ");
- break;
- case 8:
- printf("M ");
- break;
- //case 9:
- // printf("X ");
- // break;
- default:
- printf(". ");
- break;
- }
- } //MODIFIE PAR MOI
- }
- printf("\n");
- }
- }
- int deplace_personnage(int tab[20][20], int perso[2], int compteurPieces, int PV)
- {
- int saisie;
- compteurPieces=0;
- PV=10;
- perso[0]=0;
- perso[1]=0;
- int x=0;
- int i=0;
- int j=0;
- do
- {
- affiche_carte(tab,perso,compteurPieces,PV); //MODIFIE PAR MOI
- //tab[i][j]=0;
- printf("Où veux-tu aller ? 8=haut, 2=bas, 4=gauche, 6=droite, 0=quitter\n");
- scanf("%d",&saisie);
- switch (saisie)
- {
- case 8:
- if (perso[1]>0)
- {
- perso[1]=perso[1]-1;
- i=perso[1];
- if (tab[i][j]==2 || tab[i][j]==3)
- {
- printf("Obstacle !\n");
- perso[1]=perso[1]+1;
- i=perso[1];
- }
- else if (tab[i][j]==5)
- {
- compteurPieces=compteurPieces+1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==7)
- {
- PV=PV-1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==8)
- {
- PV=PV-2;
- }
- }
- else
- {
- printf("Vous sortez de la carte\n");
- }
- break;
- case 2:
- if (perso[1]<19)
- {
- perso[1]=perso[1]+1;
- i=perso[1];
- if (tab[i][j]==2 || tab[i][j]==3)
- {
- printf("Obstacle !\n");
- perso[1]=perso[1]-1;
- i=perso[1];
- }
- else if (tab[i][j]==5)
- {
- compteurPieces=compteurPieces+1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==7)
- {
- PV=PV-1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==8)
- {
- PV=PV-2;
- }
- }
- else
- {
- printf("Vous sortez de la carte\n");
- }
- break;
- case 4:
- if (perso[0]>0)
- {
- perso[0]=perso[0]-1;
- j=perso[0];
- if (tab[i][j]==2 || tab[i][j]==3)
- {
- printf("Obstacle !\n");
- perso[0]=perso[0]+1;
- j=perso[0];
- }
- else if (tab[i][j]==5)
- {
- compteurPieces=compteurPieces+1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==7)
- {
- PV=PV-1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==8)
- {
- PV=PV-2;
- }
- }
- else
- {
- printf("Vous sortez de la carte\n");
- }
- break;
- case 6:
- if (perso[0]<19)
- {
- perso[0]=perso[0]+1;
- j=perso[0];
- if (tab[i][j]==2 || tab[i][j]==3)
- {
- printf("Obstacle !\n");
- perso[0]=perso[0]-1;
- j=perso[0];
- }
- else if (tab[i][j]==5)
- {
- compteurPieces=compteurPieces+1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==7)
- {
- PV=PV-1;
- tab[i][j]=0; //MODIFIE PAR MOI
- }
- else if (tab[i][j]==8)
- {
- PV=PV-2;
- }
- }
- else
- {
- printf("Vous sortez de la carte\n");
- }
- break;
- case 0:
- printf("Vous avez quitté le jeu\n");
- return -1;
- break;
- default:
- printf("Veuillez ressaisir un nombre\n");
- break;
- }
- if (compteurPieces==10)
- {
- printf("Gagné !\n");
- return -1;
- }
- else if (PV==0)
- {
- printf("Perdu.\n");
- return -1;
- }
- //tab[i][j]=9;
- }
- while (x==0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement