Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "game.h"
  3.  
  4.  
  5.  
  6. int Afficher_Tableau(int tableau[TAILLE_RANGEE][TAILLE_COLONNE])
  7. {
  8. int i=0, j=0;
  9. for(i=0;i<TAILLE_RANGEE;i++)
  10. for(j=0;j<TAILLE_COLONNE;j++)
  11. {
  12. if (tableau[i][j]==1)
  13. printf("T");
  14. if (tableau[i][j]==0)
  15. printf(" ");
  16. if (tableau[i][j]==2)
  17. {
  18. if (j<TAILLE_COLONNE-1)
  19. printf("O");
  20. else
  21. printf("O\n");
  22. }
  23. }
  24. }
  25.  
  26.  
  27. int Deplacer_T(int tableau[TAILLE_RANGEE][TAILLE_COLONNE])
  28. {
  29. char deplacer='a';
  30. while (deplacer!='q')
  31. {
  32. Afficher_Tableau(tableau);
  33.  
  34. printf("\n\n");
  35.  
  36. printf("(d)roite, (g)auche ou (q)itter, (b)as ou (h)aut : ");
  37. scanf("%s", &deplacer);
  38.  
  39. switch(deplacer)
  40. {
  41. case 'q':
  42. break;
  43. case 'd':
  44. deplacer_droite(tableau);
  45. break;
  46. case 'g':
  47. deplacer_gauche(tableau);
  48. break;
  49. case 'b':
  50. deplacer_bas(tableau);
  51. break;
  52. case 'h':
  53. deplacer_haut(tableau);
  54. break;
  55. }
  56. }
  57.  
  58. }
  59.  
  60.  
  61. void deplacer_droite(int tableau[TAILLE_RANGEE][TAILLE_COLONNE])
  62. {
  63. int i=0, j=0;
  64.  
  65. for(i=1;i<(TAILLE_RANGEE-1);i++)
  66. {
  67. if (tableau[i][TAILLE_COLONNE-2]==1)
  68. { printf("\nTU NE PEUX PAS SORTIR DU CARDRE !!!\n");
  69. break;
  70. }
  71. for(j=1;j<(TAILLE_COLONNE-2);j++)
  72. {
  73. if (tableau[i][j]==1)
  74. {
  75. tableau[i][j]=0;
  76. tableau[i][j+1]=1;
  77. break;
  78. }
  79. }
  80. }
  81. }
  82.  
  83. void deplacer_gauche(int tableau[TAILLE_RANGEE][TAILLE_COLONNE])
  84. {
  85. int i=0, j=0;
  86.  
  87. for(i=1;i<(TAILLE_RANGEE-1);i++)
  88. {
  89. if (tableau[i][1]==1)
  90. { printf("\nTU NE PEUX PAS SORTIR DU CARDRE !!!\n");
  91. break;
  92. }
  93. for(j=2;j<(TAILLE_COLONNE-1);j++)
  94. {
  95. if (tableau[i][j]==1)
  96. {
  97. tableau[i][j]=0;
  98. tableau[i][j-1]=1;
  99. break;
  100. }
  101. }
  102. }
  103. }
  104.  
  105. void deplacer_bas(int tableau[TAILLE_RANGEE][TAILLE_COLONNE])
  106. {
  107. int i=0, j=0;
  108.  
  109. for(j=1;j<(TAILLE_COLONNE-1);j++)
  110. {
  111. if (tableau[TAILLE_RANGEE-2][j]==1)
  112. { printf("\nTU NE PEUX PAS SORTIR DU CARDRE !!!\n");
  113. break;
  114. }
  115. for(i=1;i<(TAILLE_RANGEE-2);i++)
  116. {
  117. if (tableau[i][j]==1)
  118. {
  119. tableau[i][j]=0;
  120. tableau[i+1][j]=1;
  121. break;
  122. }
  123. }
  124. }
  125. }
  126.  
  127. void deplacer_haut(int tableau[TAILLE_RANGEE][TAILLE_COLONNE])
  128. {
  129. int i=0, j=0;
  130.  
  131. for(j=1;j<(TAILLE_COLONNE-1);j++)
  132. {
  133. if (tableau[1][j]==1)
  134. { printf("\nTU NE PEUX PAS SORTIR DU CARDRE !!!\n");
  135. break;
  136. }
  137. for(i=2;i<(TAILLE_RANGEE-1);i++)
  138. {
  139. if (tableau[i][j]==1)
  140. {
  141. tableau[i][j]=0;
  142. tableau[i-1][j]=1;
  143. break;
  144. }
  145. }
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement