Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <time.h>
  4. #include <locale.h>
  5.  
  6. #define HEAD1 printf("%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,187)
  7. #define HEAD2 printf("%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,188)
  8. #define MID1 printf("%c %c %c",186,254,186)
  9. #define MID2 printf("%c %c %c %c",186,254,254,186)
  10. #define LEFT1 printf("%c %c %c",186,254,186)
  11. #define RIGHT1 printf("%c %c %c",186,254,186)
  12. #define EMPTY printf("%c %c",186,186)
  13. #define BR printf("\n")
  14. #define SP printf(" ")
  15. #define W8 Sleep(80)
  16. #define CLS system("cls")
  17. #define STOP system("pause")
  18. #define LINE1(a) (randomValue[a] == 1 ? EMPTY : (randomValue[a] == 2 || randomValue[a] == 3) ? LEFT1 : (randomValue[a] == 4 || randomValue[a] == 5 || randomValue[a] == 6) ? MID2 : EMPTY)
  19. #define LINE2(a) ((randomValue[a] == 1 || randomValue[a] == 3 || randomValue[a] == 5) ? MID1 : (randomValue[a] == 2 || randomValue[a] == 4) ? EMPTY : (randomValue[a] == 6) ? MID2 : EMPTY)
  20. #define LINE3(a) (randomValue[a] == 1 ? EMPTY : (randomValue[a] == 2 || randomValue[a] == 3) ? RIGHT1 : (randomValue[a] == 4) || (randomValue[a] == 5) || (randomValue[a] == 6) ? MID2 : EMPTY)
  21.  
  22. //print random four dice adjacent
  23. void fourDice()
  24. {
  25. setlocale(LC_ALL,"en_US");
  26. srand(time(NULL));
  27.  
  28. //array of random value from 1 to 6
  29. int randomValue[4];
  30. for(int i=0; i<4; i++)
  31. {
  32. randomValue[i] = rand()%6+1;
  33. if((i>0) && (randomValue[i]==randomValue[i-1]))
  34. {
  35. do
  36. {
  37. randomValue[i] = rand()%6+1;
  38. }
  39. while(randomValue[i] != randomValue[i-1]);
  40. }
  41. }
  42.  
  43. //print header
  44. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  45.  
  46. //print line 1
  47. for(int i=0; i<4; i++)
  48. {
  49. LINE1(randomValue[i]);
  50. SP;
  51. }
  52. BR;
  53.  
  54. //print line 2
  55. for(int i=0; i<4; i++)
  56. {
  57. LINE2(randomValue[i]);
  58. SP;
  59. }
  60. BR;
  61.  
  62. //print line 3
  63. for(int i=0; i<4; i++)
  64. {
  65. LINE3(randomValue[i]);
  66. SP;
  67. }
  68. BR;
  69.  
  70. //print footer
  71. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  72.  
  73. printf("The first random value is: %d\n",randomValue[0]);
  74. printf("The second random value is: %d\n",randomValue[1]);
  75. printf("The third random value is: %d\n",randomValue[2]);
  76. printf("The fourth random value is: %d\n",randomValue[3]);
  77. }
  78.  
  79. //animation of dice
  80. void switchAnimation(int e)
  81. {
  82. setlocale(LC_ALL, "en_US");
  83. switch(e)
  84. {
  85. case 1:
  86. //2564
  87. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  88. LEFT1;SP;MID2;SP;MID2;SP;MID2;BR;
  89. EMPTY;SP;MID1;SP;MID2;;SP;EMPTY;BR;
  90. RIGHT1;SP;MID2;SP;MID2;SP;MID2;BR;
  91. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  92. break;
  93. case 2:
  94. //4215
  95. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  96. MID2;SP;LEFT1;SP;EMPTY;SP;MID2;BR;
  97. EMPTY;SP;EMPTY;SP;MID1;SP;MID1;BR;
  98. MID2;SP;RIGHT1;SP;EMPTY;SP;MID2;BR;
  99. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  100. break;
  101. case 3:
  102. //6351
  103. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  104. MID2;SP;LEFT1;SP;MID2;SP;EMPTY;BR;
  105. MID2;SP;MID1;SP;MID1;SP;MID1;BR;
  106. MID2;SP;RIGHT1;SP;MID2;SP;EMPTY;BR;
  107. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  108. break;
  109. case 4:
  110. //1436
  111. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  112. EMPTY;SP;MID2;SP;LEFT1;SP;MID2;BR;
  113. MID1;SP;EMPTY;SP;MID1;SP;MID2;BR;
  114. EMPTY;SP;MID2;SP;RIGHT1;SP;MID2;BR;
  115. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  116. break;
  117. case 5:
  118. //3625
  119. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  120. LEFT1;SP;MID2;SP;LEFT1;SP;MID2;BR;
  121. MID1;SP;MID2;SP;EMPTY;SP;MID1;BR;
  122. RIGHT1;SP;MID2;SP;RIGHT1;SP;MID2;BR;
  123. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  124. break;
  125. case 6:
  126. //5142
  127. HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
  128. MID2;SP;EMPTY;SP;MID2;SP;LEFT1;BR;
  129. MID1;SP;MID1;SP;EMPTY;SP;EMPTY;BR;
  130. MID2;SP;EMPTY;SP;MID2;SP;RIGHT1;BR;
  131. HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
  132. break;
  133. }
  134. }
  135.  
  136. void diceAnimation(int n)
  137. {
  138. setlocale(LC_ALL,"en_US");
  139. int u,u_before=0;
  140. srand(time(NULL));
  141. for(int i=0; i<n; i++)
  142. {
  143. u = rand()%6+1;
  144. if(u_before == u)u++;
  145. switchAnimation(u);
  146. u_before=u;
  147. W8;CLS;
  148. }
  149. }
  150.  
  151.  
  152. int main()
  153. {
  154. char repeat;
  155. setlocale(LC_ALL, "en_US");
  156.  
  157. printf("The program generates you a random value on a gambling dice\n\n");
  158. STOP;CLS;
  159. do
  160. {
  161.  
  162. diceAnimation(5);
  163. fourDice();
  164. BR;
  165. printf("Do you want to repeat the program? (y/n)\n> ");
  166. scanf(" %c",&repeat);
  167. }
  168. while(repeat=='Y'||repeat=='y');
  169. STOP;
  170. return 0;
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement