Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void init_carte(int tab[20][20]);
  5. int deplace_personnage(int tab[20][20], int perso[2], int compteurPieces, int PV);
  6. void affiche_carte(int tab[20][20], int perso[2], int compteurPieces, int PV); //MODIFIE PAR MOI
  7.  
  8. int main()
  9. {
  10.     int tab[20][20];
  11.     int perso[2];
  12.     int compteurPieces,PV;
  13.     init_carte(tab);
  14.     deplace_personnage(tab,perso,compteurPieces, PV);
  15.     return 0;
  16. }
  17.  
  18. void init_carte(int tab[20][20])
  19. {
  20.     for (int i=0; i<20; i++)
  21.     {
  22.         for (int j=0; j<20; j++)
  23.         {
  24.             tab[i][j]=0;
  25.         }
  26.     }
  27.  
  28.     tab[15][13]=5;
  29.     tab[11][1]=5;
  30.     tab[18][8]=5;
  31.     tab[1][15]=5;
  32.     tab[11][19]=5;
  33.     tab[18][18]=5;
  34.     tab[4][7]=5;
  35.  
  36.     tab[1][16]=2;
  37.     tab[1][17]=2;
  38.     tab[1][18]=2;
  39.     tab[2][16]=2;
  40.     tab[2][17]=2;
  41.     tab[2][18]=2;
  42.     tab[14][13]=2;
  43.     tab[14][14]=2;
  44.     tab[14][15]=2;
  45.     tab[15][14]=2;
  46.     tab[15][15]=2;
  47.     tab[16][15]=2;
  48.  
  49.     tab[10][19]=7;
  50.     tab[12][19]=7;
  51.     tab[1][0]=7;
  52.     tab[0][3]=7;
  53.     tab[0][4]=7;
  54.     tab[0][5]=7;
  55.     tab[0][6]=7;
  56.     tab[1][4]=7;
  57.     tab[1][5]=7;
  58.  
  59.     tab[3][3]=8;
  60.     tab[8][1]=8;
  61.     tab[8][2]=8;
  62.     tab[9][2]=8;
  63.  
  64.     tab[5][11]=1;
  65.     tab[17][6]=1;
  66.     tab[14][11]=1;
  67.     tab[6][9]=1;
  68.     tab[2][18]=1;
  69.  
  70.     //tab[0][0]=9;
  71.  
  72. }
  73.  
  74. void affiche_carte(int tab[20][20], int perso[2], int compteurPieces, int PV) //MODIFIE PAR MOI
  75. {
  76.     printf("Pièce(s) : %d                    PV : %d\n",compteurPieces,PV);
  77.     for (int i=0; i<20; i++)
  78.     {
  79.         for (int j=0; j<20; j++)
  80.         {
  81.             if (perso[0] == j && perso[1] == i){ //MODIFIE PAR MOI
  82.                 printf("X "); //MODIFIE PAR MOI
  83.             } //MODIFIE PAR MOI
  84.             else //MODIFIE PAR MOI
  85.             { //MODIFIE PAR MOI
  86.                 switch (tab[i][j])
  87.                 {
  88.                 case 0:
  89.                     printf(", ");
  90.                     break;
  91.                 case 1:
  92.                     printf("f ");
  93.                     break;
  94.                 case 2:
  95.                     printf("Y ");
  96.                     break;
  97.                 case 3:
  98.                     printf("B ");
  99.                     break;
  100.                 case 4:
  101.                     printf("! ");
  102.                     break;
  103.                 case 5:
  104.                     printf("C ");
  105.                     break;
  106.                 case 6:
  107.                     printf("? ");
  108.                     break;
  109.                 case 7:
  110.                     printf("P ");
  111.                     break;
  112.                 case 8:
  113.                     printf("M ");
  114.                     break;
  115.                 //case 9:
  116.                 //    printf("X ");
  117.                 //    break;
  118.                 default:
  119.                     printf(". ");
  120.                     break;
  121.                 }
  122.             } //MODIFIE PAR MOI
  123.         }
  124.         printf("\n");
  125.     }
  126. }
  127.  
  128. int deplace_personnage(int tab[20][20], int perso[2], int compteurPieces, int PV)
  129. {
  130.     int saisie;
  131.     compteurPieces=0;
  132.     PV=10;
  133.     perso[0]=0;
  134.     perso[1]=0;
  135.     int x=0;
  136.     int i=0;
  137.     int j=0;
  138.     do
  139.     {
  140.         affiche_carte(tab,perso,compteurPieces,PV); //MODIFIE PAR MOI
  141.         //tab[i][j]=0;
  142.         printf("Où veux-tu aller ? 8=haut, 2=bas, 4=gauche, 6=droite, 0=quitter\n");
  143.         scanf("%d",&saisie);
  144.         switch (saisie)
  145.         {
  146.         case 8:
  147.             if (perso[1]>0)
  148.             {
  149.                 perso[1]=perso[1]-1;
  150.                 i=perso[1];
  151.                 if (tab[i][j]==2 || tab[i][j]==3)
  152.                 {
  153.                     printf("Obstacle !\n");
  154.                     perso[1]=perso[1]+1;
  155.                     i=perso[1];
  156.                 }
  157.                 else if (tab[i][j]==5)
  158.                 {
  159.                     compteurPieces=compteurPieces+1;
  160.                     tab[i][j]=0; //MODIFIE PAR MOI
  161.                 }
  162.                 else if (tab[i][j]==7)
  163.                 {
  164.                     PV=PV-1;
  165.                     tab[i][j]=0; //MODIFIE PAR MOI
  166.                 }
  167.                 else if (tab[i][j]==8)
  168.                 {
  169.                     PV=PV-2;
  170.                 }
  171.             }
  172.             else
  173.             {
  174.                 printf("Vous sortez de la carte\n");
  175.             }
  176.             break;
  177.         case 2:
  178.             if (perso[1]<19)
  179.             {
  180.                 perso[1]=perso[1]+1;
  181.                 i=perso[1];
  182.                 if (tab[i][j]==2 || tab[i][j]==3)
  183.                 {
  184.                     printf("Obstacle !\n");
  185.                     perso[1]=perso[1]-1;
  186.                     i=perso[1];
  187.                 }
  188.                 else if (tab[i][j]==5)
  189.                 {
  190.                     compteurPieces=compteurPieces+1;
  191.                     tab[i][j]=0; //MODIFIE PAR MOI
  192.                 }
  193.                 else if (tab[i][j]==7)
  194.                 {
  195.                     PV=PV-1;
  196.                     tab[i][j]=0; //MODIFIE PAR MOI
  197.                 }
  198.                 else if (tab[i][j]==8)
  199.                 {
  200.                     PV=PV-2;
  201.                 }
  202.             }
  203.             else
  204.             {
  205.                 printf("Vous sortez de la carte\n");
  206.             }
  207.             break;
  208.         case 4:
  209.             if (perso[0]>0)
  210.             {
  211.                 perso[0]=perso[0]-1;
  212.                 j=perso[0];
  213.                 if (tab[i][j]==2 || tab[i][j]==3)
  214.                 {
  215.                     printf("Obstacle !\n");
  216.                     perso[0]=perso[0]+1;
  217.                     j=perso[0];
  218.                 }
  219.                 else if (tab[i][j]==5)
  220.                 {
  221.                     compteurPieces=compteurPieces+1;
  222.                     tab[i][j]=0; //MODIFIE PAR MOI
  223.                 }
  224.                 else if (tab[i][j]==7)
  225.                 {
  226.                     PV=PV-1;
  227.                     tab[i][j]=0; //MODIFIE PAR MOI
  228.                 }
  229.                 else if (tab[i][j]==8)
  230.                 {
  231.                     PV=PV-2;
  232.                 }
  233.             }
  234.             else
  235.             {
  236.                 printf("Vous sortez de la carte\n");
  237.             }
  238.             break;
  239.         case 6:
  240.             if (perso[0]<19)
  241.             {
  242.                 perso[0]=perso[0]+1;
  243.                 j=perso[0];
  244.                 if (tab[i][j]==2 || tab[i][j]==3)
  245.                 {
  246.                     printf("Obstacle !\n");
  247.                     perso[0]=perso[0]-1;
  248.                     j=perso[0];
  249.                 }
  250.                 else if (tab[i][j]==5)
  251.                 {
  252.                     compteurPieces=compteurPieces+1;
  253.                     tab[i][j]=0; //MODIFIE PAR MOI
  254.                 }
  255.                 else if (tab[i][j]==7)
  256.                 {
  257.                     PV=PV-1;
  258.                     tab[i][j]=0; //MODIFIE PAR MOI
  259.                 }
  260.                 else if (tab[i][j]==8)
  261.                 {
  262.                     PV=PV-2;
  263.                 }
  264.             }
  265.             else
  266.             {
  267.                 printf("Vous sortez de la carte\n");
  268.             }
  269.             break;
  270.         case 0:
  271.             printf("Vous avez quitté le jeu\n");
  272.             return -1;
  273.             break;
  274.         default:
  275.             printf("Veuillez ressaisir un nombre\n");
  276.             break;
  277.  
  278.         }
  279.         if (compteurPieces==10)
  280.         {
  281.             printf("Gagné !\n");
  282.             return -1;
  283.         }
  284.         else if (PV==0)
  285.         {
  286.             printf("Perdu.\n");
  287.             return -1;
  288.         }
  289.         //tab[i][j]=9;
  290.     }
  291.     while (x==0);
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement